Skip to main content

LinearChainCrf

Struct LinearChainCrf 

Source
pub struct LinearChainCrf {
    pub n_labels: usize,
    pub n_features: usize,
    pub emissions: Vec<f64>,
    pub transitions: Vec<f64>,
}
Expand description

Linear-chain CRF with linear emissions over real-valued features and a full dense transition matrix.

  • emissions[label*n_features + k] — emission weight w_k for label
  • transitions[prev*n_labels + cur] — transition weight from prev to cur

Fields§

§n_labels: usize§n_features: usize§emissions: Vec<f64>§transitions: Vec<f64>

Implementations§

Source§

impl LinearChainCrf

Source

pub fn zeros(n_labels: usize, n_features: usize) -> SeqResult<Self>

Construct a zero-initialised CRF.

Source

pub fn param_count(&self) -> usize

Number of free parameters (emissions + transitions).

Source

pub fn to_params(&self) -> Vec<f64>

Pack (emissions, transitions) into a flat parameter vector.

Source

pub fn from_params(&mut self, p: &[f64]) -> SeqResult<()>

Unpack a flat parameter vector into (emissions, transitions).

Source

pub fn emit_score(&self, label: usize, x: &[f64]) -> SeqResult<f64>

Compute the emission score for a single (label, feature_vec) pair.

Source

pub fn trans_score(&self, prev: usize, cur: usize) -> SeqResult<f64>

Score for a single (prev_label, cur_label) transition.

Source

pub fn sequence_score(&self, x: &[f64], y: &[usize]) -> SeqResult<f64>

Score of a full label sequence given a feature matrix (T × n_features).

Trait Implementations§

Source§

impl Clone for LinearChainCrf

Source§

fn clone(&self) -> LinearChainCrf

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for LinearChainCrf

Source§

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

Formats the value using the given formatter. 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> 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.