[−][src]Crate lfa
lfa
is a framework for online learning of linear function approximation
models. Included is a suite of scalar and multi-output approximation
helpers, a range of basis functions for feature construction, and a set of
optimisation routines. The framework is designed to support
fallible operations for which a custom error type is provided.
Example
The code below illustrates how one might use lfa
to fit a simple linear
model with SGD.
extern crate lfa; extern crate rand; extern crate rand_distr; use lfa::{ LFA, basis::{Basis, Polynomial}, optim::SGD, }; use rand::{Rng, thread_rng}; use rand_distr::{Uniform, Normal}; use spaces::Space; fn main() { const M: f64 = 1.0; const C: f64 = -0.5; let mut fa = LFA::scalar( Polynomial::new(1, 1).with_zeroth(), SGD(1.0) ); let mut rng = thread_rng(); let mut data_dist = Uniform::new_inclusive(-1.0, 1.0); let mut noise_dist = Normal::new(0.0, 0.01).unwrap(); for x in rng.sample_iter(&data_dist).take(1000) { let y_exp = M*x + C; let y_sample = y_exp + rng.sample(noise_dist); fa.update_with(&[x], |_, y_pred| y_sample - y_pred).ok(); } let rmse = ( (fa.weights[0] - M).powi(2) + (fa.weights[1] - C).powi(2) ).sqrt(); assert!(rmse < 1e-3); }
Modules
basis | Basis function representations used to generate |
optim | SGD-based weight optimisers. |
Structs
Error | |
LFA | Linear function approximator. |
OutputIter | An iterator over the evaluated columns of a weight matrix. |
SparseActivations | Internal type used to represent a sparse feature vector. |
Enums
ErrorKind | |
Features | Sparse/dense feature vector representation. |
Type Definitions
ActivationT | Internal type used to represent a feature's activation. |
DenseActivations | Internal type used to represent a dense feature vector. |
IndexT | Internal type used to represent a feature's index. |
Result | |
ScalarLFA | Linear function approximator with scalar output. |
VectorLFA | Linear function approximator with vector output. |