monadic genetic kernels in scala

36
Genetic Kernel Models in Scala Patrick Nicolas October 2015 patricknicolas.blogspot.com www.slideshare.net/pnicolas

Upload: patrick-nicolas

Post on 16-Apr-2017

651 views

Category:

Data & Analytics


0 download

TRANSCRIPT

PowerPoint Presentation

Monadic Genetic Kernel Modelsin ScalaPatrick NicolasOctober 2015

patricknicolas.blogspot.comwww.slideshare.net/pnicolas

Context of the presentation:The transition from Java and Python to Scala is not that easy: It goes beyond selecting Scala for its obvious benefits.- support functional concepts- leverage open source libraries and framework if needed- fast, distributed enough to handle large data setsScala was the most logical choice.

Scientific programming may very well involved different roles in a project:Mathematicians for formulasData scientists for data processing and modelingSoftware engineering for implementationDev. Ops and performance engineers for deployment in production

In order to ease the pain, we tend to to learn/adopt Scala incrementally within a development team.. The problem is that you end up with an inconsistent code base with different levels of quality and the team developed a somewhat negative attitude toward the language.

The solution is to select a list of problems or roadblocks (in our case Machine learning) and compare the solution in Scala with Java, Python ... (You sell the outcome not the process).

PresentationA set of diverse Scala features or constructs the entire team agreed that Scala is a far better solution than Python or Java.1

IntroductionThe creation and update of models require constant monitoring the quality of the prediction or classification. It entails the re-evaluation of model parameters, and kernel functions if necessary with a new set of labeled data.This presentation describes a solution to automate the evaluation and selection of a kernel function appropriate to a specific training set in online training.

Kernel functionsKernel functions are widely used in machine learning to deal with non-linear models for which the dimension of the problem is not readily known

Kernel principal components analysisKernelized multi-layer perceptronSupport vector machinesKernelized clusteringBayesian kernel density estimationKernelized ridge regression

3

Some background .

4

on kernel models.

v

Tangent planeManifoldProjection:Exponential familyw(w)K(v,w) =(v).(w)A kernel function, K is represented as a projection of features vectors v, w onto a manifold for which the similarity is computed from the Riemann metric.

Similarity v.w

5

Kernel function Define a kernel function as the composition of 2 functions g o hSimilarity function hA function g from the exponential familyRadius basis function (RBF)PolynomialSigmoid

6

What challenge?Creating a model require the evaluation of multiple kernel functions. This task is rarely automated and consumes a significant amount of human and computing resourcesTime series or sequential data may require loose kernel model definition which evolve overtime (online training)We need a mechanism to automate the generation, evaluation and optimization of kernel functions.

7

Challenge online trainingOnline training requires a constant re-evaluation of the model and refinement of the underlying kernel function.

F1 scoreSize training or observations set

Re-evaluation

Re-evaluationOnce the precision, recall or F1 score reaches a threshold, the model has to be retrained with the same or different kernel functions.Validrange

8

An approach to automation 1. Automated generation of kernel functions:A kernel function is composed from 3 different functions that can be assembled through monadic composition2. Automated optimization of kernel functions:A genetic algorithm computes the loss function associated with each kernel candidates (fitness) and select the most appropriate one for any specific dataset.

9

Monadic compositionGenetic selection

Kernel function Define a kernel function as the composition of 2 functions g o hSimilarity function hA function g from the exponential family

with its implementation in Scala

11

The similarity function, h is derived from the metric defined on the tangent space of a manifold. Here are few examples of similarity functions.

Similarity functions

The projection of the metric onto the manifold defines an exponential map or family of functions. Here are some examples from the exponential family {g}: Radius basis functions kernel, polynomial kernel and sigmoid kernelExponential map functions

ParameterizationKernel function are actually parameterized with a single value or argument . For example the parameter for the radius basis function is =1/2 where is the standard deviation and the parameter for the polynomial kernel is = d where d is the degree of the polynomial function.

A parameterized kernel function is defined as

The composition of the similarity (or metric) function h and the exponential map g can be accomplished through a monadic composition:Kernel composition Monads are high level abstractions derived from the theory of category. A monad defines a computation as a sequence of transformations of two typesmap: transforms a container type by modifying each of its element with a given functionflatMap: transforms a container by promoting each of its element as a container then reducing the resulting containers to a single type

