From b4a02fae0bbfe3c0d8b8d427e58bb61df066c887 Mon Sep 17 00:00:00 2001 From: Maria Dimashova Date: Wed, 18 Apr 2012 12:22:46 +0000 Subject: [PATCH] added doc on cv::EM; moved doc on CvEM to legacy/doc --- modules/legacy/doc/expectation_maximization.rst | 204 +++++++++++++++++++++ modules/legacy/doc/legacy.rst | 1 + modules/ml/doc/expectation_maximization.rst | 233 +++++++----------------- 3 files changed, 270 insertions(+), 168 deletions(-) create mode 100644 modules/legacy/doc/expectation_maximization.rst diff --git a/modules/legacy/doc/expectation_maximization.rst b/modules/legacy/doc/expectation_maximization.rst new file mode 100644 index 0000000..eb42fc1 --- /dev/null +++ b/modules/legacy/doc/expectation_maximization.rst @@ -0,0 +1,204 @@ +Expectation Maximization +======================== + +This section describes obsolete ``C`` interface of EM algorithm. Details of the algorithm and its ``C++`` interface can be found in the other section :ref:`ML_Expectation Maximization`. + +.. highlight:: cpp + + +CvEMParams +---------- +.. ocv:class:: CvEMParams + +Parameters of the EM algorithm. All parameters are public. You can initialize them by a constructor and then override some of them directly if you want. + +CvEMParams::CvEMParams +---------------------- +The constructors + +.. ocv:function:: CvEMParams::CvEMParams() + +.. ocv:function:: CvEMParams::CvEMParams( int nclusters, int cov_mat_type=CvEM::COV_MAT_DIAGONAL, int start_step=CvEM::START_AUTO_STEP, CvTermCriteria term_crit=cvTermCriteria(CV_TERMCRIT_ITER+CV_TERMCRIT_EPS, 100, FLT_EPSILON), const CvMat* probs=0, const CvMat* weights=0, const CvMat* means=0, const CvMat** covs=0 ) + + :param nclusters: The number of mixture components in the Gaussian mixture model. 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. + + :param cov_mat_type: Constraint on covariance matrices which defines type of matrices. Possible values are: + + * **CvEM::COV_MAT_SPHERICAL** A scaled identity matrix :math:`\mu_k * I`. There is the only parameter :math:`\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 ``cov_mat_type=CvEM::COV_MAT_DIAGONAL``. + + * **CvEM::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. + + * **CvEM::COV_MAT_GENERIC** A symmetric positively defined matrix. The number of free parameters in each matrix is about :math:`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. + + :param start_step: The start step of the EM algorithm: + + * **CvEM::START_E_STEP** Start with Expectation step. You need to provide means :math:`a_k` of mixture components to use this option. Optionally you can pass weights :math:`\pi_k` and covariance matrices :math:`S_k` of mixture components. + * **CvEM::START_M_STEP** Start with Maximization step. You need to provide initial probabilities :math:`p_{i,k}` to use this option. + * **CvEM::START_AUTO_STEP** Start with Expectation step. You need not provide any parameters because they will be estimated by the kmeans algorithm. + + :param term_crit: The termination criteria of the EM algorithm. The EM algorithm can be terminated by the number of iterations ``term_crit.max_iter`` (number of M-steps) or when relative change of likelihood logarithm is less than ``term_crit.epsilon``. + + :param probs: Initial probabilities :math:`p_{i,k}` of sample :math:`i` to belong to mixture component :math:`k`. It is a floating-point matrix of :math:`nsamples \times nclusters` size. It is used and must be not NULL only when ``start_step=CvEM::START_M_STEP``. + + :param weights: Initial weights :math:`\pi_k` of mixture components. It is a floating-point vector with :math:`nclusters` elements. It is used (if not NULL) only when ``start_step=CvEM::START_E_STEP``. + + :param means: Initial means :math:`a_k` of mixture components. It is a floating-point matrix of :math:`nclusters \times dims` size. It is used used and must be not NULL only when ``start_step=CvEM::START_E_STEP``. + + :param covs: Initial covariance matrices :math:`S_k` of mixture components. Each of covariance matrices is a valid square floating-point matrix of :math:`dims \times dims` size. It is used (if not NULL) only when ``start_step=CvEM::START_E_STEP``. + +The default constructor represents a rough rule-of-the-thumb: + +:: + + CvEMParams() : nclusters(10), cov_mat_type(1/*CvEM::COV_MAT_DIAGONAL*/), + start_step(0/*CvEM::START_AUTO_STEP*/), probs(0), weights(0), means(0), covs(0) + { + term_crit=cvTermCriteria( CV_TERMCRIT_ITER+CV_TERMCRIT_EPS, 100, FLT_EPSILON ); + } + + +With another constructor it is possible to override a variety of parameters from a single number of mixtures (the only essential problem-dependent parameter) to initial values for the mixture parameters. + + +CvEM +---- +.. ocv:class:: CvEM + + The class implements the EM algorithm as described in the beginning of the section :ref:`ML_Expectation Maximization`. + + +CvEM::train +----------- +Estimates the Gaussian mixture parameters from a sample set. + +.. ocv:function:: void CvEM::train( const Mat& samples, const Mat& sample_idx=Mat(), CvEMParams params=CvEMParams(), Mat* labels=0 ) + +.. ocv:function:: bool CvEM::train( const CvMat* samples, const CvMat* sampleIdx=0, CvEMParams params=CvEMParams(), CvMat* labels=0 ) + +.. ocv:pyfunction:: cv2.EM.train(samples[, sampleIdx[, params]]) -> retval, labels + + :param samples: Samples from which the Gaussian mixture model will be estimated. + + :param sample_idx: Mask of samples to use. All samples are used by default. + + :param params: Parameters of the EM algorithm. + + :param labels: The optional output "class label" for each sample: :math:`\texttt{labels}_i=\texttt{arg max}_k(p_{i,k}), i=1..N` (indices of the most probable mixture component for each sample). + +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: +:math:`p_{i,k}` in ``probs``, +:math:`a_k` in ``means`` , +:math:`S_k` in ``covs[k]``, +:math:`\pi_k` in ``weights`` , and optionally computes the output "class label" for each sample: +:math:`\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 +:ocv:class:`CvNormalBayesClassifier`. + +For an example of clustering random samples of the multi-Gaussian distribution using EM, see ``em.cpp`` sample in the OpenCV distribution. + + +CvEM::predict +------------- +Returns a mixture component index of a sample. + +.. ocv:function:: float CvEM::predict( const Mat& sample, Mat* probs=0 ) const + +.. ocv:function:: float CvEM::predict( const CvMat* sample, CvMat* probs ) const + +.. ocv:pyfunction:: cv2.EM.predict(sample) -> retval, probs + + :param sample: A sample for classification. + + :param probs: If it is not null then the method will write posterior probabilities of each component given the sample data to this parameter. + + +CvEM::getNClusters +------------------ +Returns the number of mixture components :math:`M` in the Gaussian mixture model. + +.. ocv:function:: int CvEM::getNClusters() const + +.. ocv:function:: int CvEM::get_nclusters() const + +.. ocv:pyfunction:: cv2.EM.getNClusters() -> retval + + +CvEM::getMeans +------------------ +Returns mixture means :math:`a_k`. + +.. ocv:function:: Mat CvEM::getMeans() const + +.. ocv:function:: const CvMat* CvEM::get_means() const + +.. ocv:pyfunction:: cv2.EM.getMeans() -> means + + +CvEM::getCovs +------------- +Returns mixture covariance matrices :math:`S_k`. + +.. ocv:function:: void CvEM::getCovs(std::vector& covs) const + +.. ocv:function:: const CvMat** CvEM::get_covs() const + +.. ocv:pyfunction:: cv2.EM.getCovs([covs]) -> covs + + +CvEM::getWeights +---------------- +Returns mixture weights :math:`\pi_k`. + +.. ocv:function:: Mat CvEM::getWeights() const + +.. ocv:function:: const CvMat* CvEM::get_weights() const + +.. ocv:pyfunction:: cv2.EM.getWeights() -> weights + + +CvEM::getProbs +-------------- +Returns vectors of probabilities for each training sample. + +.. ocv:function:: Mat CvEM::getProbs() const + +.. ocv:function:: const CvMat* CvEM::get_probs() const + +.. ocv:pyfunction:: cv2.EM.getProbs() -> probs + +For each training sample :math:`i` (that have been passed to the constructor or to :ocv:func:`CvEM::train`) returns probabilities :math:`p_{i,k}` to belong to a mixture component :math:`k`. + + +CvEM::getLikelihood +------------------- +Returns logarithm of likelihood. + +.. ocv:function:: double CvEM::getLikelihood() const + +.. ocv:function:: double CvEM::get_log_likelihood() const + +.. ocv:pyfunction:: cv2.EM.getLikelihood() -> likelihood + + +CvEM::write +----------- +Writes the trained Gaussian mixture model to the file storage. + +.. ocv:function:: void CvEM::write( CvFileStorage* fs, const char* name ) const + + :param fs: A file storage where the model will be written. + :param name: A name of the file node where the model data will be written. + + +CvEM::read +----------------- +Reads the trained Gaussian mixture model from the file storage. + +.. ocv:function:: void CvEM::read( CvFileStorage* fs, CvFileNode* node ) + + :param fs: A file storage with the trained model. + + :param node: The parent map. If it is NULL, the function searches a node with parameters in all the top-level nodes (streams), starting with the first one. + diff --git a/modules/legacy/doc/legacy.rst b/modules/legacy/doc/legacy.rst index 12cfdb8..8e6a826 100644 --- a/modules/legacy/doc/legacy.rst +++ b/modules/legacy/doc/legacy.rst @@ -8,3 +8,4 @@ legacy. Deprecated stuff :maxdepth: 2 motion_analysis + expectation_maximization diff --git a/modules/ml/doc/expectation_maximization.rst b/modules/ml/doc/expectation_maximization.rst index 7de8373..5d63510 100644 --- a/modules/ml/doc/expectation_maximization.rst +++ b/modules/ml/doc/expectation_maximization.rst @@ -1,3 +1,7 @@ + +.. _ML_Expectation Maximization: + + Expectation Maximization ======================== @@ -85,87 +89,67 @@ already a good enough approximation). * Bilmes98 J. A. Bilmes. *A Gentle Tutorial of the EM Algorithm and its Application to Parameter Estimation for Gaussian Mixture and Hidden Markov Models*. Technical Report TR-97-021, International Computer Science Institute and Computer Science Division, University of California at Berkeley, April 1998. +EM +-- +.. ocv:class:: EM -CvEMParams ----------- -.. ocv:class:: CvEMParams - -Parameters of the EM algorithm. All parameters are public. You can initialize them by a constructor and then override some of them directly if you want. - +The class implements the EM algorithm as described in the beginning of this section. It is inherited from :ocv:class:`Algorithm`. -CvEMParams::CvEMParams ----------------------- -The constructors +EM::EM +------ +The constructor of the class -.. ocv:function:: CvEMParams::CvEMParams() +.. ocv:function:: EM::EM(int nclusters=EM::DEFAULT_NCLUSTERS, int covMatType=EM::COV_MAT_DIAGONAL, const TermCriteria& termCrit=TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, EM::DEFAULT_MAX_ITERS, FLT_EPSILON) ) -.. ocv:function:: CvEMParams::CvEMParams( int nclusters, int cov_mat_type=CvEM::COV_MAT_DIAGONAL, int start_step=CvEM::START_AUTO_STEP, CvTermCriteria term_crit=cvTermCriteria(CV_TERMCRIT_ITER+CV_TERMCRIT_EPS, 100, FLT_EPSILON), const CvMat* probs=0, const CvMat* weights=0, const CvMat* means=0, const CvMat** covs=0 ) - :param nclusters: The number of mixture components in the gaussian mixture model. 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. + :param 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. - :param cov_mat_type: Constraint on covariance matrices which defines type of matrices. Possible values are: - - * **CvEM::COV_MAT_SPHERICAL** A scaled identity matrix :math:`\mu_k * I`. There is the only parameter :math:`\mu_k` to be estimated for earch 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 ``cov_mat_type=CvEM::COV_MAT_DIAGONAL``. - - * **CvEM::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. - - * **CvEM::COV_MAT_GENERIC** A symmetric positively defined matrix. The number of free parameters in each matrix is about :math:`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. - - :param start_step: The start step of the EM algorithm: + :param covMatType: Constraint on covariance matrices which defines type of matrices. Possible values are: - * **CvEM::START_E_STEP** Start with Expectation step. You need to provide means :math:`a_k` of mixture components to use this option. Optionally you can pass weights :math:`\pi_k` and covariance matrices :math:`S_k` of mixture components. - * **CvEM::START_M_STEP** Start with Maximization step. You need to provide initial probabilities :math:`p_{i,k}` to use this option. - * **CvEM::START_AUTO_STEP** Start with Expectation step. You need not provide any parameters because they will be estimated by the k-means algorithm. + * **EM::COV_MAT_SPHERICAL** A scaled identity matrix :math:`\mu_k * I`. There is the only parameter :math:`\mu_k` to be estimated for earch 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``. - :param term_crit: The termination criteria of the EM algorithm. The EM algorithm can be terminated by the number of iterations ``term_crit.max_iter`` (number of M-steps) or when relative change of likelihood logarithm is less than ``term_crit.epsilon``. + * **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. - :param probs: Initial probabilities :math:`p_{i,k}` of sample :math:`i` to belong to mixture component :math:`k`. It is a floating-point matrix of :math:`nsamples \times nclusters` size. It is used and must be not NULL only when ``start_step=CvEM::START_M_STEP``. - - :param weights: Initial weights :math:`\pi_k` of mixture components. It is a floating-point vector with :math:`nclusters` elements. It is used (if not NULL) only when ``start_step=CvEM::START_E_STEP``. - - :param means: Initial means :math:`a_k` of mixture components. It is a floating-point matrix of :math:`nclusters \times dims` size. It is used used and must be not NULL only when ``start_step=CvEM::START_E_STEP``. - - :param covs: Initial covariance matrices :math:`S_k` of mixture components. Each of covariance matrices is a valid square floating-point matrix of :math:`dims \times dims` size. It is used (if not NULL) only when ``start_step=CvEM::START_E_STEP``. - -The default constructor represents a rough rule-of-the-thumb: - -:: - - CvEMParams() : nclusters(10), cov_mat_type(1/*CvEM::COV_MAT_DIAGONAL*/), - start_step(0/*CvEM::START_AUTO_STEP*/), probs(0), weights(0), means(0), covs(0) - { - term_crit=cvTermCriteria( CV_TERMCRIT_ITER+CV_TERMCRIT_EPS, 100, FLT_EPSILON ); - } - - -With another constructor it is possible to override a variety of parameters from a single number of mixtures (the only essential problem-dependent parameter) to initial values for the mixture parameters. + * **EM::COV_MAT_GENERIC** A symmetric positively defined matrix. The number of free parameters in each matrix is about :math:`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. + + :param 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``. +EM::train +--------- +Estimates the Gaussian mixture parameters from a samples set. -CvEM ----- -.. ocv:class:: CvEM +.. ocv:function:: bool EM::train(InputArray samples, OutputArray logLikelihoods=noArray(), OutputArray labels=noArray(), OutputArray probs=noArray()) - The class implements the EM algorithm as described in the beginning of this section. +.. ocv:function:: bool EM::trainE(InputArray samples, InputArray means0, InputArray covs0=noArray(), InputArray weights0=noArray(), OutputArray logLikelihoods=noArray(), OutputArray labels=noArray(), OutputArray probs=noArray()) + +.. ocv:function:: bool EM::trainM(InputArray samples, InputArray probs0, OutputArray logLikelihoods=noArray(), OutputArray labels=noArray(), OutputArray probs=noArray()) + :param 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. + + :param means0: Initial means :math:`a_k` of mixture components. It is a one-channel matrix of :math:`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. -CvEM::train ------------ -Estimates the Gaussian mixture parameters from a sample set. + :param covs0: The vector of initial covariance matrices :math:`S_k` of mixture components. Each of covariance matrices is a one-channel matrix of :math:`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. + + :param weights0: Initial weights :math:`\pi_k` of mixture components. It should be a one-channel floating-point matrix with :math:`1 \times nclusters` or :math:`nclusters \times 1` size. + + :param probs0: Initial probabilities :math:`p_{i,k}` of sample :math:`i` to belong to mixture component :math:`k`. It is a one-channel floating-point matrix of :math:`nsamples \times nclusters` size. -.. ocv:function:: void CvEM::train( const Mat& samples, const Mat& sample_idx=Mat(), CvEMParams params=CvEMParams(), Mat* labels=0 ) + :param logLikelihoods: The optional output matrix that contains a likelihood logarithm value for each sample. It has :math:`nsamples \times 1` size and ``CV_64FC1`` type. -.. ocv:function:: bool CvEM::train( const CvMat* samples, const CvMat* sampleIdx=0, CvEMParams params=CvEMParams(), CvMat* labels=0 ) + :param labels: The optional output "class label" for each sample: :math:`\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 :math:`nsamples \times 1` size and ``CV_32SC1`` type. + + :param probs: The optional output matrix that contains posterior probabilities of each Gaussian mixture component given the each sample. It has :math:`nsamples \times nclusters` size and ``CV_64FC1`` type. -.. ocv:pyfunction:: cv2.EM.train(samples[, sampleIdx[, params]]) -> retval, labels +Three versions of training method differ in the initialization of Gaussian mixture model parameters and start step: - :param samples: Samples from which the Gaussian mixture model will be estimated. +* **train** - Starts with Expectation step. Initial values of the model parameters will be estimated by the k-means algorithm. - :param sample_idx: Mask of samples to use. All samples are used by default. +* **trainE** - Starts with Expectation step. You need to provide initial means :math:`a_k` of mixture components. Optionally you can pass initial weights :math:`\pi_k` and covariance matrices :math:`S_k` of mixture components. - :param params: Parameters of the EM algorithm. +* **trainM** - Starts with Maximization step. You need to provide initial probabilities :math:`p_{i,k}` to use this option. - :param labels: The optional output "class label" for each sample: :math:`\texttt{labels}_i=\texttt{arg max}_k(p_{i,k}), i=1..N` (indices of the most probable mixture component for each sample). +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: @@ -178,121 +162,34 @@ Unlike many of the ML models, EM is an unsupervised learning algorithm and it do The trained model can be used further for prediction, just like any other classifier. The trained model is similar to the :ocv:class:`CvNormalBayesClassifier`. -For an example of clustering random samples of the multi-Gaussian distribution using EM, see ``em.cpp`` sample in the OpenCV distribution. - - -CvEM::predict -------------- -Returns a mixture component index of a sample. - -.. ocv:function:: float CvEM::predict( const Mat& sample, Mat* probs=0 ) const - -.. ocv:function:: float CvEM::predict( const CvMat* sample, CvMat* probs ) const - -.. ocv:pyfunction:: cv2.EM.predict(sample) -> retval, probs - - :param sample: A sample for classification. - - :param probs: If it is not null then the method will write posterior probabilities of each component given the sample data to this parameter. - - -CvEM::getNClusters ------------------- -Returns the number of mixture components :math:`M` in the gaussian mixture model. - -.. ocv:function:: int CvEM::getNClusters() const - -.. ocv:function:: int CvEM::get_nclusters() const - -.. ocv:pyfunction:: cv2.EM.getNClusters() -> retval - - -CvEM::getMeans ------------------- -Returns mixture means :math:`a_k`. - -.. ocv:function:: Mat CvEM::getMeans() const - -.. ocv:function:: const CvMat* CvEM::get_means() const - -.. ocv:pyfunction:: cv2.EM.getMeans() -> means - - -CvEM::getCovs -------------- -Returns mixture covariance matrices :math:`S_k`. - -.. ocv:function:: void CvEM::getCovs(std::vector& covs) const - -.. ocv:function:: const CvMat** CvEM::get_covs() const - -.. ocv:pyfunction:: cv2.EM.getCovs([covs]) -> covs - - -CvEM::getWeights ----------------- -Returns mixture weights :math:`\pi_k`. - -.. ocv:function:: Mat CvEM::getWeights() const - -.. ocv:function:: const CvMat* CvEM::get_weights() const - -.. ocv:pyfunction:: cv2.EM.getWeights() -> weights - - -CvEM::getProbs --------------- -Returns vectors of probabilities for each training sample. +EM::predict +----------- +Returns a likelihood logarithm value and an index of the most probable mixture component for the given sample. -.. ocv:function:: Mat CvEM::getProbs() const +.. ocv:function:: Vec2d predict(InputArray sample, OutputArray probs=noArray()) const + + :param sample: A sample for classification. It should be a one-channel matrix of :math:`1 \times dims` or :math:`dims \times 1` size. -.. ocv:function:: const CvMat* CvEM::get_probs() const + :param probs: Optional output matrix that contains posterior probabilities of each component given the sample. It has :math:`1 \times nclusters` size and ``CV_64FC1`` type. -.. ocv:pyfunction:: cv2.EM.getProbs() -> probs +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. -For each training sample :math:`i` (that have been passed to the constructor or to :ocv:func:`CvEM::train`) returns probabilities :math:`p_{i,k}` to belong to a mixture component :math:`k`. +CvEM::isTrained +--------------- +Returns ``true`` if the Gaussian mixture model was trained. +.. ocv:function:: bool EM::isTrained() const -CvEM::getLikelihood +EM::read, EM::write ------------------- -Returns logarithm of likelihood. - -.. ocv:function:: double CvEM::getLikelihood() const - -.. ocv:function:: double CvEM::get_log_likelihood() const - -.. ocv:pyfunction:: cv2.EM.getLikelihood() -> likelihood - - -CvEM::getLikelihoodDelta ------------------------- -Returns difference between logarithm of likelihood on the last iteration and logarithm of likelihood on the previous iteration. - -.. ocv:function:: double CvEM::getLikelihoodDelta() const - -.. ocv:function:: double CvEM::get_log_likelihood_delta() const - -.. ocv:pyfunction:: cv2.EM.getLikelihoodDelta() -> likelihood delta - -CvEM::write_params ------------------- -Writes used parameters of the EM algorithm to a file storage. - -.. ocv:function:: void CvEM::write_params( CvFileStorage* fs ) const - - :param fs: A file storage where parameters will be written. - - -CvEM::read_params ------------------ -Reads parameters of the EM algorithm. - -.. ocv:function:: void CvEM::read_params( CvFileStorage* fs, CvFileNode* node ) - - :param fs: A file storage with parameters of the EM algorithm. - - :param node: The parent map. If it is NULL, the function searches a node with parameters in all the top-level nodes (streams), starting with the first one. - -The function reads EM parameters from the specified file storage node. For example of clustering random samples of multi-Gaussian distribution using EM see em.cpp sample in OpenCV distribution. +See :ocv:function:`Algorithm::read` and :ocv:function:`Algorithm::write`. +EM::get +------- +See :ocv:function:`Algorithm::get`. The following parameters are available for getting: +* ``"nclusters"`` +* ``"covMatType"`` +* ``"weights"`` +* ``"means"`` +* ``"covs"`` -- 2.7.4