pub struct LinearChainCRF { /* private fields */ }Expand description
Linear-chain CRF for sequence labeling.
This specialized CRF structure enables efficient inference using the forward-backward algorithm and Viterbi decoding.
Implementations§
Source§impl LinearChainCRF
impl LinearChainCRF
Sourcepub fn add_feature(&mut self, feature: Box<dyn FeatureFunction>, weight: f64)
pub fn add_feature(&mut self, feature: Box<dyn FeatureFunction>, weight: f64)
Add a feature function with its weight.
Sourcepub fn set_transition_weights(&mut self, weights: Array2<f64>) -> Result<()>
pub fn set_transition_weights(&mut self, weights: Array2<f64>) -> Result<()>
Set transition weights directly.
This is useful when you have pre-trained weights.
Sourcepub fn set_emission_weights(&mut self, weights: Array2<f64>) -> Result<()>
pub fn set_emission_weights(&mut self, weights: Array2<f64>) -> Result<()>
Set emission weights directly.
Sourcepub fn viterbi(&self, input_sequence: &[usize]) -> Result<(Vec<usize>, f64)>
pub fn viterbi(&self, input_sequence: &[usize]) -> Result<(Vec<usize>, f64)>
Viterbi algorithm for finding the most likely label sequence.
Returns the optimal label sequence and its score.
Sourcepub fn forward(&self, input_sequence: &[usize]) -> Result<Array2<f64>>
pub fn forward(&self, input_sequence: &[usize]) -> Result<Array2<f64>>
Forward algorithm for computing marginal probabilities.
Returns forward probabilities: α[t, s] = P(y₁…yₜ = s, x₁…xₜ)
Sourcepub fn backward(&self, input_sequence: &[usize]) -> Result<Array2<f64>>
pub fn backward(&self, input_sequence: &[usize]) -> Result<Array2<f64>>
Backward algorithm for computing marginal probabilities.
Returns backward probabilities: β[t, s] = P(yₜ₊₁…yₙ | yₜ = s, xₜ₊₁…xₙ)
Sourcepub fn marginals(&self, input_sequence: &[usize]) -> Result<Array2<f64>>
pub fn marginals(&self, input_sequence: &[usize]) -> Result<Array2<f64>>
Compute marginal probabilities for each position.
Returns: P(yₜ = s | x) for all t and s
Sourcepub fn to_factor_graph(&self, input_sequence: &[usize]) -> Result<FactorGraph>
pub fn to_factor_graph(&self, input_sequence: &[usize]) -> Result<FactorGraph>
Convert to factor graph representation.
Auto Trait Implementations§
impl Freeze for LinearChainCRF
impl !RefUnwindSafe for LinearChainCRF
impl Send for LinearChainCRF
impl Sync for LinearChainCRF
impl Unpin for LinearChainCRF
impl !UnwindSafe for LinearChainCRF
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
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>
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>
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<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.