use alloc::vec::Vec;
pub trait StreamingLearner: Send + Sync {
fn train_one(&mut self, features: &[f64], target: f64, weight: f64);
fn predict(&self, features: &[f64]) -> f64;
fn n_samples_seen(&self) -> u64;
fn reset(&mut self);
fn train(&mut self, features: &[f64], target: f64) {
self.train_one(features, target, 1.0);
}
fn train_one_weighted(&mut self, features: &[f64], target: f64, weight: f64) {
self.train_one(features, target, weight);
}
fn predict_batch(&self, feature_matrix: &[&[f64]]) -> Vec<f64> {
feature_matrix.iter().map(|row| self.predict(row)).collect()
}
#[deprecated(
since = "10.0.0",
note = "use the `Tunable` capability trait instead: `<T as Tunable>::diagnostics_array(model)` or hold `Box<dyn Tunable>`"
)]
#[doc(hidden)]
fn diagnostics_array(&self) -> [f64; 5] {
[0.0; 5]
}
#[deprecated(
since = "10.0.0",
note = "use the `Tunable` capability trait instead: `<T as Tunable>::adjust_config(model, lr_mult, lambda_delta)` or hold `Box<dyn Tunable>`"
)]
#[doc(hidden)]
fn adjust_config(&mut self, _lr_multiplier: f64, _lambda_delta: f64) {}
#[deprecated(
since = "10.0.0",
note = "use the `Structural` capability trait instead: `<T as Structural>::apply_structural_change(model, depth_delta, steps_delta)` or hold `Box<dyn Structural>`"
)]
#[doc(hidden)]
fn apply_structural_change(&mut self, _depth_delta: i32, _steps_delta: i32) {}
#[deprecated(
since = "10.0.0",
note = "use the `Structural` capability trait instead: `<T as Structural>::replacement_count(model)` or hold `Box<dyn Structural>`"
)]
#[doc(hidden)]
fn replacement_count(&self) -> u64 {
0
}
#[deprecated(
since = "10.0.0",
note = "use the `Structural` capability trait instead: `<T as Structural>::check_proactive_prune(model)` or hold `Box<dyn Structural>`"
)]
#[doc(hidden)]
fn check_proactive_prune(&mut self) -> bool {
false
}
#[deprecated(
since = "10.0.0",
note = "use the `Structural` capability trait instead: `<T as Structural>::set_prune_half_life(model, hl)` or hold `Box<dyn Structural>`"
)]
#[doc(hidden)]
fn set_prune_half_life(&mut self, _hl: usize) {}
#[deprecated(
since = "10.0.0",
note = "use the `HasReadout` capability trait instead: `<T as HasReadout>::readout_weights(model)` or hold `Box<dyn HasReadout>`"
)]
#[doc(hidden)]
fn readout_weights(&self) -> Option<&[f64]> {
None
}
#[deprecated(
since = "10.0.0",
note = "use the `Structural` capability trait instead: `<T as Structural>::tree_structure(model)` or hold `Box<dyn Structural>`"
)]
#[doc(hidden)]
fn tree_structure(&self) -> Vec<(usize, usize, f64, f64, u64)> {
Vec::new()
}
}
pub trait HasReadout: StreamingLearner {
fn readout_weights(&self) -> &[f64];
}
pub trait Tunable: StreamingLearner {
fn diagnostics_array(&self) -> [f64; 5];
fn adjust_config(&mut self, lr_multiplier: f64, lambda_delta: f64);
}
pub trait Structural: StreamingLearner {
fn apply_structural_change(&mut self, depth_delta: i32, steps_delta: i32);
fn replacement_count(&self) -> u64;
fn check_proactive_prune(&mut self) -> bool {
false
}
fn set_prune_half_life(&mut self, _hl: usize) {}
fn tree_structure(&self) -> Vec<(usize, usize, f64, f64, u64)> {
Vec::new()
}
}
#[cfg(test)]
mod _object_safety_tests {
use super::{HasReadout, StreamingLearner, Structural, Tunable};
use alloc::boxed::Box;
fn _object_safe_streaming_learner(_: Box<dyn StreamingLearner>) {}
fn _object_safe_has_readout(_: Box<dyn HasReadout>) {}
fn _object_safe_tunable(_: Box<dyn Tunable>) {}
fn _object_safe_structural(_: Box<dyn Structural>) {}
}