Enum lfa::basis::Projection

source ·
pub enum Projection {
    Dense(DenseT),
    Sparse(SparseT),
}
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§

Return true if the projection is the Dense variant.

Return true if the projection is the Sparse variant.

Return the number of active features in the projection.

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

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

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

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

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

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

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

Trait Implementations§

The resulting type after applying the + operator.
Performs the + operation. Read more
Return the dimensionality of the output value Approximator::Value.
Evaluate the function and return its value.
Update the approximator’s estimate for the given input.
Adapt the approximator in light of newly discovered features.
Return the dimensionality of the output value Approximator::Value.
Evaluate the function and return its value.
Update the approximator’s estimate for the given input.
Adapt the approximator in light of newly discovered features.
Return the dimensionality of the output value Approximator::Value.
Evaluate the function and return its value.
Update the approximator’s estimate for the given input.
Adapt the approximator in light of newly discovered features.
Return the dimensionality of the output value Approximator::Value.
Evaluate the function and return its value.
Update the approximator’s estimate for the given input.
Adapt the approximator in light of newly discovered features.
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Deserialize this value from the given Serde deserializer. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Creates a value from an iterator. Read more
Creates a value from an iterator. Read more
The returned type after indexing.
Performs the indexing (container[index]) operation. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.