NPL
Neurological Programs and Libraries
npl::ExpMax Class Reference

Expectation Maximization With Gaussian Mixture Model. More...

#include <statistics.h>

Inherits npl::Classifier.

Public Member Functions

 ExpMax (size_t rank, size_t k=2)
 Constructor for k-means class. More...
 
void setk (size_t ngroups)
 Update the number of groups. Note that this invalidates any current information. More...
 
void updateMeanCovTau (const Ref< const MatrixXd > newmeans, const Ref< const MatrixXd > newcovs, const Ref< const VectorXd > tau)
 Sets the mean matrix. Each row of the matrix is a ND-mean, where N is the number of columns. More...
 
void updateMeanCovTau (const Ref< const MatrixXd > samples, Ref< MatrixXd > prob)
 Updates the mean/cov/tau coordinates by using the weighted class estimates (rather than hard classification, like the previous) More...
 
double expectation (const Ref< const MatrixXd > samples, Ref< MatrixXd > prob)
 Given a matrix of samples (Samples x Dims, sample on each row), apply the classifier to each sample and return a vector of the classes. More...
 
Eigen::VectorXi classify (const Ref< const MatrixXd > samples)
 Given a matrix of samples (Samples x Dims, sample on each row), apply the classifier to each sample and return a vector of the classes. More...
 
size_t classify (const Ref< const MatrixXd > samples, Ref< VectorXi > oclass)
 Given a matrix of samples (Samples x Dims, sample on each row), apply the classifier to each sample and return a vector of the classes. More...
 
int update (const Ref< const MatrixXd > samples, bool reinit=false)
 Updates the classifier with new samples, if reinit is true then no prior information will be used. If reinit is false then any existing information will be left intact. In Kmeans that would mean that the means will be left at their previous state. More...
 
const MatrixXd & getMeans ()
 Returns the current mean matrix. More...
 
const MatrixXd & getCovs ()
 Returns the current mean matrix. More...
 
void compute (const Ref< const MatrixXd > samples)
 Alias for updateClasses with reinit = true. This will perform a classification scheme on all the input samples. More...
 

Public Attributes

const int ndim
 Number of dimensions, must be set at construction. This is the number of columns in input samples. More...
 
int maxit
 Maximum number of iterations. Set below 0 for infinite. More...
 

Protected Attributes

bool m_valid
 Whether the classifier has been initialized yet. More...
 

Detailed Description

Expectation Maximization With Gaussian Mixture Model.

Definition at line 833 of file statistics.h.

Constructor & Destructor Documentation

npl::ExpMax::ExpMax ( size_t  rank,
size_t  k = 2 
)

Constructor for k-means class.

Parameters
rankNumber of dimensions in input samples.
kNumber of groups to classify samples into

Member Function Documentation

Eigen::VectorXi npl::ExpMax::classify ( const Ref< const MatrixXd >  samples)
virtual

Given a matrix of samples (Samples x Dims, sample on each row), apply the classifier to each sample and return a vector of the classes.

Parameters
samplesSet of samples, 1 per row
Returns
Vector of classes, rows match up with input sample rows

Implements npl::Classifier.

size_t npl::ExpMax::classify ( const Ref< const MatrixXd >  samples,
Ref< VectorXi >  oclass 
)
virtual

Given a matrix of samples (Samples x Dims, sample on each row), apply the classifier to each sample and return a vector of the classes.

Parameters
samplesSet of samples, 1 per row
oclassOutput classes. This vector will be resized to have the same number of rows as samples matrix.

Implements npl::Classifier.

void npl::Classifier::compute ( const Ref< const MatrixXd >  samples)
inlineinherited

Alias for updateClasses with reinit = true. This will perform a classification scheme on all the input samples.

Parameters
samplesSamples, S x D matrix with S is the number of samples and D is the dimensionality. This must match the internal dimension count.

Definition at line 713 of file statistics.h.

double npl::ExpMax::expectation ( const Ref< const MatrixXd >  samples,
Ref< MatrixXd >  prob 
)

Given a matrix of samples (Samples x Dims, sample on each row), apply the classifier to each sample and return a vector of the classes.

Parameters
samplesSet of samples, 1 per row
probClass probability of each sample, for each of the potential distributions
Returns
Change in summed likelihood
const MatrixXd& npl::ExpMax::getCovs ( )
inline

Returns the current mean matrix.

Returns
The current covariance matrix, with each covariance matrix stacked on top of the next.

Definition at line 936 of file statistics.h.

const MatrixXd& npl::ExpMax::getMeans ( )
inline

Returns the current mean matrix.

Returns
The current mean matrix

Definition at line 928 of file statistics.h.

void npl::ExpMax::setk ( size_t  ngroups)

Update the number of groups. Note that this invalidates any current information.

Parameters
ngroupsNumber of groups to classify
int npl::ExpMax::update ( const Ref< const MatrixXd >  samples,
bool  reinit = false 
)
virtual

Updates the classifier with new samples, if reinit is true then no prior information will be used. If reinit is false then any existing information will be left intact. In Kmeans that would mean that the means will be left at their previous state.

Parameters
samplesSamples, S x D matrix with S is the number of samples and D is the dimensionality. This must match the internal dimension count.
reinitwhether to reinitialize the classifier before updating

return 0 if converged, -1 otherwise

Implements npl::Classifier.

void npl::ExpMax::updateMeanCovTau ( const Ref< const MatrixXd >  newmeans,
const Ref< const MatrixXd >  newcovs,
const Ref< const VectorXd >  tau 
)

Sets the mean matrix. Each row of the matrix is a ND-mean, where N is the number of columns.

Parameters
newmeansMatrix with new mean, means are stacked so that each row represents a group mean
newmeansMatrix with new coviance matrices. Covariance matrices are stacked so that row ndim*k gets the first element of the k'th covance matrix.
newcovsthe new covariance matrices to set in the classifier
tauthe prior probaibilities of each of the mixture gaussians
void npl::ExpMax::updateMeanCovTau ( const Ref< const MatrixXd >  samples,
Ref< MatrixXd >  prob 
)

Updates the mean/cov/tau coordinates by using the weighted class estimates (rather than hard classification, like the previous)

Parameters
samplesMatrix of samples, where each row is an ND-sample.
probProbability that each sample is in a given distribution

Member Data Documentation

bool npl::Classifier::m_valid
protectedinherited

Whether the classifier has been initialized yet.

Definition at line 732 of file statistics.h.

int npl::Classifier::maxit
inherited

Maximum number of iterations. Set below 0 for infinite.

Definition at line 727 of file statistics.h.

const int npl::Classifier::ndim
inherited

Number of dimensions, must be set at construction. This is the number of columns in input samples.

Definition at line 716 of file statistics.h.


The documentation for this class was generated from the following file: