Enum lfa::basis::Projection
source · Expand description
Projected feature vector representation.
Variants§
Dense(DenseT)
Dense, floating-point activation vector.
Sparse(SparseT)
Sparse, index-based activation vector.
Note: it is taken that all active indices have implied activation of 1.
Implementations§
source§impl Projection
impl Projection
sourcepub fn remove(&mut self, idx: usize)
pub fn remove(&mut self, idx: usize)
Remove one feature entry from the projection, if present.
For the Projection::Dense
variant, the feature is set to zero, and for
the Projection::Sparse
variant, the feature index is removed
entirely.
use lfa::basis::Projection;
let mut dense: Projection = vec![0.0, 0.2, 0.4, 0.4].into();
let mut sparse: Projection = vec![0, 10, 15].into();
dense.remove(1);
sparse.remove(10);
assert_eq!(dense, vec![0.0, 0.0, 0.4, 0.4].into());
assert_eq!(sparse, vec![0, 15].into());
sourcepub fn dot(&self, weights: &Vector<f64>) -> f64
pub fn dot(&self, weights: &Vector<f64>) -> f64
Apply the dot product operation between the Projection
and some other
Vector
, typically a set of weights.
use lfa::basis::Projection;
use lfa::geometry::Vector;
let weights = Vector::from_vec(vec![2.0, 5.0, 1.0]);
assert_eq!(Projection::dot(&vec![0.0, 0.2, 0.8].into(), &weights), 1.8);
assert_eq!(Projection::dot(&vec![0, 1].into(), &weights), 7.0);
sourcepub fn matmul(&self, weights: &Matrix<f64>) -> Vector<f64>
pub fn matmul(&self, weights: &Matrix<f64>) -> Vector<f64>
Apply the dot product operation between the Projection
and some other
Vector
, typically a set of weights.
use lfa::basis::Projection;
use lfa::geometry::{Matrix, Vector};
let weights = Matrix::from_shape_vec((3, 2), vec![2.0, 5.0, 1.0, 3.0, 1.0, 3.0]).unwrap();
assert!(
Projection::matmul(&vec![0.1, 0.2, 0.7].into(), &weights).all_close(
&Vector::from_vec(vec![1.1, 3.2]),
1e-7 // eps
)
);
assert_eq!(
Projection::matmul(&vec![0, 1].into(), &weights),
Vector::from_vec(vec![3.0, 8.0])
);
sourcepub fn expanded(self, dim: usize) -> DenseT
pub fn expanded(self, dim: usize) -> DenseT
Expand the projection and convert it into a raw, dense vector.
use lfa::basis::Projection;
assert_eq!(
Projection::expanded(vec![0, 2, 1, 4].into(), 5),
vec![1.0, 1.0, 1.0, 0.0, 1.0].into()
);
sourcepub fn map_dense<F, T>(self, f: impl FnOnce(DenseT) -> T) -> Option<T>
pub fn map_dense<F, T>(self, f: impl FnOnce(DenseT) -> T) -> Option<T>
Apply the function f
to the projection if the Dense
variant or
return None
.
sourcepub fn map_sparse<F, T>(self, f: impl FnOnce(SparseT) -> T) -> Option<T>
pub fn map_sparse<F, T>(self, f: impl FnOnce(SparseT) -> T) -> Option<T>
Apply the function f
to the projection if the Sparse
variant or
return None
.
Trait Implementations§
source§impl Add<Projection> for Projection
impl Add<Projection> for Projection
§type Output = Projection
type Output = Projection
+
operator.source§fn add(self, rhs: Projection) -> Projection
fn add(self, rhs: Projection) -> Projection
+
operation. Read moresource§impl Approximator<Projection> for PairFunction
impl Approximator<Projection> for PairFunction
type Value = (f64, f64)
source§fn n_outputs(&self) -> usize
fn n_outputs(&self) -> usize
Approximator::Value
.source§fn evaluate(&self, p: &Projection) -> EvaluationResult<(f64, f64)>
fn evaluate(&self, p: &Projection) -> EvaluationResult<(f64, f64)>
source§fn update(&mut self, p: &Projection, errors: (f64, f64)) -> UpdateResult<()>
fn update(&mut self, p: &Projection, errors: (f64, f64)) -> UpdateResult<()>
source§impl Approximator<Projection> for ScalarFunction
impl Approximator<Projection> for ScalarFunction
type Value = f64
source§fn n_outputs(&self) -> usize
fn n_outputs(&self) -> usize
Approximator::Value
.source§fn evaluate(&self, p: &Projection) -> EvaluationResult<f64>
fn evaluate(&self, p: &Projection) -> EvaluationResult<f64>
source§fn update(&mut self, p: &Projection, error: f64) -> UpdateResult<()>
fn update(&mut self, p: &Projection, error: f64) -> UpdateResult<()>
source§impl Approximator<Projection> for TripleFunction
impl Approximator<Projection> for TripleFunction
type Value = (f64, f64, f64)
source§fn n_outputs(&self) -> usize
fn n_outputs(&self) -> usize
Approximator::Value
.source§fn evaluate(&self, p: &Projection) -> EvaluationResult<(f64, f64, f64)>
fn evaluate(&self, p: &Projection) -> EvaluationResult<(f64, f64, f64)>
source§fn update(&mut self, p: &Projection, errors: (f64, f64, f64)) -> UpdateResult<()>
fn update(&mut self, p: &Projection, errors: (f64, f64, f64)) -> UpdateResult<()>
source§impl Approximator<Projection> for VectorFunction
impl Approximator<Projection> for VectorFunction
type Value = ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>
source§fn n_outputs(&self) -> usize
fn n_outputs(&self) -> usize
Approximator::Value
.source§fn evaluate(&self, p: &Projection) -> EvaluationResult<Vector<f64>>
fn evaluate(&self, p: &Projection) -> EvaluationResult<Vector<f64>>
source§fn update(&mut self, p: &Projection, errors: Vector<f64>) -> UpdateResult<()>
fn update(&mut self, p: &Projection, errors: Vector<f64>) -> UpdateResult<()>
source§impl Clone for Projection
impl Clone for Projection
source§fn clone(&self) -> Projection
fn clone(&self) -> Projection
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more