[][src]Trait opencv::ml::EM

pub trait EM: StatModel {
    fn as_raw_EM(&self) -> *mut c_void;

    fn get_clusters_number(&self) -> Result<i32> { ... }
fn set_clusters_number(&mut self, val: i32) -> Result<()> { ... }
fn get_covariance_matrix_type(&self) -> Result<i32> { ... }
fn set_covariance_matrix_type(&mut self, val: i32) -> Result<()> { ... }
fn get_term_criteria(&self) -> Result<TermCriteria> { ... }
fn set_term_criteria(&mut self, val: &TermCriteria) -> Result<()> { ... }
fn get_weights(&self) -> Result<Mat> { ... }
fn get_means(&self) -> Result<Mat> { ... }
fn get_covs(&self, covs: &mut VectorOfMat) -> Result<()> { ... }
fn predict(
        &self,
        samples: &dyn ToInputArray,
        results: &mut dyn ToOutputArray,
        flags: i32
    ) -> Result<f32> { ... }
fn predict2(
        &self,
        sample: &dyn ToInputArray,
        probs: &mut dyn ToOutputArray
    ) -> Result<Vec2d> { ... }
fn train_em(
        &mut self,
        samples: &dyn ToInputArray,
        log_likelihoods: &mut dyn ToOutputArray,
        labels: &mut dyn ToOutputArray,
        probs: &mut dyn ToOutputArray
    ) -> Result<bool> { ... }
fn train_e(
        &mut self,
        samples: &dyn ToInputArray,
        means0: &dyn ToInputArray,
        covs0: &dyn ToInputArray,
        weights0: &dyn ToInputArray,
        log_likelihoods: &mut dyn ToOutputArray,
        labels: &mut dyn ToOutputArray,
        probs: &mut dyn ToOutputArray
    ) -> Result<bool> { ... }
fn train_m(
        &mut self,
        samples: &dyn ToInputArray,
        probs0: &dyn ToInputArray,
        log_likelihoods: &mut dyn ToOutputArray,
        labels: &mut dyn ToOutputArray,
        probs: &mut dyn ToOutputArray
    ) -> Result<bool> { ... } }

The class implements the Expectation Maximization algorithm.

See also

@ref ml_intro_em

Required methods

fn as_raw_EM(&self) -> *mut c_void

Loading content...

Provided methods

fn get_clusters_number(&self) -> Result<i32>

@see setClustersNumber

fn set_clusters_number(&mut self, val: i32) -> Result<()>

@copybrief getClustersNumber @see getClustersNumber

fn get_covariance_matrix_type(&self) -> Result<i32>

@see setCovarianceMatrixType

fn set_covariance_matrix_type(&mut self, val: i32) -> Result<()>

@copybrief getCovarianceMatrixType @see getCovarianceMatrixType

fn get_term_criteria(&self) -> Result<TermCriteria>

@see setTermCriteria

fn set_term_criteria(&mut self, val: &TermCriteria) -> Result<()>

@copybrief getTermCriteria @see getTermCriteria

fn get_weights(&self) -> Result<Mat>

Returns weights of the mixtures

Returns vector with the number of elements equal to the number of mixtures.

fn get_means(&self) -> Result<Mat>

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.

fn get_covs(&self, covs: &mut VectorOfMat) -> Result<()>

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.

fn predict(
    &self,
    samples: &dyn ToInputArray,
    results: &mut dyn ToOutputArray,
    flags: i32
) -> Result<f32>

Returns posterior probabilities for the provided samples

Parameters

  • samples: The input samples, floating-point matrix
  • results: The optional output inline formula matrix of results. It contains posterior probabilities for each sample from the input
  • flags: This parameter will be ignored

C++ default parameters

  • results: noArray()
  • flags: 0

fn predict2(
    &self,
    sample: &dyn ToInputArray,
    probs: &mut dyn ToOutputArray
) -> Result<Vec2d>

