Sunday, 3 January 2016

Going Reactive - Part 1

I have been reading the book Reactive Messaging Patterns with the Actor Model, Applications and Integration in Scala and Akka by Vaughn Vernon.

Reactive Applications

Reactive applications are responsive, resilient, elastic, message-driven and capable of producing a real-time feel.

See http://www.reactivemanifesto.org for more details on the four principles.


The Actor Model

An actor is a computational entity that in response to a message it receives can do the following.

  • Send a finite number of messages to other actors
  • Create a finite number of new actors
  • Designate the behaviour to be used for the next message it receives
There is no assumed sequence to these actions and they will be carried out in parallel.

More specifically actors must not share any mutable state with other actors. Actors have individual mailboxes and don't share queues.

When designing reactive systems using the Actor Model, try to anticipate the unexpected. That doesn't mean you can think of every possible situation up front, but you can build resiliency through supervision which will deal with what you cannot know up front.


Akka


Akka implements the Actor Model. Akka Actors give you:

  • Simple and high-level abstractions for concurrency and parallelism.
  • Asynchronous, non-blocking and highly performant event-driven programming model.
  • Very lightweight event-driven processes (several million actors per GB of heap memory). 

At the next part I will be looking at some example reactive applications using Akka.

Friday, 1 January 2016

Akka HTTP Client example

I have been experimenting with Akka HTTP. The following is a simple example of making a GET request using Akka HTTP and printing the response.

The build.sbt is found below.
The client is found below.
Happy New Year! :)

Monday, 24 June 2013

Scala, Machine Learning, Algorithms and Complexity, Data Analysis


1. Functional Programming in Scala, EPFL

I completed the Functional Programming in Scala online course from EPFL with distinction, 100% (top 7% of class). I enjoyed the challenging exercises and would be very interested in a follow up course, as proposed by Martin Odersky. 



The course covered topics on functional programming principles and implementations of those in the form of courseworks and examples. Such topics include functions and evaluations, tail recursion, higher order functions, currying, evaluation and operators, data and abstraction, class hierarchies and
polymorphism in scala, recursion, types and patterm matching, subtyping and generics, decomposition. It also includes chapters on lists, pairs and tuples, implicit parameters, higher-order list functions, reduction of lists, maps and other collections, combinatorial search and for-expressions. The final chapter was on lazy evaluation and the use of streams for computing infinite sequences. The course included courseworks on sets, Huffman coding, analysis of twitter data, anagrams and streams. 

Some statistics on the participants of this course follow. 4596, out of nearly 10000 students that received a certificate for the course, responded to the survey.
The field of study for the majority of the participants seems to be computer science and computer/ software engineering. There were some participants from statistics, maths, electrical engineering and physics.

At least 87% of the students have a university degree. Of these more than half are MScs or PhDs. This demonstrates that Scala attracts the interest of people with high level of academic achievements.

Nearly half of the participants (40%) will use the acquired knowledge at team or individual projects at work.







The following map shows the number of participants per country. 477 people from UK (6.37%) took the course. 


The data, the above graphs and more statistics on the course are available in github progfun-stats.


2. Machine Learning, Stanford

In addition to the Functional programming in Scala course, I took the Machine Learning course from Stanford, taught by Andrew Ng, and completed it with distinction.

The course contained material on linear algebra, univariate and multivariate linear regression, logistic regression, one-vs-all classification, regularisation, neural networks representation and learning, feed forward, back propagation, multi-class classification, machine learning system design, bias-variance, Support Vector Machines (SVMs), unsupervised learning, clustering, dimensionality reduction, k-means, Principal Components Analysis (PCA), anomaly detection, recommender systems and large-scale machine learning. 

I used Octave for the programming exercises, which included implementations for spam classifier, image compression, low-dimensional representation of face images, hand written digits recognition, detection of failing servers on a network, collaborative filtering for recommender system for movies.


I would like to implement some of exercises in Scala and try Spark, an open source cluster computing system that aims to make data analytics fast. It provides primitives for in-memory cluster computing, so that you can load data into memory and query it repeatedly much more quickly than with disk-based systems like Hadoop and MapReduce. Spark was initially developed for iterative algorithms, which are common in machine learning, and interactive data mining. In both cases, it can run up to 100x faster than Hadoop MapReduce. It can also be used for general processing too.


