pub trait EMTrait: EMTraitConst + StatModelTrait {
// Required method
fn as_raw_mut_EM(&mut self) -> *mut c_void;
// Provided methods
fn set_clusters_number(&mut self, val: i32) -> Result<()> { ... }
fn set_covariance_matrix_type(&mut self, val: i32) -> Result<()> { ... }
fn set_term_criteria(&mut self, val: TermCriteria) -> Result<()> { ... }
fn train_em(
&mut self,
samples: &impl ToInputArray,
log_likelihoods: &mut impl ToOutputArray,
labels: &mut impl ToOutputArray,
probs: &mut impl ToOutputArray,
) -> Result<bool> { ... }
fn train_em_def(&mut self, samples: &impl ToInputArray) -> Result<bool> { ... }
fn train_e(
&mut self,
samples: &impl ToInputArray,
means0: &impl ToInputArray,
covs0: &impl ToInputArray,
weights0: &impl ToInputArray,
log_likelihoods: &mut impl ToOutputArray,
labels: &mut impl ToOutputArray,
probs: &mut impl ToOutputArray,
) -> Result<bool> { ... }
fn train_e_def(
&mut self,
samples: &impl ToInputArray,
means0: &impl ToInputArray,
) -> Result<bool> { ... }
fn train_m(
&mut self,
samples: &impl ToInputArray,
probs0: &impl ToInputArray,
log_likelihoods: &mut impl ToOutputArray,
labels: &mut impl ToOutputArray,
probs: &mut impl ToOutputArray,
) -> Result<bool> { ... }
fn train_m_def(
&mut self,
samples: &impl ToInputArray,
probs0: &impl ToInputArray,
) -> Result<bool> { ... }
}
Expand description
Mutable methods for crate::ml::EM
Required Methods§
fn as_raw_mut_EM(&mut self) -> *mut c_void
Provided Methods§
Sourcefn set_clusters_number(&mut self, val: i32) -> Result<()>
fn set_clusters_number(&mut self, val: i32) -> Result<()>
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.
§See also
setClustersNumber getClustersNumber
Sourcefn set_covariance_matrix_type(&mut self, val: i32) -> Result<()>
fn set_covariance_matrix_type(&mut self, val: i32) -> Result<()>
Constraint on covariance matrices which defines type of matrices. See EM::Types.
§See also
setCovarianceMatrixType getCovarianceMatrixType
Sourcefn set_term_criteria(&mut self, val: TermCriteria) -> Result<()>
fn set_term_criteria(&mut self, val: TermCriteria) -> Result<()>
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.
§See also
setTermCriteria getTermCriteria
Sourcefn train_em(
&mut self,
samples: &impl ToInputArray,
log_likelihoods: &mut impl ToOutputArray,
labels: &mut impl ToOutputArray,
probs: &mut impl ToOutputArray,
) -> Result<bool>
fn train_em( &mut self, samples: &impl ToInputArray, log_likelihoods: &mut impl ToOutputArray, labels: &mut impl ToOutputArray, probs: &mut impl ToOutputArray, ) -> Result<bool>
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: in probs,
in means ,
in
covs[k],
in weights , and optionally computes the output “class label” for each
sample:
(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
- 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.
- logLikelihoods: The optional output matrix that contains a likelihood logarithm value for
each sample. It has
size and CV_64FC1 type.
- labels: The optional output “class label” for each sample:
(indices of the most probable mixture component for each sample). It has
size and CV_32SC1 type.
- probs: The optional output matrix that contains posterior probabilities of each Gaussian
mixture component given the each sample. It has
size and CV_64FC1 type.
§C++ default parameters
- log_likelihoods: noArray()
- labels: noArray()
- probs: noArray()
Sourcefn train_em_def(&mut self, samples: &impl ToInputArray) -> Result<bool>
fn train_em_def(&mut self, samples: &impl ToInputArray) -> Result<bool>
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: in probs,
in means ,
in
covs[k],
in weights , and optionally computes the output “class label” for each
sample:
(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
- 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.
- logLikelihoods: The optional output matrix that contains a likelihood logarithm value for
each sample. It has
size and CV_64FC1 type.
- labels: The optional output “class label” for each sample:
(indices of the most probable mixture component for each sample). It has
size and CV_32SC1 type.
- probs: The optional output matrix that contains posterior probabilities of each Gaussian
mixture component given the each sample. It has
size and CV_64FC1 type.
§Note
This alternative version of EMTrait::train_em function uses the following default values for its arguments:
- log_likelihoods: noArray()
- labels: noArray()
- probs: noArray()
Sourcefn train_e(
&mut self,
samples: &impl ToInputArray,
means0: &impl ToInputArray,
covs0: &impl ToInputArray,
weights0: &impl ToInputArray,
log_likelihoods: &mut impl ToOutputArray,
labels: &mut impl ToOutputArray,
probs: &mut impl ToOutputArray,
) -> Result<bool>
fn train_e( &mut self, samples: &impl ToInputArray, means0: &impl ToInputArray, covs0: &impl ToInputArray, weights0: &impl ToInputArray, log_likelihoods: &mut impl ToOutputArray, labels: &mut impl ToOutputArray, probs: &mut impl ToOutputArray, ) -> Result<bool>
Estimate the Gaussian mixture parameters from a samples set.
This variation starts with Expectation step. You need to provide initial means of
mixture components. Optionally you can pass initial weights
and covariance matrices
of mixture components.
§Parameters
- 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.
- means0: Initial means
of mixture components. It is a one-channel matrix of
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.
- covs0: The vector of initial covariance matrices
of mixture components. Each of covariance matrices is a one-channel matrix of
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.
- weights0: Initial weights
of mixture components. It should be a one-channel floating-point matrix with
or
size.
- logLikelihoods: The optional output matrix that contains a likelihood logarithm value for
each sample. It has
size and CV_64FC1 type.
- labels: The optional output “class label” for each sample:
(indices of the most probable mixture component for each sample). It has
size and CV_32SC1 type.
- probs: The optional output matrix that contains posterior probabilities of each Gaussian
mixture component given the each sample. It has
size and CV_64FC1 type.
§C++ default parameters
- covs0: noArray()
- weights0: noArray()
- log_likelihoods: noArray()
- labels: noArray()
- probs: noArray()
Sourcefn train_e_def(
&mut self,
samples: &impl ToInputArray,
means0: &impl ToInputArray,
) -> Result<bool>
fn train_e_def( &mut self, samples: &impl ToInputArray, means0: &impl ToInputArray, ) -> Result<bool>
Estimate the Gaussian mixture parameters from a samples set.
This variation starts with Expectation step. You need to provide initial means of
mixture components. Optionally you can pass initial weights
and covariance matrices
of mixture components.
§Parameters
- 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.
- means0: Initial means
of mixture components. It is a one-channel matrix of
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.
- covs0: The vector of initial covariance matrices
of mixture components. Each of covariance matrices is a one-channel matrix of
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.
- weights0: Initial weights
of mixture components. It should be a one-channel floating-point matrix with
or
size.
- logLikelihoods: The optional output matrix that contains a likelihood logarithm value for
each sample. It has
size and CV_64FC1 type.
- labels: The optional output “class label” for each sample:
(indices of the most probable mixture component for each sample). It has
size and CV_32SC1 type.
- probs: The optional output matrix that contains posterior probabilities of each Gaussian
mixture component given the each sample. It has
size and CV_64FC1 type.
§Note
This alternative version of EMTrait::train_e function uses the following default values for its arguments:
- covs0: noArray()
- weights0: noArray()
- log_likelihoods: noArray()
- labels: noArray()
- probs: noArray()
Sourcefn train_m(
&mut self,
samples: &impl ToInputArray,
probs0: &impl ToInputArray,
log_likelihoods: &mut impl ToOutputArray,
labels: &mut impl ToOutputArray,
probs: &mut impl ToOutputArray,
) -> Result<bool>
fn train_m( &mut self, samples: &impl ToInputArray, probs0: &impl ToInputArray, log_likelihoods: &mut impl ToOutputArray, labels: &mut impl ToOutputArray, probs: &mut impl ToOutputArray, ) -> Result<bool>
Estimate the Gaussian mixture parameters from a samples set.
This variation starts with Maximization step. You need to provide initial probabilities
to use this option.
§Parameters
- 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.
- probs0: the probabilities
- logLikelihoods: The optional output matrix that contains a likelihood logarithm value for
each sample. It has
size and CV_64FC1 type.
- labels: The optional output “class label” for each sample:
(indices of the most probable mixture component for each sample). It has
size and CV_32SC1 type.
- probs: The optional output matrix that contains posterior probabilities of each Gaussian
mixture component given the each sample. It has
size and CV_64FC1 type.
§C++ default parameters
- log_likelihoods: noArray()
- labels: noArray()
- probs: noArray()
Sourcefn train_m_def(
&mut self,
samples: &impl ToInputArray,
probs0: &impl ToInputArray,
) -> Result<bool>
fn train_m_def( &mut self, samples: &impl ToInputArray, probs0: &impl ToInputArray, ) -> Result<bool>
Estimate the Gaussian mixture parameters from a samples set.
This variation starts with Maximization step. You need to provide initial probabilities
to use this option.
§Parameters
- 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.
- probs0: the probabilities
- logLikelihoods: The optional output matrix that contains a likelihood logarithm value for
each sample. It has
size and CV_64FC1 type.
- labels: The optional output “class label” for each sample:
(indices of the most probable mixture component for each sample). It has
size and CV_32SC1 type.
- probs: The optional output matrix that contains posterior probabilities of each Gaussian
mixture component given the each sample. It has
size and CV_64FC1 type.
§Note
This alternative version of EMTrait::train_m function uses the following default values for its arguments:
- log_likelihoods: noArray()
- labels: noArray()
- probs: noArray()
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.