CvEMParams::CvEMParams
The constructors
-
C++: CvEMParams::CvEMParams()
-
C++: CvEMParams::CvEMParams(int nclusters, int cov_mat_type=EM::COV_MAT_DIAGONAL, int start_step=EM::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 )
-
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::train
Estimates the Gaussian mixture parameters from a sample set.
-
C++: bool CvEM::train(const Mat& samples, const Mat& sampleIdx=Mat(), CvEMParams params=CvEMParams(), Mat* labels=0 )
-
C++: bool CvEM::train(const CvMat* samples, const CvMat* sampleIdx=0, CvEMParams params=CvEMParams(), CvMat* labels=0 )
Parameters: |
- samples – Samples from which the Gaussian mixture model will be estimated.
- sampleIdx – Mask of samples to use. All samples are used by default.
- params – Parameters of the EM algorithm.
- labels – The optional output “class label” for each sample:
System Message: WARNING/2 (\texttt{labels}_i=\texttt{arg max}_k(p_{i,k}), i=1..N)
latex exited with error
[stdout]
This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2014-OpenBSD_Ports) (preloaded format=latex)
restricted \write18 enabled.
entering extended mode
(./math.tex
LaTeX2e <2014/05/01>
Babel <3.9k> and hyphenation patterns for 78 languages loaded.
(/usr/local/share/texmf-dist/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/local/share/texmf-dist/tex/latex/base/size12.clo))
(/usr/local/share/texmf-dist/tex/latex/base/inputenc.sty
! LaTeX Error: File `utf8x.def’ not found.
Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: def)
Enter file name:
! Emergency stop.
<read *>
l.165 \endinput
^^M
No pages of output.
Transcript written on math.log.
(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:
System Message: WARNING/2 (p_{i,k})
latex exited with error
[stdout]
This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2014-OpenBSD_Ports) (preloaded format=latex)
restricted \write18 enabled.
entering extended mode
(./math.tex
LaTeX2e <2014/05/01>
Babel <3.9k> and hyphenation patterns for 78 languages loaded.
(/usr/local/share/texmf-dist/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/local/share/texmf-dist/tex/latex/base/size12.clo))
(/usr/local/share/texmf-dist/tex/latex/base/inputenc.sty
! LaTeX Error: File `utf8x.def’ not found.
Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: def)
Enter file name:
! Emergency stop.
<read *>
l.165 \endinput
^^M
No pages of output.
Transcript written on math.log.
in
probs,
System Message: WARNING/2 (a_k)
latex exited with error
[stdout]
This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2014-OpenBSD_Ports) (preloaded format=latex)
restricted \write18 enabled.
entering extended mode
(./math.tex
LaTeX2e <2014/05/01>
Babel <3.9k> and hyphenation patterns for 78 languages loaded.
(/usr/local/share/texmf-dist/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/local/share/texmf-dist/tex/latex/base/size12.clo))
(/usr/local/share/texmf-dist/tex/latex/base/inputenc.sty
! LaTeX Error: File `utf8x.def’ not found.
Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: def)
Enter file name:
! Emergency stop.
<read *>
l.165 \endinput
^^M
No pages of output.
Transcript written on math.log.
in
means ,
System Message: WARNING/2 (S_k)
latex exited with error
[stdout]
This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2014-OpenBSD_Ports) (preloaded format=latex)
restricted \write18 enabled.
entering extended mode
(./math.tex
LaTeX2e <2014/05/01>
Babel <3.9k> and hyphenation patterns for 78 languages loaded.
(/usr/local/share/texmf-dist/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/local/share/texmf-dist/tex/latex/base/size12.clo))
(/usr/local/share/texmf-dist/tex/latex/base/inputenc.sty
! LaTeX Error: File `utf8x.def’ not found.
Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: def)
Enter file name:
! Emergency stop.
<read *>
l.165 \endinput
^^M
No pages of output.
Transcript written on math.log.
in
covs[k],
System Message: WARNING/2 (\pi_k)
latex exited with error
[stdout]
This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2014-OpenBSD_Ports) (preloaded format=latex)
restricted \write18 enabled.
entering extended mode
(./math.tex
LaTeX2e <2014/05/01>
Babel <3.9k> and hyphenation patterns for 78 languages loaded.
(/usr/local/share/texmf-dist/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/local/share/texmf-dist/tex/latex/base/size12.clo))
(/usr/local/share/texmf-dist/tex/latex/base/inputenc.sty
! LaTeX Error: File `utf8x.def’ not found.
Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: def)
Enter file name:
! Emergency stop.
<read *>
l.165 \endinput
^^M
No pages of output.
Transcript written on math.log.
in
weights , and optionally computes the output “class label” for each sample:
System Message: WARNING/2 (\texttt{labels}_i=\texttt{arg max}_k(p_{i,k}), i=1..N)
latex exited with error
[stdout]
This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2014-OpenBSD_Ports) (preloaded format=latex)
restricted \write18 enabled.
entering extended mode
(./math.tex
LaTeX2e <2014/05/01>
Babel <3.9k> and hyphenation patterns for 78 languages loaded.
(/usr/local/share/texmf-dist/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/local/share/texmf-dist/tex/latex/base/size12.clo))
(/usr/local/share/texmf-dist/tex/latex/base/inputenc.sty
! LaTeX Error: File `utf8x.def’ not found.
Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: def)
Enter file name:
! Emergency stop.
<read *>
l.165 \endinput
^^M
No pages of output.
Transcript written on math.log.
(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.
For an example of clustering random samples of the multi-Gaussian distribution using EM, see em.cpp sample in the OpenCV distribution.
CvEM::getNClusters
Returns the number of mixture components
System Message: WARNING/2 (M)
latex exited with error
[stdout]
This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2014-OpenBSD_Ports) (preloaded format=latex)
restricted \write18 enabled.
entering extended mode
(./math.tex
LaTeX2e <2014/05/01>
Babel <3.9k> and hyphenation patterns for 78 languages loaded.
(/usr/local/share/texmf-dist/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/local/share/texmf-dist/tex/latex/base/size12.clo))
(/usr/local/share/texmf-dist/tex/latex/base/inputenc.sty
! LaTeX Error: File `utf8x.def’ not found.
Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: def)
Enter file name:
! Emergency stop.
<read *>
l.165 \endinput
^^M
No pages of output.
Transcript written on math.log.
in the Gaussian mixture model.
-
C++: int CvEM::getNClusters() const
-
C++: int CvEM::get_nclusters() const
CvEM::getCovs
Returns mixture covariance matrices
System Message: WARNING/2 (S_k)
latex exited with error
[stdout]
This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2014-OpenBSD_Ports) (preloaded format=latex)
restricted \write18 enabled.
entering extended mode
(./math.tex
LaTeX2e <2014/05/01>
Babel <3.9k> and hyphenation patterns for 78 languages loaded.
(/usr/local/share/texmf-dist/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/local/share/texmf-dist/tex/latex/base/size12.clo))
(/usr/local/share/texmf-dist/tex/latex/base/inputenc.sty
! LaTeX Error: File `utf8x.def’ not found.
Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: def)
Enter file name:
! Emergency stop.
<read *>
l.165 \endinput
^^M
No pages of output.
Transcript written on math.log.
.
-
C++: void CvEM::getCovs(std::vector<cv::Mat>& covs) const
-
C++: const CvMat** CvEM::get_covs() const
CvEM::getProbs
Returns vectors of probabilities for each training sample.
-
C++: Mat CvEM::getProbs() const
-
C++: const CvMat* CvEM::get_probs() const
For each training sample
System Message: WARNING/2 (i)
latex exited with error
[stdout]
This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2014-OpenBSD_Ports) (preloaded format=latex)
restricted \write18 enabled.
entering extended mode
(./math.tex
LaTeX2e <2014/05/01>
Babel <3.9k> and hyphenation patterns for 78 languages loaded.
(/usr/local/share/texmf-dist/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/local/share/texmf-dist/tex/latex/base/size12.clo))
(/usr/local/share/texmf-dist/tex/latex/base/inputenc.sty
! LaTeX Error: File `utf8x.def’ not found.
Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: def)
Enter file name:
! Emergency stop.
<read *>
l.165 \endinput
^^M
No pages of output.
Transcript written on math.log.
(that have been passed to the constructor or to
CvEM::train()) returns probabilities
System Message: WARNING/2 (p_{i,k})
latex exited with error
[stdout]
This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2014-OpenBSD_Ports) (preloaded format=latex)
restricted \write18 enabled.
entering extended mode
(./math.tex
LaTeX2e <2014/05/01>
Babel <3.9k> and hyphenation patterns for 78 languages loaded.
(/usr/local/share/texmf-dist/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/local/share/texmf-dist/tex/latex/base/size12.clo))
(/usr/local/share/texmf-dist/tex/latex/base/inputenc.sty
! LaTeX Error: File `utf8x.def’ not found.
Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: def)
Enter file name:
! Emergency stop.
<read *>
l.165 \endinput
^^M
No pages of output.
Transcript written on math.log.
to belong to a mixture component
System Message: WARNING/2 (k)
latex exited with error
[stdout]
This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2014-OpenBSD_Ports) (preloaded format=latex)
restricted \write18 enabled.
entering extended mode
(./math.tex
LaTeX2e <2014/05/01>
Babel <3.9k> and hyphenation patterns for 78 languages loaded.
(/usr/local/share/texmf-dist/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/local/share/texmf-dist/tex/latex/base/size12.clo))
(/usr/local/share/texmf-dist/tex/latex/base/inputenc.sty
! LaTeX Error: File `utf8x.def’ not found.
Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: def)
Enter file name:
! Emergency stop.
<read *>
l.165 \endinput
^^M
No pages of output.
Transcript written on math.log.
.