OpenCV for Unity  2.6.0
Enox Software / Please refer to OpenCV official document ( http://docs.opencv.org/4.9.0/index.html ) for the details of the argument of the method.
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | List of all members
OpenCVForUnity.MlModule.EM Class Reference

The class implements the Expectation Maximization algorithm. More...

Inheritance diagram for OpenCVForUnity.MlModule.EM:
OpenCVForUnity.MlModule.StatModel OpenCVForUnity.CoreModule.Algorithm OpenCVForUnity.DisposableOpenCVObject OpenCVForUnity.DisposableObject

Public Member Functions

int getClustersNumber ()
 
void setClustersNumber (int val)
 
int getCovarianceMatrixType ()
 
void setCovarianceMatrixType (int val)
 
TermCriteria getTermCriteria ()
 
void setTermCriteria (TermCriteria val)
 
Mat getWeights ()
 Returns weights of the mixtures. More...
 
Mat getMeans ()
 Returns the cluster centers (means of the Gaussian mixture) More...
 
void getCovs (List< Mat > covs)
 Returns covariation matrices. More...
 
override float predict (Mat samples, Mat results, int flags)
 Returns posterior probabilities for the provided samples. More...
 
override float predict (Mat samples, Mat results)
 Returns posterior probabilities for the provided samples. More...
 
override float predict (Mat samples)
 Returns posterior probabilities for the provided samples. More...
 
double [] predict2 (Mat sample, Mat probs)
 Returns a likelihood logarithm value and an index of the most probable mixture component for the given sample. More...
 
bool trainEM (Mat samples, Mat logLikelihoods, Mat labels, Mat probs)
 Estimate the Gaussian mixture parameters from a samples set. More...
 
bool trainEM (Mat samples, Mat logLikelihoods, Mat labels)
 Estimate the Gaussian mixture parameters from a samples set. More...
 
bool trainEM (Mat samples, Mat logLikelihoods)
 Estimate the Gaussian mixture parameters from a samples set. More...
 
bool trainEM (Mat samples)
 Estimate the Gaussian mixture parameters from a samples set. More...
 
bool trainE (Mat samples, Mat means0, Mat covs0, Mat weights0, Mat logLikelihoods, Mat labels, Mat probs)
 Estimate the Gaussian mixture parameters from a samples set. More...
 
bool trainE (Mat samples, Mat means0, Mat covs0, Mat weights0, Mat logLikelihoods, Mat labels)
 Estimate the Gaussian mixture parameters from a samples set. More...
 
bool trainE (Mat samples, Mat means0, Mat covs0, Mat weights0, Mat logLikelihoods)
 Estimate the Gaussian mixture parameters from a samples set. More...
 
bool trainE (Mat samples, Mat means0, Mat covs0, Mat weights0)
 Estimate the Gaussian mixture parameters from a samples set. More...
 
bool trainE (Mat samples, Mat means0, Mat covs0)
 Estimate the Gaussian mixture parameters from a samples set. More...
 
bool trainE (Mat samples, Mat means0)
 Estimate the Gaussian mixture parameters from a samples set. More...
 
bool trainM (Mat samples, Mat probs0, Mat logLikelihoods, Mat labels, Mat probs)
 Estimate the Gaussian mixture parameters from a samples set. More...
 
bool trainM (Mat samples, Mat probs0, Mat logLikelihoods, Mat labels)
 Estimate the Gaussian mixture parameters from a samples set. More...
 
bool trainM (Mat samples, Mat probs0, Mat logLikelihoods)
 Estimate the Gaussian mixture parameters from a samples set. More...
 
bool trainM (Mat samples, Mat probs0)
 Estimate the Gaussian mixture parameters from a samples set. More...
 
- Public Member Functions inherited from OpenCVForUnity.MlModule.StatModel
int getVarCount ()
 Returns the number of variables in training samples. More...
 
override bool empty ()
 Returns true if the Algorithm is empty (e.g. in the very beginning or after unsuccessful read. More...
 
bool isTrained ()
 Returns true if the model is trained. More...
 
bool isClassifier ()
 Returns true if the model is classifier. More...
 
bool train (TrainData trainData, int flags)
 Trains the statistical model. More...
 
bool train (TrainData trainData)
 Trains the statistical model. More...
 
bool train (Mat samples, int layout, Mat responses)
 Trains the statistical model. More...
 
float calcError (TrainData data, bool test, Mat resp)
 Computes error on the training or test dataset. More...
 
- Public Member Functions inherited from OpenCVForUnity.CoreModule.Algorithm
IntPtr getNativeObjAddr ()
 
virtual void clear ()
 Clears the algorithm state. More...
 
void save (string filename)
 
virtual string getDefaultName ()
 
- Public Member Functions inherited from OpenCVForUnity.DisposableObject
void Dispose ()
 
void ThrowIfDisposed ()
 

Static Public Member Functions

static new EM __fromPtr__ (IntPtr addr)
 
static EM create ()
 
static EM load (string filepath, string nodeName)
 Loads and creates a serialized EM from a file. More...
 
static EM load (string filepath)
 Loads and creates a serialized EM from a file. More...
 
- Static Public Member Functions inherited from OpenCVForUnity.MlModule.StatModel
static new StatModel __fromPtr__ (IntPtr addr)
 
- Static Public Member Functions inherited from OpenCVForUnity.CoreModule.Algorithm
static Algorithm __fromPtr__ (IntPtr addr)
 
- Static Public Member Functions inherited from OpenCVForUnity.DisposableObject
static IntPtr ThrowIfNullIntPtr (IntPtr ptr)
 

Public Attributes

const int DEFAULT_NCLUSTERS = 5
 
const int DEFAULT_MAX_ITERS = 100
 
const int START_E_STEP = 1
 
const int START_M_STEP = 2
 
const int START_AUTO_STEP = 0
 
const int COV_MAT_SPHERICAL = 0
 
const int COV_MAT_DIAGONAL = 1
 
const int COV_MAT_GENERIC = 2
 
const int COV_MAT_DEFAULT = COV_MAT_DIAGONAL
 
- Public Attributes inherited from OpenCVForUnity.MlModule.StatModel
const int UPDATE_MODEL = 1
 
const int RAW_OUTPUT = 1
 
const int COMPRESSED_INPUT = 2
 
const int PREPROCESSED_INPUT = 4
 

Protected Member Functions

override void Dispose (bool disposing)
 
- Protected Member Functions inherited from OpenCVForUnity.MlModule.StatModel
override void Dispose (bool disposing)
 
- Protected Member Functions inherited from OpenCVForUnity.DisposableOpenCVObject
 DisposableOpenCVObject ()
 
 DisposableOpenCVObject (IntPtr ptr)
 
 DisposableOpenCVObject (bool isEnabledDispose)
 
 DisposableOpenCVObject (IntPtr ptr, bool isEnabledDispose)
 
- Protected Member Functions inherited from OpenCVForUnity.DisposableObject
 DisposableObject ()
 
 DisposableObject (bool isEnabledDispose)
 

Additional Inherited Members

- Properties inherited from OpenCVForUnity.DisposableObject
bool IsDisposed [get, protected set]
 
bool IsEnabledDispose [get, set]
 

Detailed Description

The class implements the Expectation Maximization algorithm.

See also
ml_intro_em

Member Function Documentation

◆ __fromPtr__()

static new EM OpenCVForUnity.MlModule.EM.__fromPtr__ ( IntPtr  addr)
static

◆ create()

static EM OpenCVForUnity.MlModule.EM.create ( )
static

Creates empty EM model. The model should be trained then using StatModel::train(traindata, flags) method. Alternatively, you can use one of the EM::train* methods or load it from file using Algorithm::load<EM>(filename).

◆ Dispose()

override void OpenCVForUnity.MlModule.EM.Dispose ( bool  disposing)
protectedvirtual

◆ getClustersNumber()

int OpenCVForUnity.MlModule.EM.getClustersNumber ( )

◆ getCovarianceMatrixType()

int OpenCVForUnity.MlModule.EM.getCovarianceMatrixType ( )

◆ getCovs()

void OpenCVForUnity.MlModule.EM.getCovs ( List< Mat covs)

Returns covariation matrices.

Returns vector of covariation matrices. Number of matrices is the number of gaussian mixtures, each matrix is a square floating-point matrix NxN, where N is the space dimensionality.

◆ getMeans()

Mat OpenCVForUnity.MlModule.EM.getMeans ( )

Returns the cluster centers (means of the Gaussian mixture)

Returns matrix with the number of rows equal to the number of mixtures and number of columns equal to the space dimensionality.

◆ getTermCriteria()

TermCriteria OpenCVForUnity.MlModule.EM.getTermCriteria ( )
See also
setTermCriteria

◆ getWeights()

Mat OpenCVForUnity.MlModule.EM.getWeights ( )

Returns weights of the mixtures.

Returns vector with the number of elements equal to the number of mixtures.

◆ load() [1/2]

static EM OpenCVForUnity.MlModule.EM.load ( string  filepath,
string  nodeName 
)
static

Loads and creates a serialized EM from a file.

Use EM::save to serialize and store an EM to disk. Load the EM from this file again, by calling this function with the path to the file. Optionally specify the node for the file containing the classifier

Parameters
filepathpath to serialized EM
nodeNamename of node containing the classifier

◆ load() [2/2]

static EM OpenCVForUnity.MlModule.EM.load ( string  filepath)
static

Loads and creates a serialized EM from a file.

Use EM::save to serialize and store an EM to disk. Load the EM from this file again, by calling this function with the path to the file. Optionally specify the node for the file containing the classifier

Parameters
filepathpath to serialized EM
nodeNamename of node containing the classifier

◆ predict() [1/3]

override float OpenCVForUnity.MlModule.EM.predict ( Mat  samples,
Mat  results,
int  flags 
)
virtual

Returns posterior probabilities for the provided samples.

Parameters
samplesThe input samples, floating-point matrix
resultsThe optional output \( nSamples \times nClusters\) matrix of results. It contains posterior probabilities for each sample from the input
flagsThis parameter will be ignored

Reimplemented from OpenCVForUnity.MlModule.StatModel.

◆ predict() [2/3]

override float OpenCVForUnity.MlModule.EM.predict ( Mat  samples,
Mat  results 
)
virtual

Returns posterior probabilities for the provided samples.

Parameters
samplesThe input samples, floating-point matrix
resultsThe optional output \( nSamples \times nClusters\) matrix of results. It contains posterior probabilities for each sample from the input
flagsThis parameter will be ignored

Reimplemented from OpenCVForUnity.MlModule.StatModel.

◆ predict() [3/3]

override float OpenCVForUnity.MlModule.EM.predict ( Mat  samples)
virtual

Returns posterior probabilities for the provided samples.

Parameters
samplesThe input samples, floating-point matrix
resultsThe optional output \( nSamples \times nClusters\) matrix of results. It contains posterior probabilities for each sample from the input
flagsThis parameter will be ignored

Reimplemented from OpenCVForUnity.MlModule.StatModel.

◆ predict2()

double [] OpenCVForUnity.MlModule.EM.predict2 ( Mat  sample,
Mat  probs 
)

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

Parameters
sampleA sample for classification. It should be a one-channel matrix of \(1 \times dims\) or \(dims \times 1\) size.
probsOptional output matrix that contains posterior probabilities of each component given the sample. It has \(1 \times nclusters\) size and CV_64FC1 type.

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.

◆ setClustersNumber()

void OpenCVForUnity.MlModule.EM.setClustersNumber ( int  val)

◆ setCovarianceMatrixType()

void OpenCVForUnity.MlModule.EM.setCovarianceMatrixType ( int  val)

◆ setTermCriteria()

void OpenCVForUnity.MlModule.EM.setTermCriteria ( TermCriteria  val)
See also
getTermCriteria

◆ trainE() [1/6]

bool OpenCVForUnity.MlModule.EM.trainE ( Mat  samples,
Mat  means0,
Mat  covs0,
Mat  weights0,
Mat  logLikelihoods,
Mat  labels,
Mat  probs 
)

Estimate the Gaussian mixture parameters from a samples set.

This variation starts with Expectation step. You need to provide initial means \(a_k\) of mixture components. Optionally you can pass initial weights \(\pi_k\) and covariance matrices \(S_k\) of mixture components.

Parameters
samplesSamples 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.
means0Initial means \(a_k\) of mixture components. It is a one-channel matrix of \(nclusters \times dims\) size. If the matrix does not have CV_64F type it will be converted to the inner matrix of such type for the further computing.
covs0The vector of initial covariance matrices \(S_k\) of mixture components. Each of covariance matrices is a one-channel matrix of \(dims \times dims\) size. If the matrices do not have CV_64F type they will be converted to the inner matrices of such type for the further computing.
weights0Initial weights \(\pi_k\) of mixture components. It should be a one-channel floating-point matrix with \(1 \times nclusters\) or \(nclusters \times 1\) size.
logLikelihoodsThe optional output matrix that contains a likelihood logarithm value for each sample. It has \(nsamples \times 1\) size and CV_64FC1 type.
labelsThe optional output "class label" for each sample: \(\texttt{labels}_i=\texttt{arg max}_k(p_{i,k}), i=1..N\) (indices of the most probable mixture component for each sample). It has \(nsamples \times 1\) size and CV_32SC1 type.
probsThe optional output matrix that contains posterior probabilities of each Gaussian mixture component given the each sample. It has \(nsamples \times nclusters\) size and CV_64FC1 type.

◆ trainE() [2/6]

bool OpenCVForUnity.MlModule.EM.trainE ( Mat  samples,
Mat  means0,
Mat  covs0,
Mat  weights0,
Mat  logLikelihoods,
Mat  labels 
)

Estimate the Gaussian mixture parameters from a samples set.

This variation starts with Expectation step. You need to provide initial means \(a_k\) of mixture components. Optionally you can pass initial weights \(\pi_k\) and covariance matrices \(S_k\) of mixture components.

Parameters
samplesSamples 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.
means0Initial means \(a_k\) of mixture components. It is a one-channel matrix of \(nclusters \times dims\) size. If the matrix does not have CV_64F type it will be converted to the inner matrix of such type for the further computing.
covs0The vector of initial covariance matrices \(S_k\) of mixture components. Each of covariance matrices is a one-channel matrix of \(dims \times dims\) size. If the matrices do not have CV_64F type they will be converted to the inner matrices of such type for the further computing.
weights0Initial weights \(\pi_k\) of mixture components. It should be a one-channel floating-point matrix with \(1 \times nclusters\) or \(nclusters \times 1\) size.
logLikelihoodsThe optional output matrix that contains a likelihood logarithm value for each sample. It has \(nsamples \times 1\) size and CV_64FC1 type.
labelsThe optional output "class label" for each sample: \(\texttt{labels}_i=\texttt{arg max}_k(p_{i,k}), i=1..N\) (indices of the most probable mixture component for each sample). It has \(nsamples \times 1\) size and CV_32SC1 type.
probsThe optional output matrix that contains posterior probabilities of each Gaussian mixture component given the each sample. It has \(nsamples \times nclusters\) size and CV_64FC1 type.

◆ trainE() [3/6]

bool OpenCVForUnity.MlModule.EM.trainE ( Mat  samples,
Mat  means0,
Mat  covs0,
Mat  weights0,
Mat  logLikelihoods 
)

Estimate the Gaussian mixture parameters from a samples set.

This variation starts with Expectation step. You need to provide initial means \(a_k\) of mixture components. Optionally you can pass initial weights \(\pi_k\) and covariance matrices \(S_k\) of mixture components.

Parameters
samplesSamples 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.
means0Initial means \(a_k\) of mixture components. It is a one-channel matrix of \(nclusters \times dims\) size. If the matrix does not have CV_64F type it will be converted to the inner matrix of such type for the further computing.
covs0The vector of initial covariance matrices \(S_k\) of mixture components. Each of covariance matrices is a one-channel matrix of \(dims \times dims\) size. If the matrices do not have CV_64F type they will be converted to the inner matrices of such type for the further computing.
weights0Initial weights \(\pi_k\) of mixture components. It should be a one-channel floating-point matrix with \(1 \times nclusters\) or \(nclusters \times 1\) size.
logLikelihoodsThe optional output matrix that contains a likelihood logarithm value for each sample. It has \(nsamples \times 1\) size and CV_64FC1 type.
labelsThe optional output "class label" for each sample: \(\texttt{labels}_i=\texttt{arg max}_k(p_{i,k}), i=1..N\) (indices of the most probable mixture component for each sample). It has \(nsamples \times 1\) size and CV_32SC1 type.
probsThe optional output matrix that contains posterior probabilities of each Gaussian mixture component given the each sample. It has \(nsamples \times nclusters\) size and CV_64FC1 type.

◆ trainE() [4/6]

bool OpenCVForUnity.MlModule.EM.trainE ( Mat  samples,
Mat  means0,
Mat  covs0,
Mat  weights0 
)

Estimate the Gaussian mixture parameters from a samples set.

This variation starts with Expectation step. You need to provide initial means \(a_k\) of mixture components. Optionally you can pass initial weights \(\pi_k\) and covariance matrices \(S_k\) of mixture components.

Parameters
samplesSamples 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.
means0Initial means \(a_k\) of mixture components. It is a one-channel matrix of \(nclusters \times dims\) size. If the matrix does not have CV_64F type it will be converted to the inner matrix of such type for the further computing.
covs0The vector of initial covariance matrices \(S_k\) of mixture components. Each of covariance matrices is a one-channel matrix of \(dims \times dims\) size. If the matrices do not have CV_64F type they will be converted to the inner matrices of such type for the further computing.
weights0Initial weights \(\pi_k\) of mixture components. It should be a one-channel floating-point matrix with \(1 \times nclusters\) or \(nclusters \times 1\) size.
logLikelihoodsThe optional output matrix that contains a likelihood logarithm value for each sample. It has \(nsamples \times 1\) size and CV_64FC1 type.
labelsThe optional output "class label" for each sample: \(\texttt{labels}_i=\texttt{arg max}_k(p_{i,k}), i=1..N\) (indices of the most probable mixture component for each sample). It has \(nsamples \times 1\) size and CV_32SC1 type.
probsThe optional output matrix that contains posterior probabilities of each Gaussian mixture component given the each sample. It has \(nsamples \times nclusters\) size and CV_64FC1 type.

◆ trainE() [5/6]

bool OpenCVForUnity.MlModule.EM.trainE ( Mat  samples,
Mat  means0,
Mat  covs0 
)

Estimate the Gaussian mixture parameters from a samples set.

This variation starts with Expectation step. You need to provide initial means \(a_k\) of mixture components. Optionally you can pass initial weights \(\pi_k\) and covariance matrices \(S_k\) of mixture components.

Parameters
samplesSamples 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.
means0Initial means \(a_k\) of mixture components. It is a one-channel matrix of \(nclusters \times dims\) size. If the matrix does not have CV_64F type it will be converted to the inner matrix of such type for the further computing.
covs0The vector of initial covariance matrices \(S_k\) of mixture components. Each of covariance matrices is a one-channel matrix of \(dims \times dims\) size. If the matrices do not have CV_64F type they will be converted to the inner matrices of such type for the further computing.
weights0Initial weights \(\pi_k\) of mixture components. It should be a one-channel floating-point matrix with \(1 \times nclusters\) or \(nclusters \times 1\) size.
logLikelihoodsThe optional output matrix that contains a likelihood logarithm value for each sample. It has \(nsamples \times 1\) size and CV_64FC1 type.
labelsThe optional output "class label" for each sample: \(\texttt{labels}_i=\texttt{arg max}_k(p_{i,k}), i=1..N\) (indices of the most probable mixture component for each sample). It has \(nsamples \times 1\) size and CV_32SC1 type.
probsThe optional output matrix that contains posterior probabilities of each Gaussian mixture component given the each sample. It has \(nsamples \times nclusters\) size and CV_64FC1 type.

◆ trainE() [6/6]

bool OpenCVForUnity.MlModule.EM.trainE ( Mat  samples,
Mat  means0 
)

Estimate the Gaussian mixture parameters from a samples set.

This variation starts with Expectation step. You need to provide initial means \(a_k\) of mixture components. Optionally you can pass initial weights \(\pi_k\) and covariance matrices \(S_k\) of mixture components.

Parameters
samplesSamples 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.
means0Initial means \(a_k\) of mixture components. It is a one-channel matrix of \(nclusters \times dims\) size. If the matrix does not have CV_64F type it will be converted to the inner matrix of such type for the further computing.
covs0The vector of initial covariance matrices \(S_k\) of mixture components. Each of covariance matrices is a one-channel matrix of \(dims \times dims\) size. If the matrices do not have CV_64F type they will be converted to the inner matrices of such type for the further computing.
weights0Initial weights \(\pi_k\) of mixture components. It should be a one-channel floating-point matrix with \(1 \times nclusters\) or \(nclusters \times 1\) size.
logLikelihoodsThe optional output matrix that contains a likelihood logarithm value for each sample. It has \(nsamples \times 1\) size and CV_64FC1 type.
labelsThe optional output "class label" for each sample: \(\texttt{labels}_i=\texttt{arg max}_k(p_{i,k}), i=1..N\) (indices of the most probable mixture component for each sample). It has \(nsamples \times 1\) size and CV_32SC1 type.
probsThe optional output matrix that contains posterior probabilities of each Gaussian mixture component given the each sample. It has \(nsamples \times nclusters\) size and CV_64FC1 type.

◆ trainEM() [1/4]

bool OpenCVForUnity.MlModule.EM.trainEM ( Mat  samples,
Mat  logLikelihoods,
Mat  labels,
Mat  probs 
)

Estimate the Gaussian mixture parameters from a samples set.

This variation starts with Expectation step. Initial values of the model parameters will be estimated by the k-means algorithm.

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: \(\texttt{labels}_i=\texttt{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 NormalBayesClassifier.

Parameters
samplesSamples 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.
logLikelihoodsThe optional output matrix that contains a likelihood logarithm value for each sample. It has \(nsamples \times 1\) size and CV_64FC1 type.
labelsThe optional output "class label" for each sample: \(\texttt{labels}_i=\texttt{arg max}_k(p_{i,k}), i=1..N\) (indices of the most probable mixture component for each sample). It has \(nsamples \times 1\) size and CV_32SC1 type.
probsThe optional output matrix that contains posterior probabilities of each Gaussian mixture component given the each sample. It has \(nsamples \times nclusters\) size and CV_64FC1 type.

◆ trainEM() [2/4]

bool OpenCVForUnity.MlModule.EM.trainEM ( Mat  samples,
Mat  logLikelihoods,
Mat  labels 
)

Estimate the Gaussian mixture parameters from a samples set.

This variation starts with Expectation step. Initial values of the model parameters will be estimated by the k-means algorithm.

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: \(\texttt{labels}_i=\texttt{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 NormalBayesClassifier.

Parameters
samplesSamples 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.
logLikelihoodsThe optional output matrix that contains a likelihood logarithm value for each sample. It has \(nsamples \times 1\) size and CV_64FC1 type.
labelsThe optional output "class label" for each sample: \(\texttt{labels}_i=\texttt{arg max}_k(p_{i,k}), i=1..N\) (indices of the most probable mixture component for each sample). It has \(nsamples \times 1\) size and CV_32SC1 type.
probsThe optional output matrix that contains posterior probabilities of each Gaussian mixture component given the each sample. It has \(nsamples \times nclusters\) size and CV_64FC1 type.

◆ trainEM() [3/4]

bool OpenCVForUnity.MlModule.EM.trainEM ( Mat  samples,
Mat  logLikelihoods 
)

Estimate the Gaussian mixture parameters from a samples set.

This variation starts with Expectation step. Initial values of the model parameters will be estimated by the k-means algorithm.

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: \(\texttt{labels}_i=\texttt{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 NormalBayesClassifier.

Parameters
samplesSamples 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.
logLikelihoodsThe optional output matrix that contains a likelihood logarithm value for each sample. It has \(nsamples \times 1\) size and CV_64FC1 type.
labelsThe optional output "class label" for each sample: \(\texttt{labels}_i=\texttt{arg max}_k(p_{i,k}), i=1..N\) (indices of the most probable mixture component for each sample). It has \(nsamples \times 1\) size and CV_32SC1 type.
probsThe optional output matrix that contains posterior probabilities of each Gaussian mixture component given the each sample. It has \(nsamples \times nclusters\) size and CV_64FC1 type.

◆ trainEM() [4/4]

bool OpenCVForUnity.MlModule.EM.trainEM ( Mat  samples)

Estimate the Gaussian mixture parameters from a samples set.

This variation starts with Expectation step. Initial values of the model parameters will be estimated by the k-means algorithm.

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: \(\texttt{labels}_i=\texttt{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 NormalBayesClassifier.

Parameters
samplesSamples 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.
logLikelihoodsThe optional output matrix that contains a likelihood logarithm value for each sample. It has \(nsamples \times 1\) size and CV_64FC1 type.
labelsThe optional output "class label" for each sample: \(\texttt{labels}_i=\texttt{arg max}_k(p_{i,k}), i=1..N\) (indices of the most probable mixture component for each sample). It has \(nsamples \times 1\) size and CV_32SC1 type.
probsThe optional output matrix that contains posterior probabilities of each Gaussian mixture component given the each sample. It has \(nsamples \times nclusters\) size and CV_64FC1 type.

◆ trainM() [1/4]

bool OpenCVForUnity.MlModule.EM.trainM ( Mat  samples,
Mat  probs0,
Mat  logLikelihoods,
Mat  labels,
Mat  probs 
)

Estimate the Gaussian mixture parameters from a samples set.

This variation starts with Maximization step. You need to provide initial probabilities \(p_{i,k}\) to use this option.

Parameters
samplesSamples 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.
probs0the probabilities
logLikelihoodsThe optional output matrix that contains a likelihood logarithm value for each sample. It has \(nsamples \times 1\) size and CV_64FC1 type.
labelsThe optional output "class label" for each sample: \(\texttt{labels}_i=\texttt{arg max}_k(p_{i,k}), i=1..N\) (indices of the most probable mixture component for each sample). It has \(nsamples \times 1\) size and CV_32SC1 type.
probsThe optional output matrix that contains posterior probabilities of each Gaussian mixture component given the each sample. It has \(nsamples \times nclusters\) size and CV_64FC1 type.

◆ trainM() [2/4]

bool OpenCVForUnity.MlModule.EM.trainM ( Mat  samples,
Mat  probs0,
Mat  logLikelihoods,
Mat  labels 
)

Estimate the Gaussian mixture parameters from a samples set.

This variation starts with Maximization step. You need to provide initial probabilities \(p_{i,k}\) to use this option.

Parameters
samplesSamples 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.
probs0the probabilities
logLikelihoodsThe optional output matrix that contains a likelihood logarithm value for each sample. It has \(nsamples \times 1\) size and CV_64FC1 type.
labelsThe optional output "class label" for each sample: \(\texttt{labels}_i=\texttt{arg max}_k(p_{i,k}), i=1..N\) (indices of the most probable mixture component for each sample). It has \(nsamples \times 1\) size and CV_32SC1 type.
probsThe optional output matrix that contains posterior probabilities of each Gaussian mixture component given the each sample. It has \(nsamples \times nclusters\) size and CV_64FC1 type.

◆ trainM() [3/4]

bool OpenCVForUnity.MlModule.EM.trainM ( Mat  samples,
Mat  probs0,
Mat  logLikelihoods 
)

Estimate the Gaussian mixture parameters from a samples set.

This variation starts with Maximization step. You need to provide initial probabilities \(p_{i,k}\) to use this option.

Parameters
samplesSamples 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.
probs0the probabilities
logLikelihoodsThe optional output matrix that contains a likelihood logarithm value for each sample. It has \(nsamples \times 1\) size and CV_64FC1 type.
labelsThe optional output "class label" for each sample: \(\texttt{labels}_i=\texttt{arg max}_k(p_{i,k}), i=1..N\) (indices of the most probable mixture component for each sample). It has \(nsamples \times 1\) size and CV_32SC1 type.
probsThe optional output matrix that contains posterior probabilities of each Gaussian mixture component given the each sample. It has \(nsamples \times nclusters\) size and CV_64FC1 type.

◆ trainM() [4/4]

bool OpenCVForUnity.MlModule.EM.trainM ( Mat  samples,
Mat  probs0 
)

Estimate the Gaussian mixture parameters from a samples set.

This variation starts with Maximization step. You need to provide initial probabilities \(p_{i,k}\) to use this option.

Parameters
samplesSamples 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.
probs0the probabilities
logLikelihoodsThe optional output matrix that contains a likelihood logarithm value for each sample. It has \(nsamples \times 1\) size and CV_64FC1 type.
labelsThe optional output "class label" for each sample: \(\texttt{labels}_i=\texttt{arg max}_k(p_{i,k}), i=1..N\) (indices of the most probable mixture component for each sample). It has \(nsamples \times 1\) size and CV_32SC1 type.
probsThe optional output matrix that contains posterior probabilities of each Gaussian mixture component given the each sample. It has \(nsamples \times nclusters\) size and CV_64FC1 type.

Member Data Documentation

◆ COV_MAT_DEFAULT

const int OpenCVForUnity.MlModule.EM.COV_MAT_DEFAULT = COV_MAT_DIAGONAL

◆ COV_MAT_DIAGONAL

const int OpenCVForUnity.MlModule.EM.COV_MAT_DIAGONAL = 1

◆ COV_MAT_GENERIC

const int OpenCVForUnity.MlModule.EM.COV_MAT_GENERIC = 2

◆ COV_MAT_SPHERICAL

const int OpenCVForUnity.MlModule.EM.COV_MAT_SPHERICAL = 0

◆ DEFAULT_MAX_ITERS

const int OpenCVForUnity.MlModule.EM.DEFAULT_MAX_ITERS = 100

◆ DEFAULT_NCLUSTERS

const int OpenCVForUnity.MlModule.EM.DEFAULT_NCLUSTERS = 5

◆ START_AUTO_STEP

const int OpenCVForUnity.MlModule.EM.START_AUTO_STEP = 0

◆ START_E_STEP

const int OpenCVForUnity.MlModule.EM.START_E_STEP = 1

◆ START_M_STEP

const int OpenCVForUnity.MlModule.EM.START_M_STEP = 2

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