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
| Type | Allocates? |
|---|---|
Sample | Already 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);