pub struct HiddenMarkovModel<State = Untrained> { /* private fields */ }Expand description
Hidden Markov Model for sequence modeling
A statistical model that assumes the system being modeled is a Markov process with unobserved (hidden) states. HMMs are particularly useful for temporal pattern recognition such as speech recognition, handwriting recognition, gesture recognition, part-of-speech tagging, and bioinformatics.
§Examples
use sklears_core::traits::{Predict, Fit};
use sklears_multioutput::HiddenMarkovModel;
// Use SciRS2-Core for arrays and random number generation (SciRS2 Policy)
use scirs2_core::ndarray::array;
let X = array![[[1.0, 2.0], [2.0, 3.0], [1.5, 2.5]]]; // One sequence
let y = array![[0, 1, 0]]; // State sequence
let hmm = HiddenMarkovModel::new().n_states(2).max_iterations(100);
let trained_hmm = hmm.fit(&X, &y).unwrap();
let predictions = trained_hmm.predict(&X).unwrap();Implementations§
Source§impl HiddenMarkovModel<Untrained>
impl HiddenMarkovModel<Untrained>
Sourcepub fn max_iterations(self, max_iterations: usize) -> Self
pub fn max_iterations(self, max_iterations: usize) -> Self
Set the maximum number of iterations for EM algorithm
Sourcepub fn random_state(self, random_state: u64) -> Self
pub fn random_state(self, random_state: u64) -> Self
Set the random state for reproducible results
Source§impl HiddenMarkovModel<Untrained>
impl HiddenMarkovModel<Untrained>
Sourcepub fn transition_matrix(&self) -> Option<&Array2<Float>>
pub fn transition_matrix(&self) -> Option<&Array2<Float>>
Get the transition matrix (only available after training)
Sourcepub fn emission_means(&self) -> Option<&Array2<Float>>
pub fn emission_means(&self) -> Option<&Array2<Float>>
Get the emission means (only available after training)
Sourcepub fn initial_probabilities(&self) -> Option<&Array1<Float>>
pub fn initial_probabilities(&self) -> Option<&Array1<Float>>
Get the initial state probabilities (only available after training)
Source§impl HiddenMarkovModel<HiddenMarkovModelTrained>
impl HiddenMarkovModel<HiddenMarkovModelTrained>
Sourcepub fn transition_matrix(&self) -> &Array2<Float>
pub fn transition_matrix(&self) -> &Array2<Float>
Get the transition matrix
Sourcepub fn emission_means(&self) -> &Array2<Float>
pub fn emission_means(&self) -> &Array2<Float>
Get the emission means
Sourcepub fn initial_probabilities(&self) -> &Array1<Float>
pub fn initial_probabilities(&self) -> &Array1<Float>
Get the initial state probabilities
Trait Implementations§
Source§impl<State: Clone> Clone for HiddenMarkovModel<State>
impl<State: Clone> Clone for HiddenMarkovModel<State>
Source§fn clone(&self) -> HiddenMarkovModel<State>
fn clone(&self) -> HiddenMarkovModel<State>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<State: Debug> Debug for HiddenMarkovModel<State>
impl<State: Debug> Debug for HiddenMarkovModel<State>
Source§impl Default for HiddenMarkovModel<Untrained>
impl Default for HiddenMarkovModel<Untrained>
Source§impl Estimator for HiddenMarkovModel<Untrained>
impl Estimator for HiddenMarkovModel<Untrained>
Source§type Error = SklearsError
type Error = SklearsError
Error type for the estimator
Source§fn validate_config(&self) -> Result<(), SklearsError>
fn validate_config(&self) -> Result<(), SklearsError>
Validate estimator configuration with detailed error context
Source§fn check_compatibility(
&self,
n_samples: usize,
n_features: usize,
) -> Result<(), SklearsError>
fn check_compatibility( &self, n_samples: usize, n_features: usize, ) -> Result<(), SklearsError>
Check if estimator is compatible with given data dimensions
Source§fn metadata(&self) -> EstimatorMetadata
fn metadata(&self) -> EstimatorMetadata
Get estimator metadata
Source§impl Fit<ArrayBase<OwnedRepr<f64>, Dim<[usize; 3]>>, ArrayBase<OwnedRepr<i32>, Dim<[usize; 2]>>> for HiddenMarkovModel<Untrained>
impl Fit<ArrayBase<OwnedRepr<f64>, Dim<[usize; 3]>>, ArrayBase<OwnedRepr<i32>, Dim<[usize; 2]>>> for HiddenMarkovModel<Untrained>
Source§type Fitted = HiddenMarkovModel<HiddenMarkovModelTrained>
type Fitted = HiddenMarkovModel<HiddenMarkovModelTrained>
The fitted model type
Source§fn fit(self, X: &Array3<Float>, y: &Array2<i32>) -> SklResult<Self::Fitted>
fn fit(self, X: &Array3<Float>, y: &Array2<i32>) -> SklResult<Self::Fitted>
Fit the model to the provided data with validation
Source§fn fit_with_validation(
self,
x: &X,
y: &Y,
_x_val: Option<&X>,
_y_val: Option<&Y>,
) -> Result<(Self::Fitted, FitMetrics), SklearsError>where
Self: Sized,
fn fit_with_validation(
self,
x: &X,
y: &Y,
_x_val: Option<&X>,
_y_val: Option<&Y>,
) -> Result<(Self::Fitted, FitMetrics), SklearsError>where
Self: Sized,
Fit with custom validation and early stopping
Source§impl Predict<ArrayBase<OwnedRepr<f64>, Dim<[usize; 3]>>, ArrayBase<OwnedRepr<i32>, Dim<[usize; 2]>>> for HiddenMarkovModel<HiddenMarkovModelTrained>
impl Predict<ArrayBase<OwnedRepr<f64>, Dim<[usize; 3]>>, ArrayBase<OwnedRepr<i32>, Dim<[usize; 2]>>> for HiddenMarkovModel<HiddenMarkovModelTrained>
Source§fn predict(&self, X: &Array3<Float>) -> SklResult<Array2<i32>>
fn predict(&self, X: &Array3<Float>) -> SklResult<Array2<i32>>
Make predictions on the provided data
Source§fn predict_with_uncertainty(
&self,
x: &X,
) -> Result<(Output, UncertaintyMeasure), SklearsError>
fn predict_with_uncertainty( &self, x: &X, ) -> Result<(Output, UncertaintyMeasure), SklearsError>
Make predictions with confidence intervals
Auto Trait Implementations§
impl<State> Freeze for HiddenMarkovModel<State>where
State: Freeze,
impl<State> RefUnwindSafe for HiddenMarkovModel<State>where
State: RefUnwindSafe,
impl<State> Send for HiddenMarkovModel<State>where
State: Send,
impl<State> Sync for HiddenMarkovModel<State>where
State: Sync,
impl<State> Unpin for HiddenMarkovModel<State>where
State: Unpin,
impl<State> UnwindSafe for HiddenMarkovModel<State>where
State: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> StableApi for Twhere
T: Estimator,
impl<T> StableApi for Twhere
T: Estimator,
Source§const STABLE_SINCE: &'static str = "0.1.0"
const STABLE_SINCE: &'static str = "0.1.0"
API version this type was stabilized in
Source§const HAS_EXPERIMENTAL_FEATURES: bool = false
const HAS_EXPERIMENTAL_FEATURES: bool = false
Whether this API has any experimental features