[][src]Enum lfa::core::Features

pub enum Features {
    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 Features[src]

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

Return true if the features is the Dense variant.

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

Return true if the features is the Sparse variant.

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

Return the number of active features.

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

Remove one feature entry from the features, if present.

For the Features::Dense variant, the feature is set to zero, and for the Features::Sparse variant, the feature index is removed entirely.

use lfa::basis::Features;

let mut dense: Features = vec![0.0, 0.2, 0.4, 0.4].into();
let mut sparse: Features = 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: &VectorView<f64>) -> f64[src]

Apply the dot product operation between the Features and some other Vector, typically a set of weights.

use lfa::basis::Features;
use lfa::geometry::Vector;

let weights = Vector::from_vec(vec![2.0, 5.0, 1.0]);

assert_eq!(Features::dot(&vec![0.0, 0.2, 0.8].into(), &weights.view()), 1.8);
assert_eq!(Features::dot(&vec![0, 1].into(), &weights.view()), 7.0);

pub fn dot_dense(activations: &DenseT, weights: &VectorView<f64>) -> f64[src]

pub fn dot_sparse(indices: &SparseT, weights: &VectorView<f64>) -> f64[src]

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

Apply the dot product operation between the Features and some other Vector, typically a set of weights.

use lfa::basis::Features;
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!(
    Features::matmul(&vec![0.1, 0.2, 0.7].into(), &weights.view()).all_close(
        &Vector::from_vec(vec![1.1, 3.2]),
        1e-7 // eps
    )
);
assert_eq!(
    Features::matmul(&vec![0, 1].into(), &weights.view()),
    Vector::from_vec(vec![3.0, 8.0])
);

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

Expand the features and convert it into a raw, dense vector.

use lfa::basis::Features;

assert_eq!(
    Features::expanded(&vec![0, 2, 1, 4].into(), 5),
    vec![1.0, 1.0, 1.0, 0.0, 1.0].into()
);

pub fn stack(self, d1: usize, other: Features, d2: usize) -> Features[src]

Stack two feature vectors together, maintaining sparsity where possible.

use lfa::basis::Features;

assert_eq!(
    Features::stack(vec![0.0, 1.0].into(), 2, vec![1.0, 0.0, 1.0].into(), 3),
    vec![0.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 features 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 features 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 features; either Dense or Sparse, respectively.

Trait Implementations

impl PartialEq<Features> for Features[src]

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

This method tests for !=.

impl Clone for Features[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 Features[src]

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

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

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

impl Debug for Features[src]

impl Index<usize> for Features[src]

type Output = f64

The returned type after indexing.

impl FromIterator<f64> for Features[src]

impl FromIterator<usize> for Features[src]

Auto Trait Implementations

impl Send for Features

impl Sync for Features

Blanket Implementations

impl<T> Composable for T[src]

fn lfa<A: Approximator>(self, approximator: A) -> LFA<Self, A>[src]

Return an LFA using this Projector instance and a given Approximator.

fn stack<P>(self, p: P) -> Stack<Self, P>[src]

Return a Stack of this Projector over another.

fn add<P: Space>(self, p: P) -> Sum<Self, P> where
    Self: Space
[src]

Return the Sum of this Projector and another.

fn subtract<P: Space>(self, p: P) -> Sum<Self, Negate<P>> where
    Self: Space
[src]

Return the Sum of this Projector and the Negated other.

fn shift(self, offset: f64) -> Shift<Self>[src]

Return the original Projector with all activations Shifted by some offset.

fn multiply<P: Space>(self, p: P) -> Product<Self, P> where
    Self: Space
[src]

Return the Product of this Projector and another.

fn divide<P: Space>(self, p: P) -> Product<Self, Reciprocal<P>> where
    Self: Space
[src]

Return the Product of this Projector and the Reciprocal of the other.

fn scale(self, factor: f64) -> Scale<Self>[src]

Return the original Projector with all activations Scaled by some factor.

fn normalise_l1(self) -> L1Normalise<Self>[src]

Return the original Projector with all activations normalised in L₁.

fn normalise_l2(self) -> L2Normalise<Self>[src]

Return the original Projector with all activations normalised in L₂.

fn normalise_lp(self, p: u8) -> LpNormalise<Self>[src]

Return the original Projector with all activations normalised in Lp.

fn normalise_linf(self) -> LinfNormalise<Self>[src]

Return the original Projector with all activations normalised in L∞.

fn with_constant(self) -> Stack<Self, Constant>[src]

Return the a Stack of this Projector with a single constant feature term.

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

type Owned = T

The resulting type after obtaining ownership.

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<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, 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> 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]