GaussianMixtureModel

Struct GaussianMixtureModel 

Source
pub struct GaussianMixtureModel {
    pub cov_option: CovOption,
    /* private fields */
}
Expand description

A Gaussian Mixture Model

Fields§

§cov_option: CovOption

The covariance options for the GMM.

Implementations§

Source§

impl GaussianMixtureModel

Source

pub fn new(k: usize) -> GaussianMixtureModel

Constructs a new Gaussian Mixture Model

Defaults to 100 maximum iterations and full covariance structure.

§Examples
use rusty_machine::learning::gmm::GaussianMixtureModel;

let gmm = GaussianMixtureModel::new(3);
Source

pub fn with_weights( k: usize, mixture_weights: Vector<f64>, ) -> LearningResult<GaussianMixtureModel>

Constructs a new GMM with the specified prior mixture weights.

The mixture weights must have the same length as the number of components. Each element of the mixture weights must be non-negative.

§Examples
use rusty_machine::learning::gmm::GaussianMixtureModel;
use rusty_machine::linalg::Vector;

let mix_weights = Vector::new(vec![0.25, 0.25, 0.5]);

let gmm = GaussianMixtureModel::with_weights(3, mix_weights).unwrap();
§Failures

Fails if either of the following conditions are met:

  • Mixture weights do not have length k.
  • Mixture weights have a negative entry.
Source

pub fn means(&self) -> Option<&Matrix<f64>>

The model means

Returns an Option<&Matrix> containing the model means. Each row represents the mean of one of the Gaussians.

Source

pub fn covariances(&self) -> Option<&Vec<Matrix<f64>>>

The model covariances

Returns an Option<&Vec<Matrix>> containing the model covariances. Each Matrix in the vector is the covariance of one of the Gaussians.

Source

pub fn mixture_weights(&self) -> &Vector<f64>

The model mixture weights

Returns a reference to the model mixture weights. These are the weighted contributions of each underlying Gaussian to the model distribution.

Source

pub fn set_max_iters(&mut self, iters: usize)

Sets the max number of iterations for the EM algorithm.

§Examples
use rusty_machine::learning::gmm::GaussianMixtureModel;

let mut gmm = GaussianMixtureModel::new(2);
gmm.set_max_iters(5);

Trait Implementations§

Source§

impl Debug for GaussianMixtureModel

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl UnSupModel<Matrix<f64>, Matrix<f64>> for GaussianMixtureModel

Source§

fn train(&mut self, inputs: &Matrix<f64>) -> LearningResult<()>

Train the model using inputs.

Source§

fn predict(&self, inputs: &Matrix<f64>) -> LearningResult<Matrix<f64>>

Predict output from inputs.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.