[−][src]Enum lfa::basis::Projection
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]
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
projection; either Dense
or Sparse
, respectively.
Trait Implementations
impl Approximator<Projection> for ScalarFunction
[src]
type Value = f64
fn n_outputs(&self) -> usize
[src]
fn evaluate(&self, p: &Projection) -> EvaluationResult<f64>
[src]
fn update(&mut self, p: &Projection, error: f64) -> UpdateResult<()>
[src]
fn adapt(
&mut self,
new_features: &HashMap<IndexT, IndexSet>
) -> AdaptResult<usize>
[src]
&mut self,
new_features: &HashMap<IndexT, IndexSet>
) -> AdaptResult<usize>
impl Approximator<Projection> for PairFunction
[src]
type Value = (f64, f64)
fn n_outputs(&self) -> usize
[src]
fn evaluate(&self, p: &Projection) -> EvaluationResult<(f64, f64)>
[src]
fn update(&mut self, p: &Projection, errors: (f64, f64)) -> UpdateResult<()>
[src]
fn adapt(
&mut self,
new_features: &HashMap<IndexT, IndexSet>
) -> AdaptResult<usize>
[src]
&mut self,
new_features: &HashMap<IndexT, IndexSet>
) -> AdaptResult<usize>
impl Approximator<Projection> for TripleFunction
[src]
type Value = (f64, f64, f64)
fn n_outputs(&self) -> usize
[src]
fn evaluate(&self, p: &Projection) -> EvaluationResult<(f64, f64, f64)>
[src]
fn update(
&mut self,
p: &Projection,
errors: (f64, f64, f64)
) -> UpdateResult<()>
[src]
&mut self,
p: &Projection,
errors: (f64, f64, f64)
) -> UpdateResult<()>
fn adapt(
&mut self,
new_features: &HashMap<IndexT, IndexSet>
) -> AdaptResult<usize>
[src]
&mut self,
new_features: &HashMap<IndexT, IndexSet>
) -> AdaptResult<usize>
impl Approximator<Projection> for VectorFunction
[src]
type Value = Vector<f64>
fn n_outputs(&self) -> usize
[src]
fn evaluate(&self, p: &Projection) -> EvaluationResult<Vector<f64>>
[src]
fn update(&mut self, p: &Projection, errors: Vector<f64>) -> UpdateResult<()>
[src]
fn adapt(
&mut self,
new_features: &HashMap<IndexT, IndexSet>
) -> AdaptResult<usize>
[src]
&mut self,
new_features: &HashMap<IndexT, IndexSet>
) -> AdaptResult<usize>
impl PartialEq<Projection> for Projection
[src]
fn eq(&self, rhs: &Projection) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl Clone for Projection
[src]
fn clone(&self) -> 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]
fn from(activations: DenseT) -> Projection
[src]
impl From<Vec<f64>> for Projection
[src]
fn from(activations: Vec<ActivationT>) -> Projection
[src]
impl From<BTreeSet<usize>> for Projection
[src]
fn from(indices: SparseT) -> Projection
[src]
impl From<Vec<usize>> for Projection
[src]
fn from(indices: Vec<IndexT>) -> Projection
[src]
impl Add<Projection> for Projection
[src]
type Output = Projection
The resulting type after applying the +
operator.
fn add(self, rhs: Projection) -> Projection
[src]
impl Index<usize> for Projection
[src]
impl FromIterator<f64> for Projection
[src]
fn from_iter<I: IntoIterator<Item = ActivationT>>(iter: I) -> Self
[src]
impl FromIterator<usize> for Projection
[src]
fn from_iter<I: IntoIterator<Item = IndexT>>(iter: I) -> Self
[src]
impl Debug for Projection
[src]
impl Serialize for Projection
[src]
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
impl<'de> Deserialize<'de> for Projection
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
Auto Trait Implementations
impl Send for Projection
impl Sync for Projection
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T> From for T
[src]
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> 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,
fn borrow_mut(&mut self) -> &mut T
[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> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,