PPCAModel

Struct PPCAModel 

Source
pub struct PPCAModel(/* private fields */);
Expand description

A PPCA model which can infer missing values.

Each sample for this model behaves according to the following statistical latent variable model.

x ~ N(0; I(nxn))
y = C * x + y0 + noise
noise ~ N(0; sigma ^ 2 * I(mxm))

Here, x is the latent state, y is the observed sample, that is an affine transformation of the hidden state contaminated by isotropic noise.

§Note

All arrays involved have to be of data type float64.

Implementations§

Source§

impl PPCAModel

Source

pub fn new( isotropic_noise: f64, transform: DMatrix<f64>, mean: DVector<f64>, ) -> PPCAModel

Source

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

Creates a new random untrained model from a given latent state size and a dataset.

Source

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

Then center of mass of the distribution in the output space.

Source

pub fn isotropic_noise(&self) -> f64

The standard deviation of the noise in the output space.

Source

pub fn transform(&self) -> &DMatrix<f64>

The linear transformation from hidden state space to output space.

Source

pub fn output_size(&self) -> usize

The number of features for this model.

Source

pub fn state_size(&self) -> usize

The number of hidden values for this model.

Source

pub fn uninferred(&self) -> InferredMasked

Creates a zeroed InferredMasked struct that is compatible with this model.

Source

pub fn n_parameters(&self) -> usize

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

Source

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

The relative strength of each hidden variable on the output. This is equivalent to the eigenvalues in the standard PCA.

Source

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

Compute the log-likelihood of a single sample.

Source

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

Compute the log-likelihood of a given dataset.

Source

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

Compute the log-likelihood for each sample in a given dataset.

Source

pub fn sample_one(&self, mask_prob: f64) -> MaskedSample

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

Source

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

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

Source

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

Infers the hidden components for one single sample. Use this method for fine-grain control on the properties you want to extract from the model.

Source

pub fn inferred_one( &self, state: DVector<f64>, covariance: DMatrix<f64>, ) -> InferredMasked

Builds a new InferredMasked from the raw values.

Source

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

Infers the hidden components for each sample in the dataset. Use this method for fine-grain control on the properties you want to extract from the model.

Source

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

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

Source

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

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

Source

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

Extrapolates the missing values with the most probable values for a single sample. This method does not alter the extant values.

Source

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

Extrapolates the missing values with the most probable values for a full dataset. This method does not alter the extant values.

Source

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

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

Source

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

Makes one iteration of the EM algorithm for the PPCA over an observed dataset, using a supplied PPCA prior 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) -> PPCAModel

Returns a canonical version of this model. This does not alter the log-probability function nor the quality of the training. All it does is to transform the hidden variables.

Trait Implementations§

Source§

impl Clone for PPCAModel

Source§

fn clone(&self) -> PPCAModel

Returns a duplicate 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 PPCAModel

Source§

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

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

impl<'de> Deserialize<'de> for PPCAModel

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 PPCAModel

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 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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

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

fn is_in_subset(&self) -> bool

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

fn to_subset_unchecked(&self) -> SS

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

fn from_subset(element: &SS) -> SP

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

impl<T> ToOwned for T
where T: Clone,

Source§

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 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.
Source§

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

Source§

fn vzip(self) -> V

Source§

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