#![warn(missing_docs)]
use std::iter::IntoIterator;
pub trait Model {
type Features;
type Target;
fn num_coefficients(&self) -> usize;
fn coefficient(&mut self, coefficient: usize) -> &mut f64;
fn predict(&self, _: &Self::Features) -> Self::Target;
fn gradient(&self, coefficient: usize, input: &Self::Features) -> Self::Target;
}
pub trait Cost<Truth, Target = f64> {
fn outer_derivative(&self, prediction: &Target, truth: Truth) -> Target;
fn cost(&self, prediction: Target, truth: Truth) -> f64;
}
pub trait Teacher<M: Model> {
type Training;
fn new_training(&self, model: &M) -> Self::Training;
fn teach_event<Y, C>(
&self,
training: &mut Self::Training,
model: &mut M,
cost: &C,
features: &M::Features,
truth: Y,
) where
C: Cost<Y, M::Target>,
Y: Copy;
}
pub trait Crisp {
type Truth;
fn crisp(&self) -> Self::Truth;
}
pub fn learn_history<M, C, T, H, Truth>(teacher: &T, cost: &C, model: &mut M, history: H)
where
M: Model,
C: Cost<Truth, M::Target>,
T: Teacher<M>,
H: IntoIterator<Item = (M::Features, Truth)>,
Truth: Copy,
{
let mut training = teacher.new_training(model);
for (features, truth) in history {
teacher.teach_event(&mut training, model, cost, &features, truth);
}
}
mod array;
pub mod cost;
pub mod crisp;
pub mod linear_algebra;
pub mod model;
pub mod teacher;
pub mod tutorial;