3. Algorithms I, Princeton

Furthermore, I completed the Algorithms I course from Princeton, taught by Robert Sedgewick and Kevin Wayne. 

The course was on fundamental data types, algorithms and data structures with emphasis on performance of Java implementations. Topics covered include union-find algorithms, basic iterable data types (such as stack, queues and bags), sorting algorithms (insertion sort, selection sort, shellsort, quicksort, 3-way quicksort, mergesort, heapsort, binary heaps) and applications, priority queues, binary search trees, red black trees, separate chaining and linear probing hash tables, Graham scan for computing the convex hull of a finite set of points in the plane with time complexity O(nlogn), kd-trees and symbol-table applications.

The material can be found on the Algorithms, 4th edition by R. Sedgewick and K. Wayne.

There is a part II on this course, which I am planning to follow later on this year. 


4. Computing for Data Analysis, John Hopkins University

This course was on R programming and application to statistical data analysis. More specifically, it covers the flow of retrieving, organising and summarising the data. In addition it includes plotting data for exploratory purposes, exploratory statistical models, statistical models for inference (linear models, basic confidence intervals/ hypothesis testing), cross-validation, exploratory and expository graphs, hierarchical clustering, k-means clustering, dimensionality reduction and Singular Value Decomposition (SVD).

This course has helped me get closer to the data and understand better the difficulties of gathering and cleaning a dataset. It also helped me learn how to create useful graphs for visualising my dataset. 


In the future...

Those were some interesting courses and there are even more exciting courses to follow. It feels like I am doing a part time MSc, while having a full time job. 

Sunday, 31 March 2013

Finding Square Root in Scala

Scala
After completing the Algorithms I course by Robert Sedgewick, I am now taking the Functional Programming Principles in Scala by Martin Odersky. 

The following is a Scala snippet for finding the square root:

A graphical representation of Newton's method for finding the nth root.

Newton's method updating rule 
The higher order terms O(h^2) have been dropped in the f(x+h) approximation, since it is a linear approximation.








The updating rule x_(n+1):








Happy Easter! :)

Friday, 24 August 2012

MSc MTF Distinction!

I just completed the MSc Mathematical Trading and Finance in Cass Business School with Distinction (First Class)! It was a challenging and rewarding year. It's now time to start applying my knowledge into practice. More exciting moments are to come!

Sunday, 25 September 2011

Low-Latency Summit 2011

I will be attending the Low-Latency Summit 2011 - Winning Strategies for Deploying Low-Latency Technologies. I attended the Summit last year and I got a good insight about technologies used for low-latency and what are the right low-latency choices in order to stay ahead in Electronic Trading. This year the opening will be by Pete Harris (Publisher & Editor of Low-Latency.com) and Benjamin Stephens (Electronic Trading & Quantitative Prime Brokerage Origination at Nomura International)

Wednesday, 3 August 2011

14-10 Club @ the Royal Institution

I received an invitation to join the 14-10 Club and I will be attending their meetups from October onwards. This club is for finance professionals who have a background in science and mathematics and want to keep their interests alive!


"The Royal Institution was founded in 1799 to promote the application of science. Fittingly, it is now turning its attention to modern applications of science and maths and is delighted to be welcoming the finance community into the fold, through the 14-10 club. The club takes its name from the outstanding achievement of the Royal Institution, where 10 chemical elements were discovered and 14 Nobel Prizes won.


At the clubs monthly gatherings you will hear from scientists and mathematicians on topics as varied as cosmology, artificial intelligence and multi-dimensional mathematics- as well as from the top names in finance. The Royal Institution has put together a first class programme for the club's first six months. You will meet cosmologist John Barrow (Cambridge University); theoretical ecologist and past Government Chief Scientific Advisor, Lord Robert May (Oxford University); head quant at Barclays Capital and Risk magazine 'Quant of the Year 2011', Vladimir Piterbarg and Nobel Laureate and behavioural economist, Professor Daniel Kahneman (Princeton University)."


Further information can be found online at www.rigb.org/14-10club.