Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ndarray for matrix operations #1

Open
messense opened this issue Feb 2, 2021 · 2 comments
Open

Use ndarray for matrix operations #1

messense opened this issue Feb 2, 2021 · 2 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@messense
Copy link
Owner

messense commented Feb 2, 2021

https://github.com/rust-ndarray/ndarray

@messense messense added enhancement New feature or request help wanted Extra attention is needed labels Feb 2, 2021
@xd009642
Copy link

Just before I start looking into this is it still necessary (I notice the issue is >1 year old and code has obviously changed since then), and if so where in the code should I start looking 👀

@messense
Copy link
Owner Author

Not much has changed, I think it's the Context code.

crfs-rs/src/context.rs

Lines 26 to 100 in dcd02b5

/// Context maintains internal data for an instance
#[derive(Debug, Clone, Default)]
pub struct Context {
/// Flag specifying the functionality
flag: Flag,
/// The total number of distinct labels
pub num_labels: u32,
/// The number of items in the instance
pub num_items: u32,
/// The maximum number of labels
cap_items: u32,
/// Logarithm of the normalization factor for the instance.
///
/// This is equivalent to the total scores of all paths in the lattice.
log_norm: f64,
/// State scores
///
/// This is a `[T][L]` matrix whose element `[t][l]` presents total score
/// of state features associating label #l at #t.
pub state: Vec<f64>,
/// Transition scores
///
/// This is a `[L][L]` matrix whose element `[i][j]` represents the total
/// score of transition features associating labels #i and #j.
pub trans: Vec<f64>,
/// Alpha score matrix
///
/// This is a `[T][L]` matrix whose element `[t][l]` presents the total
/// score of paths starting at BOS and arriving at (t, l).
alpha_score: Vec<f64>,
/// Beta score matrix
///
/// This is a `[T][L]` matrix whose element `[t][l]` presents the total
/// score of paths starting at (t, l) and arriving at EOS.
beta_score: Vec<f64>,
/// Scale factor vector
///
/// This is a `[T]` vector whose element `[t]` presents the scaling
/// coefficient for the alpha_score and beta_score.
scale_factor: Vec<f64>,
/// Row vector (work space)
///
/// This is a `[T]` vector used internally for a work space.
row: Vec<f64>,
/// Backward edges
///
/// This is a `[T][L]` matrix whose element `[t][j]` represents the label #i
/// that yields the maximum score to arrive at (t, j).
/// This member is available only with `CTXF_VITERBI` flag enabled.
backward_edge: Vec<u32>,
/// Exponents of state scores
///
/// This is a `[T][L]` matrix whose element `[t][l]` presents the exponent
/// of the total score of state features associating label #l at #t.
/// This member is available only with `CTXF_MARGINALS` flag.
exp_state: Vec<f64>,
/// Exponents of transition scores.
///
/// This is a `[L][L]` matrix whose element `[i][j]` represents the exponent
/// of the total score of transition features associating labels #i and #j.
/// This member is available only with `CTXF_MARGINALS` flag.
exp_trans: Vec<f64>,
/// Model expectations of states.
///
/// This is a `[T][L]` matrix whose element `[t][l]` presents the model
/// expectation (marginal probability) of the state (t,l)
/// This member is available only with CTXF_MARGINALS flag.
mexp_state: Vec<f64>,
/// Model expectations of transitions.
///
/// This is a `[L][L]` matrix whose element `[i][j]` presents the model
/// expectation of the transition (i--j).
/// This member is available only with `CTXF_MARGINALS` flag.
mexp_trans: Vec<f64>,
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants