Struct ppca::PPCAMix

source ·
pub struct PPCAMix(_);
Expand description

A mixture of PPCA models. Each PPCA model is associated with a prior probability expressed in log-scale. This models allows for modelling of data clustering and non-linear learning of data. However, it will use significantly more memory and is not guaranteed to converge to a global maximum.

Notes

  • The list of log-weights does not need to be normalized. Normalization is carried out internally.
  • Each PPCA model in the mixture might have its own state size. However, all PPCA models must have the same output space. Additionally, the set of PPCA models must be non-empty.

Implementations§

source§

impl PPCAMix

source

pub fn new(models: Vec<PPCAModel>, log_weights: DVector<f64>) -> PPCAMix

source

pub fn init(n_models: usize, state_size: usize, dataset: &Dataset) -> PPCAMix

Creates a new random untrained model from a given number of PPCA modes, a latent state size, a dataset and a smoothing factor. The smoothing factor helps with overfit of rarely occuring dimensions. If you don’t care about that, set it to 0.0.

source

pub fn output_size(&self) -> usize

The number of features for this model.

source

pub fn state_sizes(&self) -> Vec<usize>

The number of hidden values for each PPCA model.

source

pub fn n_parameters(&self) -> usize

The total number of parameters involved in training (used for information criteria).

source

pub fn models(&self) -> &[PPCAModel]

The list of constituent PPCA models.

source

pub fn log_weights(&self) -> &DVector<f64>

The log-strength (or log-a priori probablilty) for each PPCA model.

source

pub fn weights(&self) -> DVector<f64>

The strength (or a priori probablilty) for each PPCA model.

source

pub fn sample(&self, dataset_size: usize, mask_probability: f64) -> Dataset

Sample a full dataset from the PPCA model and masks each entry according to a Bernoulli (coin-toss) distribution of proability mask_prob of erasing the generated value.

source

pub fn llk_one(&self, sample: &MaskedSample) -> f64

Computes the log-likelihood for a single sample.

source

pub fn llks(&self, dataset: &Dataset) -> DVector<f64>

Computes the log-likelihood for each sample in a dataset.

source

pub fn llk(&self, dataset: &Dataset) -> f64

Computes the total log-likelihood for a given dataset.

source

pub fn infer_cluster(&self, dataset: &Dataset) -> DMatrix<f64>

Returns the posterior distribution (i.e., with Baye’s rule applied) for each sample in the given dataset. Each row of the matrix corresponds to a categorical distribution on the probability of a sample belonging to a particular PPCA model.

source

pub fn uninferred(&self) -> InferredMaskedMix

Creates a zeroed InferredMasked struct that is compatible with this model. This returns the prior associated with this model.

source

pub fn infer_one(&self, sample: &MaskedSample) -> InferredMaskedMix

Infers the probability distribution of a single sample.

source

pub fn infer(&self, dataset: &Dataset) -> Vec<InferredMaskedMix>

Infers the probability distribution of a given dataset.

source

pub fn smooth_one(&self, sample: &MaskedSample) -> MaskedSample

Filters a single samples, removing noise from it and inferring the missing dimensions.

source

pub fn smooth(&self, dataset: &Dataset) -> Dataset

Filters a dataset of samples, removing noise from the extant samples and inferring the missing samples.

source

pub fn extrapolate_one(&self, sample: &MaskedSample) -> MaskedSample

Extrapolates the missing values from a sample with the most probable values.

source

pub fn extrapolate(&self, dataset: &Dataset) -> Dataset

Extrapolates the missing values from a dataset with the most probable values.

source

pub fn iterate(&self, dataset: &Dataset) -> PPCAMix

Makes one iteration of the EM algorithm for the PPCA mixture model over an observed dataset, returning a improved model. The log-likelihood will always increase for the returned model.

source

pub fn iterate_with_prior(&self, dataset: &Dataset, prior: &Prior) -> PPCAMix

Makes one iteration of the EM algorithm for the PPCA mixture over an observe dataset, using a supplied PPCA prior (same for all constituent PPCA models) and returning the improved model. This method will not necessarily increase the log-likelihood of the returned model, but it will return an improved maximum a posteriori (MAP) estimate of the PPCA model according to the supplied prior.

source

pub fn to_canonical(&self) -> PPCAMix

Maps PPCAModel::to_canonical for each constituent model.

Trait Implementations§

source§

impl Clone for PPCAMix

source§

fn clone(&self) -> PPCAMix

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for PPCAMix

source§

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

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

impl<'de> Deserialize<'de> for PPCAMix

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Serialize for PPCAMix

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,