Returns a likelihood logarithm value and an index of the most probable mixture component for the given sample.

Parameters

  • sample: A sample for classification. It should be a one-channel matrix of inline formula or inline formula size.
  • probs: Optional output matrix that contains posterior probabilities of each component given the sample. It has inline formula size and CV_64FC1 type.

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.

fn train_em(
    &mut self,
    samples: &dyn ToInputArray,
    log_likelihoods: &mut dyn ToOutputArray,
    labels: &mut dyn ToOutputArray,
    probs: &mut dyn 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: inline formula in probs, inline formula in means , inline formula in covs[k], inline formula in weights , and optionally computes the output "class label" for each sample: inline formula (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 inline formula size and CV_64FC1 type.
  • labels: The optional output "class label" for each sample: inline formula (indices of the most probable mixture component for each sample). It has inline formula 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 inline formula size and CV_64FC1 type.

C++ default parameters

  • log_likelihoods: noArray()
  • labels: noArray()
  • probs: noArray()

fn train_e(
    &mut self,
    samples: &dyn ToInputArray,
    means0: &dyn ToInputArray,
    covs0: &dyn ToInputArray,
    weights0: &dyn ToInputArray,
    log_likelihoods: &mut dyn ToOutputArray,
    labels: &mut dyn ToOutputArray,
    probs: &mut dyn ToOutputArray
) -> Result<bool>

Estimate the Gaussian mixture parameters from a samples set.

This variation starts with Expectation step. You need to provide initial means inline formula of mixture components. Optionally you can pass initial weights inline formula and covariance matrices inline formula 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 inline formula of mixture components. It is a one-channel matrix of inline formula 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 inline formula of mixture components. Each of covariance matrices is a one-channel matrix of inline formula 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 inline formula of mixture components. It should be a one-channel floating-point matrix with inline formula or inline formula size.
  • logLikelihoods: The optional output matrix that contains a likelihood logarithm value for each sample. It has inline formula size and CV_64FC1 type.
  • labels: The optional output "class label" for each sample: inline formula (indices of the most probable mixture component for each sample). It has inline formula 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 inline formula size and CV_64FC1 type.

C++ default parameters

  • covs0: noArray()
  • weights0: noArray()
  • log_likelihoods: noArray()
  • labels: noArray()
  • probs: noArray()

fn train_m(
    &mut self,
    samples: &dyn ToInputArray,
    probs0: &dyn ToInputArray,
    log_likelihoods: &mut dyn ToOutputArray,
    labels: &mut dyn ToOutputArray,
    probs: &mut dyn ToOutputArray
) -> Result<bool>

Estimate the Gaussian mixture parameters from a samples set.

This variation starts with Maximization step. You need to provide initial probabilities inline formula 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 inline formula size and CV_64FC1 type.
  • labels: The optional output "class label" for each sample: inline formula (indices of the most probable mixture component for each sample). It has inline formula 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 inline formula size and CV_64FC1 type.

C++ default parameters

  • log_likelihoods: noArray()
  • labels: noArray()
  • probs: noArray()
Loading content...

Methods

impl<'_> dyn EM + '_[src]

pub fn create() -> Result<PtrOfEM>[src]

Creates empty %EM model. The model should be trained then using StatModel::train(traindata, flags) method. Alternatively, you can use one of the EM::train* methods or load it from file using Algorithm::load<EM>(filename).

pub fn load(filepath: &str, node_name: &str) -> Result<PtrOfEM>[src]

Loads and creates a serialized EM from a file

Use EM::save to serialize and store an EM to disk. Load the EM from this file again, by calling this function with the path to the file. Optionally specify the node for the file containing the classifier

Parameters

  • filepath: path to serialized EM
  • nodeName: name of node containing the classifier

C++ default parameters

  • node_name: String()

Implementors

impl EM for PtrOfEM[src]

Loading content...