Trait potpourri::Parametrizable
source · pub trait Parametrizable {
type SufficientStatistics: Send + Sync;
type Likelihood;
type DataIn<'a>: Sync;
type DataOut;
// Required methods
fn expect(
&self,
data: &Self::DataIn<'_>
) -> Result<(Self::Likelihood, AvgLLH), Error>;
fn compute(
&self,
data: &Self::DataIn<'_>,
responsibilities: &Self::Likelihood
) -> Result<Self::SufficientStatistics, Error>;
fn maximize(
&mut self,
sufficient_statistics: &Self::SufficientStatistics
) -> Result<(), Error>;
fn predict(&self, data: &Self::DataIn<'_>) -> Result<Self::DataOut, Error>;
fn update(
&mut self,
sufficient_statistics: &Self::SufficientStatistics,
weight: f64
) -> Result<(), Error>;
fn merge(
sufficient_statistics: &[&Self::SufficientStatistics],
weights: &[f64]
) -> Result<Self::SufficientStatistics, Error>;
// Provided method
fn expect_rand(
&self,
_data: &Self::DataIn<'_>,
_k: usize
) -> Result<Self::Likelihood, Error> { ... }
}
Required Associated Types§
type SufficientStatistics: Send + Sync
type Likelihood
type DataIn<'a>: Sync
type DataOut
Required Methods§
sourcefn expect(
&self,
data: &Self::DataIn<'_>
) -> Result<(Self::Likelihood, AvgLLH), Error>
fn expect( &self, data: &Self::DataIn<'_> ) -> Result<(Self::Likelihood, AvgLLH), Error>
The E-Step. Computes the likelihood for each component in the mixture
Note that for Mixables
, this is the log-likelihood
sourcefn compute(
&self,
data: &Self::DataIn<'_>,
responsibilities: &Self::Likelihood
) -> Result<Self::SufficientStatistics, Error>
fn compute( &self, data: &Self::DataIn<'_>, responsibilities: &Self::Likelihood ) -> Result<Self::SufficientStatistics, Error>
Computes the sufficient statistics from the responsibility matrix. The
Optionally, stores the
sufficient statistics (for incremental learning and store.restore functionality)
can be disabled for performance (defaults to True
)
sourcefn maximize(
&mut self,
sufficient_statistics: &Self::SufficientStatistics
) -> Result<(), Error>
fn maximize( &mut self, sufficient_statistics: &Self::SufficientStatistics ) -> Result<(), Error>
Maximize the model parameters from
fn predict(&self, data: &Self::DataIn<'_>) -> Result<Self::DataOut, Error>
sourcefn update(
&mut self,
sufficient_statistics: &Self::SufficientStatistics,
weight: f64
) -> Result<(), Error>
fn update( &mut self, sufficient_statistics: &Self::SufficientStatistics, weight: f64 ) -> Result<(), Error>
Update the stored sufficient statistics (for incremental learning) Weights is a tuple (a float should suffice, if summing to one)
sourcefn merge(
sufficient_statistics: &[&Self::SufficientStatistics],
weights: &[f64]
) -> Result<Self::SufficientStatistics, Error>
fn merge( sufficient_statistics: &[&Self::SufficientStatistics], weights: &[f64] ) -> Result<Self::SufficientStatistics, Error>
merge multiple sufficient statistics into one.
Provided Methods§
sourcefn expect_rand(
&self,
_data: &Self::DataIn<'_>,
_k: usize
) -> Result<Self::Likelihood, Error>
fn expect_rand( &self, _data: &Self::DataIn<'_>, _k: usize ) -> Result<Self::Likelihood, Error>
Generate a random expectation. Used as an initalization. It is recommended
to draw the expectations from a univorm Dirichlet distribution.
Note: This works better than an initialization method, because the layers
such as the Probabilistic
trait don’t need to implement backend-specific
random samplers.