Tuesday, December 19, 2017

Object Functional Programming

Object functional programming can be considered as a mix of object oriented programming and functional programming. While standard OOPS approach will focus on objects, and standard functional programming function will focus on functions, object functional programming will focus on object transformations - resulting in higher productivity and quality.



References

http://www.artima.com/weblogs/viewpost.jsp?thread=275983
https://academy.realm.io/posts/altconf-saul-mora-object-orientated-functional-programming/

Sunday, December 3, 2017

Transducing in JS

Say there is a list

var list = [3,4,7,8,11,14,15]

And we want to apply following function to each element

function add1 (n) { return n+1;}

And then filter out only the odd numbers

function isOdd (n) { return n%%2=1;}

And then get sum of those numbers

function sum (total, n) { return total +n };


This can be done :

list
.map(add1)
.filter(isOdd)
.reduce(sum);

This can be reduced to a one line code by using transducer which takes up a sum function as combiner.

Transducer will compose mapReducer and filterReducer together.



Further Reading

frontendmasters.com
Full code - https://gist.github.com/getify/7ba2b8f5a50116f3efa2849e4c6d1f79
http://jlongster.com/Transducers.js--A-JavaScript-Library-for-Transformation-of-Data




Proper Tail Calls, CPS, Trampolines

Proper Tail Calls allows us to run a program with recursive calls without blowing up stack memory.  Tail calls are functions which can be executed without growing stack.

In addition to having proper tail calls, we can implement TCO - Tail Call Optimizations to improve performance of tail recursive functions.

Continuation Passing Style can be used for advanced recursion.

Using Trampolines, we will be calling functions one by one and can get around limitations of having no PTC support. A Trampoline expects a continuation function and executes the same whenever it gets one.

Further Reading
http://lucasfcosta.com/2017/05/08/All-About-Recursion-PTC-TCO-and-STC-in-JavaScript.html
frontendmasters.com
http://www.datchley.name/recursion-tail-calls-and-trampolines/

Saturday, December 2, 2017

Closures, Partial functions and Currying

Closure is when a function "remembers" the variables around it even when the function is executed elsewhere.

Any language that implements lexically scoped name binding with first class functions will have closures. It can be considered as a record storing function and its environment.

Partial functions and Currying are two different techniques for specializing a generalized functions. Partial functions will take some arguments at one time and rest at other time. Currying on the other hand provides arguments one by one for specialization. Currying is kind of calling partial function automatically at each level with one argument




Further Reading

frontendmasters.com

Porter's Five Forces Framework

Analysis of forces close to a company that affect its ability to serve its customers and make a profit.

Based on structure, conduct, performance paradigm in IO economics

Five Forces are

- Bargaining Power of Suppliers
- Threat of New Entrants
- Threat of Substitutes
- Bargaining Power of Buyers
- Industrial Rivalry

Friday, December 1, 2017

The Circles Method

C - Comprehend situation : What , Who, Why, How?

I -  Identify Personas / customers

R - Report customer needs - as ___, I want ___ that ____

C - Cut, through prioritization > ROI Estimate?

L - List Solutions

E - Evaluate trade offs: thoughtful, analytical, objective

S - Summarize recommendation - what, why vs others, recap.




References & Further Reading

https://www.impactinterview.com/2016/08/circles-method-product-design-framework/

Jupyter Notebooks - 1

Jupyter Notebook is essentially a web app that allows us to combine explanatory text, code, equations, visualizations etc in a document that can be shared.

Notebooks are a form of literate programming.

Notebook server which is the core of all interactions via Notebook support a number of kernels.

Read more about how IPython (kernel for python) & Jupyter Notebook works at

https://jupyter.readthedocs.io/en/latest/architecture/how_jupyter_ipython_work.html

Here's a reference diagram from that documentation:





Further Reading:
Setting up remote kernel - http://jupyter-notebook.readthedocs.io/en/latest/public_server.html

Monday, November 27, 2017

