Class EM
The class implements the Expectation Maximization algorithm.
Implements
Inherited Members
Namespace: OpenCvSharp
Assembly: OpenCvSharp.dll
Syntax
public class EM : Algorithm, ICvPtrHolder
Constructors
| Improve this Doc View SourceEM(IntPtr)
Creates instance by pointer cv::Ptr<EM>
Declaration
protected EM(IntPtr p)
Parameters
Type | Name | Description |
---|---|---|
IntPtr | p |
Fields
| Improve this Doc View SourceDEFAULT_MAX_ITERS
Declaration
public const int DEFAULT_MAX_ITERS = 100
Field Value
Type | Description |
---|---|
System.Int32 |
DEFAULT_NCLUSTERS
Declaration
public const int DEFAULT_NCLUSTERS = 5
Field Value
Type | Description |
---|---|
System.Int32 |
Properties
| Improve this Doc View SourceClustersNumber
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.
Declaration
public int ClustersNumber { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
CovarianceMatrixType
Constraint on covariance matrices which defines type of matrices.
Declaration
public int CovarianceMatrixType { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
TermCriteria
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.
Declaration
public TermCriteria TermCriteria { get; set; }
Property Value
Type | Description |
---|---|
OpenCvSharp.TermCriteria |
Methods
| Improve this Doc View SourceCreate()
Creates empty EM model.
Declaration
public static EM Create()
Returns
Type | Description |
---|---|
EM |
DisposeManaged()
Releases managed resources
Declaration
protected override void DisposeManaged()
Overrides
| Improve this Doc View SourceGetCovs()
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.
Declaration
public Mat[] GetCovs()
Returns
Type | Description |
---|---|
Mat[] |
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.
Declaration
public Mat GetMeans()
Returns
Type | Description |
---|---|
Mat |
GetWeights()
Returns weights of the mixtures. Returns vector with the number of elements equal to the number of mixtures.
Declaration
public Mat GetWeights()
Returns
Type | Description |
---|---|
Mat |
Load(String)
Loads and creates a serialized model from a file.
Declaration
public static EM Load(string filePath)
Parameters
Type | Name | Description |
---|---|---|
System.String | filePath |
Returns
Type | Description |
---|---|
EM |
LoadFromString(String)
Loads algorithm from a String.
Declaration
public static EM LoadFromString(string strModel)
Parameters
Type | Name | Description |
---|---|---|
System.String | strModel | he string variable containing the model you want to load. |
Returns
Type | Description |
---|---|
EM |
Predict2(InputArray, OutputArray)
Predicts the response for sample
Declaration
public virtual Vec2d Predict2(InputArray sample, OutputArray probs = null)
Parameters
Type | Name | Description |
---|---|---|
InputArray | sample | A sample for classification. It should be a one-channel matrix of \f$1 \times dims\f$ or \f$dims \times 1\f$ size. |
OutputArray | probs | Optional output matrix that contains posterior probabilities of each component given the sample. It has \f$1 \times nclusters\f$ size and CV_64FC1 type. |
Returns
Type | Description |
---|---|
Vec2d |
TrainE(InputArray, InputArray, InputArray, InputArray, OutputArray, OutputArray, OutputArray)
Estimate the Gaussian mixture parameters from a samples set.
Declaration
public virtual bool TrainE(InputArray samples, InputArray means0, InputArray covs0 = null, InputArray weights0 = null, OutputArray logLikelihoods = null, OutputArray labels = null, OutputArray probs = null)
Parameters
Type | Name | Description |
---|---|---|
InputArray | 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. |
InputArray | means0 | Initial means \f$a_k\f$ of mixture components. It is a one-channel matrix of \f$nclusters \times dims\f$ 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. |
InputArray | covs0 | The vector of initial covariance matrices \f$S_k\f$ of mixture components. Each of covariance matrices is a one-channel matrix of \f$dims \times dims\f$ 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. |
InputArray | weights0 | Initial weights \f$\pi_k\f$ of mixture components. It should be a one-channel floating-point matrix with \f$1 \times nclusters\f$ or \f$nclusters \times 1\f$ size. |
OutputArray | logLikelihoods | The optional output matrix that contains a likelihood logarithm value for each sample. It has \f$nsamples \times 1\f$ size and CV_64FC1 type. |
OutputArray | labels | The optional output "class label" for each sample: \f$\texttt{labels}_i=\texttt{arg max}k(p{i,k}), i=1..N\f$ (indices of the most probable mixture component for each sample). It has \f$nsamples \times 1\f$ size and CV_32SC1 type. |
OutputArray | probs | The optional output matrix that contains posterior probabilities of each Gaussian mixture component given the each sample. It has \f$nsamples \times nclusters\f$ size and CV_64FC1 type. |
Returns
Type | Description |
---|---|
System.Boolean |
TrainEM(InputArray, OutputArray, OutputArray, OutputArray)
Estimate the Gaussian mixture parameters from a samples set.
Declaration
public virtual bool TrainEM(InputArray samples, OutputArray logLikelihoods = null, OutputArray labels = null, OutputArray probs = null)
Parameters
Type | Name | Description |
---|---|---|
InputArray | 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. |
OutputArray | logLikelihoods | The optional output matrix that contains a likelihood logarithm value for each sample. It has \f$nsamples \times 1\f$ size and CV_64FC1 type. |
OutputArray | labels | The optional output "class label" for each sample: \f$\texttt{labels}_i=\texttt{arg max}k(p{i,k}), i=1..N\f$ (indices of the most probable mixture component for each sample). It has \f$nsamples \times 1\f$ size and CV_32SC1 type. |
OutputArray | probs | The optional output matrix that contains posterior probabilities of each Gaussian mixture component given the each sample. It has \f$nsamples \times nclusters\f$ size and CV_64FC1 type. |
Returns
Type | Description |
---|---|
System.Boolean |
TrainM(InputArray, InputArray, OutputArray, OutputArray, OutputArray)
Estimate the Gaussian mixture parameters from a samples set.
Declaration
public virtual bool TrainM(InputArray samples, InputArray probs0, OutputArray logLikelihoods = null, OutputArray labels = null, OutputArray probs = null)
Parameters
Type | Name | Description |
---|---|---|
InputArray | 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. |
InputArray | probs0 | the probabilities |
OutputArray | logLikelihoods | The optional output matrix that contains a likelihood logarithm value for each sample. It has \f$nsamples \times 1\f$ size and CV_64FC1 type. |
OutputArray | labels | The optional output "class label" for each sample: \f$\texttt{labels}_i=\texttt{arg max}k(p{i,k}), i=1..N\f$ (indices of the most probable mixture component for each sample). It has \f$nsamples \times 1\f$ size and CV_32SC1 type. |
OutputArray | probs | The optional output matrix that contains posterior probabilities of each Gaussian mixture component given the each sample. It has \f$nsamples \times nclusters\f$ size and CV_64FC1 type. |
Returns
Type | Description |
---|---|
System.Boolean |