Skip to main content

CostModel

Trait CostModel 

Source
pub trait CostModel {
    type Prepared;

    // Required methods
    fn prepare(&self, step: &Step) -> Self::Prepared;
    fn cost_prepared(&self, a: &Self::Prepared, b: &Self::Prepared) -> f64;

    // Provided method
    fn cost(&self, a: &Step, b: &Step) -> f64 { ... }
}
Expand description

A step-vs-step alignment cost in [0, 1]: 0.0 = identical content, 1.0 = nothing in common. Implementations must be deterministic and symmetric — the aligner’s output is part of the reproducibility promise, and the fork rule’s tau thresholds compare against these values directly.

The trait is split at the per-step precomputation seam: prepare digests one step into whatever form the model compares — LexicalCost’s token sequence, a future tf-idf model’s term vector, an embedding — and cost_prepared scores two digests. The aligner prepares each run once (O(n+m)) and only scores inside the O(n·m) cost matrix, so per-step work never multiplies by the number of cells (issue #16).

Required Associated Types§

Source

type Prepared

The per-step precomputation this model compares by.

Required Methods§

Source

fn prepare(&self, step: &Step) -> Self::Prepared

Digest one step into its comparable form.

Source

fn cost_prepared(&self, a: &Self::Prepared, b: &Self::Prepared) -> f64

Cost of aligning two prepared steps.

Provided Methods§

Source

fn cost(&self, a: &Step, b: &Step) -> f64

Cost of aligning a with b: prepare both, score once. A one-off convenience — code that compares many pairs prepares each step once and calls cost_prepared.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§