A monad is defined as a Scala trait for a container type MThe monadic implementation of a kernel function of type KF consists of overriding the map and flatMap transformation.

Monadic composition

Monadic composition with parameterizationThe computation of the parameterized kernel function K(x, y) is broken down into three sequential stepsExecution of similarity function h (map) Application of the parameter (flatMap) Execution of the exponential map g (flatMap) The sequence is generated by applying a flatMap method to the output to a map or another flatMap monadic operations.

abbMonadic composition of parameterized kernelsabaImplementation of monadic composition using the for comprehensive loop notation

18

Monadic compositionGenetic selection

Brief introduction to genetic algorithms Genetic algorithms use reproduction to evolve a population of solutions to a problem.The components of a genetic algorithm are:Genetic encoding (and decoding): Conversion between a solution and a binary format (bits, string) known as chromosomeGenetic operations: Functions that extract the most genetically fit solutionGenetic fitness function: Criteria to evaluate each solution.

Reproduction cycle The reproduction cycle controls the population of chromosomes using three genetic operators:Selection: ranks chromosomes according to a fitness function Crossover: pairs chromosomes to generate offspring chromosomesMutation: introduces minor alteration in the genetic code

Genetic crossoverThe purpose of the genetic crossover is to expand the current population of chromosomes in order to intensify the competition and improve the genetic quality of the population

The offspring chromosomes are added to the population along with their parent to increase genetic diversity

Genetic mutationThe mutation procedure inserts a small variation in a chromosome to maintain some level of diversity between generations

The mutated chromosome is added to the population along with the original.

aaa01011101100010101010111000101110100nhngnKernel function: encoding Here an example of flat encoding for a parameterized kernel function.Note: A tree representation of the kernel function (Genetic programming) is a viable alternative.

Kernel function: cross-over 1 01011111010110101100101010110011110100110101000010110100111011hh111010011010100001011111010110101100101010hhParentsOff springsggggGenetic cross-over indexed on the exponential map.

25

Kernel function: cross-over 2 01011111010110101100101010110011110100110101000010110101111001hh111010011010100001011111010110101100101010hhParentsOff springsggggGenetic cross-over indexed on the lambda parameter

26

Kernel function: mutation 01011111010110101100101010hg01011111010111101100101010h'gOriginalMutatedOne-bit XOR genetic mutation indexed on the lambda parameter

Kernel function: fitness Given a kernel function K and a training set {xi}, a classifier model w is generated by minimizing the loss LkThe fitness of a kernel function is the F1 score over a new validation set.

Scala: EncoderEncoder for a Kernel function. The method apply (resp. unapply) implements the encoding (resp. decoding) algorithm Generic encoder for parameterized type

Scala: encodingEncoding for a Kernel function kf, given an implicit quantization scheme quant, for the lambda parameter, Conversion of the similarity function h, parameter and exponential map g into a bit stream.

30

Scala: DecodingConversion of bits representation of similarity function h, lambda parameter and exponential map g.Assembling of bit stream to instantiate a new kernel function

Scala: chromosome

Quantization for lambda parameter

Chromosome structure and genetic operators

Scala: cross-over

Chromosome cross-over at bit indexGene splicing at bit index

Scala: mutation

Chromosome mutation at bit indexGene cloning

ConclusionThe monadic composition and genetic encoding of kernel functions allows analytical engine to adaptive classification and prediction models to online trainingThe approach selects the kernel that is the most appropriate to new batches of labeled observations.

ReferencesMachine Learning: A Probabilistic Perspective 14.1 Kernels Introduction K. Murphy MIT Press 2012 Genetic Algorithms in Search, Optimization and Machine Learning D. Goldberg - Addison-Wesley 1989 Scala for Machine Learning 10 Genetic Algorithms P. Nicolas - Packt publishing 2014Introduction to Genetic Algorithms -Scaling of Relative Fitness E.D Goodman, Michigan State University 2009 World Summit on Genetic and Evolutionary Computation Introduction to Evolutionary Computing 2 What is an Evolutionary Algorithm? A. Eiben, J.E. Smith Springer 2003