Class EM
- Namespace
- OpenCvSharp
- Assembly
- OpenCvSharp.dll
The class implements the Expectation Maximization algorithm.
public class EM : Algorithm, IDisposable, ICvPtrHolder
- Inheritance
-
EM
- Implements
- Inherited Members
Constructors
EM(nint)
Creates instance by pointer cv::Ptr<EM>
protected EM(nint p)
Parameters
pnint
Fields
DEFAULT_MAX_ITERS
public const int DEFAULT_MAX_ITERS = 100
Field Value
DEFAULT_NCLUSTERS
public const int DEFAULT_NCLUSTERS = 5
Field Value
Properties
ClustersNumber
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.
public int ClustersNumber { get; set; }
Property Value
CovarianceMatrixType
Constraint on covariance matrices which defines type of matrices.
public int CovarianceMatrixType { get; set; }
Property Value
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.
public TermCriteria TermCriteria { get; set; }
Property Value
Methods
Create()
Creates empty EM model.
public static EM Create()
Returns
DisposeManaged()
Releases managed resources
protected override void DisposeManaged()
GetCovs()
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.
public Mat[] GetCovs()
Returns
- 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.
public Mat GetMeans()
Returns
GetWeights()
Returns weights of the mixtures. Returns vector with the number of elements equal to the number of mixtures.
public Mat GetWeights()
Returns
Load(string)
Loads and creates a serialized model from a file.
public static EM Load(string filePath)
Parameters
filePathstring
Returns
LoadFromString(string)
Loads algorithm from a String.
public static EM LoadFromString(string strModel)
Parameters
strModelstringhe string variable containing the model you want to load.
Returns
Predict2(InputArray, OutputArray?)
Predicts the response for sample
public virtual Vec2d Predict2(InputArray sample, OutputArray? probs = null)
Parameters
sampleInputArrayA sample for classification. It should be a one-channel matrix of \f$1 \times dims\f$ or \f$dims \times 1\f$ size.
probsOutputArrayOptional 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
TrainE(InputArray, InputArray, InputArray?, InputArray?, OutputArray?, OutputArray?, OutputArray?)
Estimate the Gaussian mixture parameters from a samples set.
public virtual bool TrainE(InputArray samples, InputArray means0, InputArray? covs0 = null, InputArray? weights0 = null, OutputArray? logLikelihoods = null, OutputArray? labels = null, OutputArray? probs = null)
Parameters
samplesInputArraySamples 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.
means0InputArrayInitial 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.
covs0InputArrayThe 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.
weights0InputArrayInitial 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.
logLikelihoodsOutputArrayThe optional output matrix that contains a likelihood logarithm value for each sample. It has \f$nsamples \times 1\f$ size and CV_64FC1 type.
labelsOutputArrayThe 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.
probsOutputArrayThe 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
TrainEM(InputArray, OutputArray?, OutputArray?, OutputArray?)
Estimate the Gaussian mixture parameters from a samples set.
public virtual bool TrainEM(InputArray samples, OutputArray? logLikelihoods = null, OutputArray? labels = null, OutputArray? probs = null)
Parameters
samplesInputArraySamples 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.
logLikelihoodsOutputArrayThe optional output matrix that contains a likelihood logarithm value for each sample. It has \f$nsamples \times 1\f$ size and CV_64FC1 type.
labelsOutputArrayThe 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.
probsOutputArrayThe 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
TrainM(InputArray, InputArray, OutputArray?, OutputArray?, OutputArray?)
Estimate the Gaussian mixture parameters from a samples set.
public virtual bool TrainM(InputArray samples, InputArray probs0, OutputArray? logLikelihoods = null, OutputArray? labels = null, OutputArray? probs = null)
Parameters
samplesInputArraySamples 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.
probs0InputArraythe probabilities
logLikelihoodsOutputArrayThe optional output matrix that contains a likelihood logarithm value for each sample. It has \f$nsamples \times 1\f$ size and CV_64FC1 type.
labelsOutputArrayThe 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.
probsOutputArrayThe 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.