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: callers can pass borrowed slices directly via SampleRef or tuple impls without allocating.

§Built-in implementations

TypeAllocates?
SampleRef<'a>No – borrows &[f64]
(&[f64], f64)No – tuple of slice + target
(Vec<f64>, f64)Owns Vec<f64> (requires alloc feature)

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)

Available on crate feature alloc only.
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)

Available on crate feature alloc only.
Source§

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

Source§

fn target(&self) -> f64

Implementors§

Source§

impl Observation for &Sample

Available on crate feature alloc only.
Source§

impl Observation for Sample

Available on crate feature alloc only.
Source§

impl<'a> Observation for SampleRef<'a>