OpenCV 2.4.3.2

org.opencv.ml
Class EM

java.lang.Object
  extended by org.opencv.core.Algorithm
      extended by org.opencv.ml.EM

public class EM
extends Algorithm

The class implements the EM algorithm as described in the beginning of this section. It is inherited from "Algorithm".

See Also:
org.opencv.ml.EM : public Algorithm

Field Summary
static int COV_MAT_DEFAULT
           
static int COV_MAT_DIAGONAL
           
static int COV_MAT_GENERIC
           
static int COV_MAT_SPHERICAL
           
static int DEFAULT_MAX_ITERS
           
static int DEFAULT_NCLUSTERS
           
static int START_AUTO_STEP
           
static int START_E_STEP
           
static int START_M_STEP
           
 
Constructor Summary
EM()
          The constructor of the class
EM(int nclusters, int covMatType, TermCriteria termCrit)
          The constructor of the class
 
Method Summary
 void clear()
           
 boolean isTrained()
           
 double[] predict(Mat sample)
          Returns a likelihood logarithm value and an index of the most probable mixture component for the given sample.
 double[] predict(Mat sample, Mat probs)
          Returns a likelihood logarithm value and an index of the most probable mixture component for the given sample.
 boolean train(Mat samples)
          Estimates the Gaussian mixture parameters from a samples set.
 boolean train(Mat samples, Mat logLikelihoods, Mat labels, Mat probs)
          Estimates the Gaussian mixture parameters from a samples set.
 boolean trainE(Mat samples, Mat means0)
           
 boolean trainE(Mat samples, Mat means0, Mat covs0, Mat weights0, Mat logLikelihoods, Mat labels, Mat probs)
           
 boolean trainM(Mat samples, Mat probs0)
           
 boolean trainM(Mat samples, Mat probs0, Mat logLikelihoods, Mat labels, Mat probs)
           
 
Methods inherited from class org.opencv.core.Algorithm
getBool, getDouble, getInt, getMat, getMatVector, getString, paramHelp, paramType, setBool, setDouble, setInt, setMat, setMatVector, setString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COV_MAT_DEFAULT

public static final int COV_MAT_DEFAULT
See Also:
Constant Field Values

COV_MAT_DIAGONAL

public static final int COV_MAT_DIAGONAL
See Also:
Constant Field Values

COV_MAT_GENERIC

public static final int COV_MAT_GENERIC
See Also:
Constant Field Values

COV_MAT_SPHERICAL

public static final int COV_MAT_SPHERICAL
See Also:
Constant Field Values

DEFAULT_MAX_ITERS

public static final int DEFAULT_MAX_ITERS
See Also:
Constant Field Values

DEFAULT_NCLUSTERS

public static final int DEFAULT_NCLUSTERS
See Also:
Constant Field Values

START_AUTO_STEP

public static final int START_AUTO_STEP
See Also:
Constant Field Values

START_E_STEP

public static final int START_E_STEP
See Also:
Constant Field Values

START_M_STEP

public static final int START_M_STEP
See Also:
Constant Field Values
Constructor Detail

EM

public EM()

The constructor of the class

See Also:
org.opencv.ml.EM.EM

EM

public EM(int nclusters,
          int covMatType,
          TermCriteria termCrit)

The constructor of the class

Parameters:
nclusters - The number of mixture components in the Gaussian mixture model. Default value of the parameter is EM.DEFAULT_NCLUSTERS=5. Some of EM implementation could determine the optimal number of mixtures within a specified value range, but that is not the case in ML yet.
covMatType - Constraint on covariance matrices which defines type of matrices. Possible values are:
  • EM.COV_MAT_SPHERICAL A scaled identity matrix mu_k * I. There is the only parameter mu_k to be estimated for each matrix. The option may be used in special cases, when the constraint is relevant, or as a first step in the optimization (for example in case when the data is preprocessed with PCA). The results of such preliminary estimation may be passed again to the optimization procedure, this time with covMatType=EM.COV_MAT_DIAGONAL.
  • EM.COV_MAT_DIAGONAL A diagonal matrix with positive diagonal elements. The number of free parameters is d for each matrix. This is most commonly used option yielding good estimation results.
  • EM.COV_MAT_GENERIC A symmetric positively defined matrix. The number of free parameters in each matrix is about d^2/2. It is not recommended to use this option, unless there is pretty accurate initial estimation of the parameters and/or a huge number of training samples.
termCrit - The termination criteria of the EM algorithm. The EM algorithm can be terminated by the number of iterations termCrit.maxCount (number of M-steps) or when relative change of likelihood logarithm is less than termCrit.epsilon. Default maximum number of iterations is EM.DEFAULT_MAX_ITERS=100.
See Also:
org.opencv.ml.EM.EM
Method Detail

