[][src]Enum lfa::basis::Projection

pub enum Projection {
    Dense(DenseT),
    Sparse(SparseT),
}

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.

Methods

impl Projection[src]

pub fn is_dense(&self) -> bool[src]

Return true if the projection is the Dense variant.

pub fn is_sparse(&self) -> bool[src]

Return true if the projection is the Sparse variant.

pub fn activity(&self) -> usize[src]

Return the number of active features in the projection.

pub fn remove(&mut self, idx: usize)[src]

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());

pub fn dot(&self, weights: &Vector<f64>) -> f64[src]

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);

pub fn matmul(&self, weights: &Matrix<f64>) -> Vector<f64>[src]

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])
);

pub fn expanded(self, dim: usize) -> DenseT[src]

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()
);

pub fn map_dense<F, T>(self, f: impl FnOnce(DenseT) -> T) -> Option<T>[src]

Apply the function f to the projection if the Dense variant or return None.

pub fn map_sparse<F, T>(self, f: impl FnOnce(SparseT) -> T) -> Option<T>[src]

Apply the function f to the projection if the Sparse variant or return None.

pub fn map_either<T>(
    self,
    f_dense: impl FnOnce(DenseT) -> T,
    f_sparse: impl FnOnce(SparseT) -> T
) -> T
[src]

Apply the function f or g depending on the contents of the projection; either Dense or Sparse, respectively.

Trait Implementations

impl Approximator<Projection> for ScalarFunction[src]

type Value = f64

impl Approximator<Projection> for PairFunction[src]

type Value = (f64, f64)

impl Approximator<Projection> for TripleFunction[src]

type Value = (f64, f64, f64)

impl Approximator<Projection> for VectorFunction[src]

type Value = Vector<f64>

impl PartialEq<Projection> for Projection[src]

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests for !=.

impl Clone for Projection[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl From<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>> for Projection[src]

impl From<Vec<f64>> for Projection[src]

impl From<BTreeSet<usize>> for Projection[src]

impl From<Vec<usize>> for Projection[src]

impl Add<Projection> for Projection[src]

type Output = Projection

The resulting type after applying the + operator.

impl Index<usize> for Projection[src]

type Output = f64

The returned type after indexing.

impl FromIterator<f64> for Projection[src]

impl FromIterator<usize> for Projection[src]

impl Debug for Projection[src]

impl Serialize for Projection[src]

impl<'de> Deserialize<'de> for Projection[src]

Auto Trait Implementations

impl Send for Projection

impl Sync for Projection

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]