Skip to main content

eml_core/
features.rs

1//! Generic feature vector trait for EML model inputs.
2//!
3//! Any struct that can produce a slice of `f64` values can implement
4//! [`FeatureVector`] to be used as input to an [`EmlModel`].
5
6/// Trait for types that can produce a fixed-length feature vector
7/// suitable as EML model input.
8///
9/// Implementors should normalize features to roughly [0, 1] for
10/// best numerical stability.
11///
12/// # Example
13///
14/// ```
15/// use eml_core::FeatureVector;
16///
17/// struct SensorReading {
18///     temperature: f64,
19///     humidity: f64,
20///     pressure: f64,
21/// }
22///
23/// impl FeatureVector for SensorReading {
24///     fn as_features(&self) -> Vec<f64> {
25///         vec![
26///             self.temperature / 100.0,  // normalize to ~[0,1]
27///             self.humidity / 100.0,
28///             self.pressure / 1100.0,
29///         ]
30///     }
31///
32///     fn feature_count() -> usize {
33///         3
34///     }
35/// }
36/// ```
37pub trait FeatureVector {
38    /// Return the feature values as a Vec of f64.
39    ///
40    /// Values should be normalized to roughly [0, 1] for best
41    /// training convergence.
42    fn as_features(&self) -> Vec<f64>;
43
44    /// The number of features this type produces.
45    ///
46    /// Must be constant for all instances of the same type.
47    fn feature_count() -> usize;
48}