[−][src]Enum lfa::core::Features
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]
self,
f_dense: impl FnOnce(DenseT) -> T,
f_sparse: impl FnOnce(SparseT) -> T
) -> T
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]
fn eq(&self, rhs: &Features) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl Clone for Features
[src]
fn clone(&self) -> 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]
fn from(activations: Vec<ActivationT>) -> 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]
impl FromIterator<f64> for Features
[src]
fn from_iter<I: IntoIterator<Item = ActivationT>>(iter: I) -> Self
[src]
impl FromIterator<usize> for Features
[src]
fn from_iter<I: IntoIterator<Item = IndexT>>(iter: I) -> Self
[src]
Auto Trait Implementations
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]
Self: Space,
Return the Sum
of this Projector
and another.
fn subtract<P: Space>(self, p: P) -> Sum<Self, Negate<P>> where
Self: Space,
[src]
Self: Space,
Return the Sum
of this Projector
and the Negate
d other.
fn shift(self, offset: f64) -> Shift<Self>
[src]
Return the original Projector
with all activations Shift
ed by some offset
.
fn multiply<P: Space>(self, p: P) -> Product<Self, P> where
Self: Space,
[src]
Self: Space,
Return the Product
of this Projector
and another.
fn divide<P: Space>(self, p: P) -> Product<Self, Reciprocal<P>> where
Self: Space,
[src]
Self: Space,
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 Scale
d 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]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> From for T
[src]
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,