Skip to main content

Observation

Trait Observation 

Source
pub trait Observation {
    // Required methods
    fn features(&self) -> &[f64];
    fn target(&self) -> f64;

    // Provided method
    fn weight(&self) -> f64 { ... }
}
Expand description

Trait for anything that can be used as a training observation.

Implementors provide a feature slice and a target value. The optional weight method defaults to 1.0 for uniform weighting.

This trait enables zero-copy training: instead of requiring an owned Sample (which forces a Vec<f64> allocation), callers can pass borrowed slices directly via SampleRef or tuple impls.

§Built-in implementations

TypeAllocates?
SampleAlready owns Vec<f64>
SampleRef<'a>No — borrows &[f64]
(&[f64], f64)No — tuple of slice + target
(Vec<f64>, f64)Owns Vec<f64>

§Example

use irithyll::Observation;

// Zero-copy from a raw slice:
let features = [1.0, 2.0, 3.0];
let obs = (&features[..], 42.0);
assert_eq!(obs.features(), &[1.0, 2.0, 3.0]);
assert_eq!(obs.target(), 42.0);
assert_eq!(obs.weight(), 1.0);

Required Methods§

Source

fn features(&self) -> &[f64]

The feature values for this observation.

Source

fn target(&self) -> f64

The target value (regression) or class label (classification).

Provided Methods§

Source

fn weight(&self) -> f64

Optional sample weight. Defaults to 1.0 (uniform).

Implementations on Foreign Types§

Source§

impl Observation for (&Vec<f64>, f64)

Source§

fn features(&self) -> &[f64]

Source§

fn target(&self) -> f64

Source§

impl Observation for (&[f64], f64)

Source§

fn features(&self) -> &[f64]

Source§

fn target(&self) -> f64

Source§

impl Observation for (Vec<f64>, f64)

Source§

fn features(&self) -> &[f64]

Source§

fn target(&self) -> f64

Implementors§