Skip to main content

QuantilePolicy

Struct QuantilePolicy 

Source
pub struct QuantilePolicy {
    pub rank_error: f64,
    pub exact_threshold: usize,
    pub max_summary_entries: usize,
}
Expand description

Error and memory policy for a QuantileSketch.

Fields§

§rank_error: f64

Maximum target rank error, as a fraction of the observation count.

§exact_threshold: usize

Number of observations retained exactly before summarization begins.

§max_summary_entries: usize

Hard maximum number of retained summary entries. Insertion fails instead of silently exceeding this limit or weakening rank_error.

Implementations§

Source§

impl QuantilePolicy

Source

pub fn new( rank_error: f64, exact_threshold: usize, max_summary_entries: usize, ) -> Result<Self, QuantileError>

Builds a checked policy.

Examples found in repository?
examples/bounded_sequence_inference.rs (line 7)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let policy = QuantilePolicy::new(0.02, 8, 256)?;
8    let mut left = QuantileSketch::new(policy.clone())?;
9    let mut right = QuantileSketch::new(policy)?;
10    for value in 0..100 {
11        if value % 2 == 0 {
12            left.insert(value as f64)?;
13        } else {
14            right.insert(value as f64)?;
15        }
16    }
17    left.merge(&right)?;
18    let median = left.estimate(0.5)?;
19    println!(
20        "quantile value={} rank=[{:.3},{:.3}] retained={} exact={}",
21        median.value, median.rank_lower, median.rank_upper, median.retained_entries, median.exact
22    );
23
24    let model = HiddenMarkovModel::discrete(
25        vec!["quiet", "active"],
26        vec![0.6, 0.4],
27        vec![vec![0.8, 0.2], vec![0.3, 0.7]],
28        vec![vec![0.9, 0.1], vec![0.2, 0.8]],
29    )?;
30    let observations = [0, 0, 1, 1];
31    let inference = forward_backward(&model, &observations)?;
32    let path = viterbi(&model, &observations)?;
33    println!(
34        "inference log-likelihood={:.6} path={:?} repairs={}",
35        inference.evidence.log_likelihood, path.states, inference.evidence.numerical_repairs
36    );
37
38    let data = [
39        Sequence::Discrete(vec![0, 0, 1, 1, 1, 0]),
40        Sequence::Discrete(vec![0, 1, 1, 0, 0, 0]),
41    ];
42    let report = fit_hmm(
43        &data,
44        HmmSpec::Discrete {
45            states: 2,
46            symbols: 2,
47            additive_smoothing: 1.0e-6,
48        },
49        HmmFitControl::new(23, 6, 1.0e-7, 10_000, 1.0e-12)?,
50    )?;
51    println!(
52        "fit likelihood={:.6} iterations={} converged={} repairs={} work={} termination={:?} seed={}",
53        report.evidence.log_likelihood,
54        report.evidence.iterations,
55        report.evidence.converged,
56        report.evidence.numerical_repairs,
57        report.evidence.work,
58        report.evidence.termination,
59        report.evidence.seed
60    );
61    Ok(())
62}

Trait Implementations§

Source§

impl Clone for QuantilePolicy

Source§

fn clone(&self) -> QuantilePolicy

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 QuantilePolicy

Source§

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

Formats the value using the given formatter. Read more
Source§

impl PartialEq for QuantilePolicy

Source§

fn eq(&self, other: &QuantilePolicy) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for QuantilePolicy

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.