Anomaly Detection - 1

On a broad level, anomalies can be classified as point anomalies, contextual anomalies and collective anomalies.

Here's some of techniques that can be used to detect anomalies

1.  Statistical Methods

Flag data points that deviate from common statistical properties of a distribution - mean, mode, median, quantile.

We can use rolling average or moving average to smoothen short term fluctuations. A low pass filter can be used by n-period simple moving average.

2.  Density Based Anomaly Detection

This technique assumes that normal data points will occur around a dense neighborhood and the abnormalities will be far away (based on k-nearest neighbors algorithm or local outlier factor).

3. Clustering (e.g. K-means clustering algorithm)

4. Support Vector Machine - Variants of SVM like One-Class SVM can be used for anomaly detection.



Further Reading: 

1.https://en.wikipedia.org/wiki/Anomaly_detection
2.http://www.nehalemlabs.net/prototype/blog/2013/04/05/an-introduction-to-smoothing-time-series-in-python-part-i-filtering-theory/
3.https://bugra.github.io/work/notes/2014-03-31/outlier-detection-in-time-series-signals-fft-median-filtering/

NLP Basics - 1

Tokenization - Process of segmenting running text into words and sentences.

Normalization - Steps we take to condense terms into lexical units.

Named Entity Extraction - Locate and classify named entities in text into pre-defined categories

Stemming - Reducing inflected words to their root form.

Lemmatization - Grouping together inflected forms of a words so that they can be analyzed as a single item.




API  Links:

1. Watson - https://www.ibm.com/watson/services/natural-language-classifier/
2. Google Cloud Platform - https://cloud.google.com/natural-language/
3. Amazon Lex - https://aws.amazon.com/lex/
4. Facebook Deep Text - https://code.facebook.com/posts/181565595577955/introducing-deeptext-facebook-s-text-understanding-engine/
5. Microsoft Cognitive Services - https://azure.microsoft.com/en-in/services/cognitive-services/directory/lang/



References:

https://www.ibm.com/developerworks/community/blogs/nlp/entry/tokenization?lang=en

Saturday, November 25, 2017

Interpreting ML Models - 1

Data Leakage - When information available in the context of model training is unavailable in deployment setting

Feature Importance Algorithm - Describes magnitude of dependance a model has on a feature

FairML can be used to measure model's dependence on its inputs

1. Seeing Data - glyphs, correlation graphs, 2-d projections, partial dependence plots, residual analysis

2. Related Models - OLS regression : penalized regression, generalized additive models, quantile regression

3. Understanding complex learning models: Surrogate modes, Local Interpretable Model agnostic explanations (LIME) , LOCO, Tree Interpreter.







References & Further Reading:

http://blog.fastforwardlabs.com/2017/03/09/fairml-auditing-black-box-predictive-models.html
https://www.oreilly.com/ideas/ideas-on-interpreting-machine-learning
http://www.nature.com/news/can-we-open-the-black-box-of-ai-1.20731
https://homes.cs.washington.edu/~marcotcr/blog/lime/

Friday, November 24, 2017

AI Environments

Here's some basic terminology related to environments in AI


1. Fully vs Partially Observable Environment / System

An environment is called fully observable if the what the intelligent agent senses is good enough to make an optimal decision.

In partially observable systems, an intelligent agent will generally need some memory to make the best possible action.

2. Deterministic vs Stochastic Environment

If we can uniquely determine outcomes from agent's actions, we are in an deterministic environment. If there is an element of randomness that impacts the outcome, we are in a stochastic environment.

3.  Discrete vs Continous

Discrete: We have finitely many action choices or finitely many things that can be sensed (e.g. Chess)
Continous: Space of possible actions or things we can sense may be infinite

4. Benign vs Adversarial Environments

Benign : Environment might be random/ stochastic but it has no objectives of its own to contradict your own objectives

Adversarial: There is an agent which actively observes you and counteracts what you are trying to achieve