clear

public void clear()

isTrained

public boolean isTrained()

predict

public double[] predict(Mat sample)

Returns a likelihood logarithm value and an index of the most probable mixture component for the given sample.

The method returns a two-element double vector. Zero element is a likelihood logarithm value for the sample. First element is an index of the most probable mixture component for the given sample.

Parameters:
sample - A sample for classification. It should be a one-channel matrix of 1 x dims or dims x 1 size.
See Also:
org.opencv.ml.EM.predict

predict

public double[] predict(Mat sample,
                        Mat probs)

Returns a likelihood logarithm value and an index of the most probable mixture component for the given sample.

The method returns a two-element double vector. Zero element is a likelihood logarithm value for the sample. First element is an index of the most probable mixture component for the given sample.

Parameters:
sample - A sample for classification. It should be a one-channel matrix of 1 x dims or dims x 1 size.
probs - Optional output matrix that contains posterior probabilities of each component given the sample. It has 1 x nclusters size and CV_64FC1 type.
See Also:
org.opencv.ml.EM.predict

train

public boolean train(Mat samples)

Estimates the Gaussian mixture parameters from a samples set.

Three versions of training method differ in the initialization of Gaussian mixture model parameters and start step:

The methods return true if the Gaussian mixture model was trained successfully, otherwise it returns false.

Unlike many of the ML models, EM is an unsupervised learning algorithm and it does not take responses (class labels or function values) as input. Instead, it computes the *Maximum Likelihood Estimate* of the Gaussian mixture parameters from an input sample set, stores all the parameters inside the structure: p_(i,k) in probs, a_k in means, S_k in covs[k], pi_k in weights, and optionally computes the output "class label" for each sample: labels_i=arg max_k(p_(i,k)), i=1..N (indices of the most probable mixture component for each sample).

The trained model can be used further for prediction, just like any other classifier. The trained model is similar to the "CvNormalBayesClassifier".

Parameters:
samples - Samples from which the Gaussian mixture model will be estimated. It should be a one-channel matrix, each row of which is a sample. If the matrix does not have CV_64F type it will be converted to the inner matrix of such type for the further computing.
See Also:
org.opencv.ml.EM.train

train

public boolean train(Mat samples,
                     Mat logLikelihoods,
                     Mat labels,
                     Mat probs)

Estimates the Gaussian mixture parameters from a samples set.

Three versions of training method differ in the initialization of Gaussian mixture model parameters and start step:

The methods return true if the Gaussian mixture model was trained successfully, otherwise it returns false.

Unlike many of the ML models, EM is an unsupervised learning algorithm and it does not take responses (class labels or function values) as input. Instead, it computes the *Maximum Likelihood Estimate* of the Gaussian mixture parameters from an input sample set, stores all the parameters inside the structure: p_(i,k) in probs, a_k in means, S_k in covs[k], pi_k in weights, and optionally computes the output "class label" for each sample: labels_i=arg max_k(p_(i,k)), i=1..N (indices of the most probable mixture component for each sample).

The trained model can be used further for prediction, just like any other classifier. The trained model is similar to the "CvNormalBayesClassifier".

Parameters:
samples - Samples from which the Gaussian mixture model will be estimated. It should be a one-channel matrix, each row of which is a sample. If the matrix does not have CV_64F type it will be converted to the inner matrix of such type for the further computing.
logLikelihoods - The optional output matrix that contains a likelihood logarithm value for each sample. It has nsamples x 1 size and CV_64FC1 type.
labels - The optional output "class label" for each sample: labels_i=arg max_k(p_(i,k)), i=1..N (indices of the most probable mixture component for each sample). It has nsamples x 1 size and CV_32SC1 type.
probs - The optional output matrix that contains posterior probabilities of each Gaussian mixture component given the each sample. It has nsamples x nclusters size and CV_64FC1 type.
See Also:
org.opencv.ml.EM.train

trainE

public boolean trainE(Mat samples,
                      Mat means0)

trainE

public boolean trainE(Mat samples,
                      Mat means0,
                      Mat covs0,
                      Mat weights0,
                      Mat logLikelihoods,
                      Mat labels,
                      Mat probs)

trainM

public boolean trainM(Mat samples,
                      Mat probs0)

trainM

public boolean trainM(Mat samples,
                      Mat probs0,
                      Mat logLikelihoods,
                      Mat labels,
                      Mat probs)

OpenCV 2.4.3.2 Documentation