NPL
Neurological Programs and Libraries
npl::KMeans Class Reference

K-means classifier. More...

#include <statistics.h>

Inherits npl::Classifier.

Public Member Functions

 KMeans (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 updateMeans (const Ref< const MatrixXd > newmeans)
 Sets the mean matrix. Each row of the matrix is a ND-mean, where N is the number of columns. More...
 
void updateMeans (const Ref< const MatrixXd > samples, const Ref< const Eigen::VectorXi > classes)
 Updates the mean coordinates by providing a set of labeled samples. More...
 
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...
 
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

K-means classifier.

Definition at line 739 of file statistics.h.

Constructor & Destructor Documentation

npl::KMeans::KMeans ( 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

VectorXi npl::KMeans::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::KMeans::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.

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

Returns the current mean matrix.

Returns
The current mean matrix

Definition at line 816 of file statistics.h.

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

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

Parameters
ngroupsNumber of groups to classify
int npl::KMeans::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
Returns
-1 if maximum number of iterations hit, 0 otherwise

Implements npl::Classifier.

void npl::KMeans::updateMeans ( const Ref< const MatrixXd >  newmeans)

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
void npl::KMeans::updateMeans ( const Ref< const MatrixXd >  samples,
const Ref< const Eigen::VectorXi >  classes 
)

Updates the mean coordinates by providing a set of labeled samples.

Parameters
samplesMatrix of samples, where each row is an ND-sample.
classesClasses, where rows match the rows of the samples matrix. Classes should be integers 0 <= c < K where K is the number of classes in this.

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: