Sei sulla pagina 1di 5

OpenVision Library Gaussian Mixture Implementation

Pi19404
March 2, 2014

Contents

Contents
OpenVision Library Gaussian Mixture Implementation
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 0.1.1 Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 0.1

3 5 5

2|5

OpenVision Library Gaussian Mixture Implementation

OpenVision Library Gaussian Mixture Implementation


0.1 Introduction

      

In this article we will look at gaussian mixture model. Mixture Models are a type of density model which comprise a number of component functions, usually Gaussian. These component functions are combined to provide a multimodal density. GMM is a weighted average of gaussians where gaussian by its own mean can covariance matrix matrix The mixture density is given by

P (X j; ; w) =

P w N (X;  ; )
k k k k

To compute the likelyhood that a random variable is sampled from the mixture model we just need to compute the probability of individual gaussian component and then find the weighted average. Instead of probability we can compute the log likelyhood of gaussian components which would simply be the log of sum of weighted exponentials.

L(X j; ; w) = log

P exp(logw
k

+ logN (X; k ; k ))

A gaussian mixture model is characterized by

 Number of mixture components  Weights of mixtures  Mean and covariances of individual mixture components
Thus given the model parameters computation of probability that a vector is sampled from the gaussian mixture model is fairly simple

3|5

OpenVision Library Gaussian Mixture Implementation

vector<Gaussian> components; /** * @brief ProbMix:method returns the probability that * vector X belongs to each of mixture gaussian * @param X : input vector X * @return :output vector of probabilities */ vector<float> ProbMix(Mat X) { vector<float> res; res.resize(_nmix); for(int i=0;i<_nmix;i++) { // cerr << _weights[i] << endl; res[i]=(_components[i].Prob(X)); } return res; } /** * @brief Prob : method computes the probability that vector X * is drawn from the gaussian mixture model * @param X : input vector X * @return */ float Prob(Mat X) { float res=0; for(int i=0;i<_nmix;i++) { // cerr << _weights[i] << endl; res=res+_weights[i]*(_components[i].Prob(X)); } return res; }

For example if we consider the following mixture models

MU1 = [1 2]; SIGMA1 = [2 0; 0 .5]; MU2 = [-3 -5]; SIGMA2 = [1 0; 0 1];

4|5

OpenVision Library Gaussian Mixture Implementation

priors=[0.4 0.6]; X=[1.1 2.3];

  

The probability that vector X belongs to GMM is computed as 0:0580374 using the method Prob The probability that vector X belongs to individual mixture components is computed as 0:145093 : 9:5455e 17 Both the above results can be verified by manual calculation or other packages etc.

0.1.1 Code

 

The code for the same can be found in OpenVision git repository https://github.com/pi19404/OpenVision in files ImgMl/gaussianmixture.cpp and ImgMl/gaussianmixture.hpp files. OpenVision is attempt at a opensource C/C++ Library developed in C/C++ using OpenCV,Eigen etc providing modular interface for image processing,computer vision,machine learning applications.

5|5

Potrebbero piacerti anche