pub struct SparseFeatures { /* private fields */ }Expand description
Sparse feature vector: sorted (FeatureId, value) pairs.
§Requirements
- Sorted by
FeatureIdin ascending order. - No duplicate
FeatureIds. - Zero values may be omitted.
- Not a
HashMap<String, f64>.
§Examples
use rill_ml::sparse::SparseFeatures;
let features = SparseFeatures::from_sorted(vec![
(1, 0.5),
(3, 2.0),
(7, -1.0),
]).unwrap();
assert_eq!(features.len(), 3);
assert_eq!(features.get(3), Some(2.0));Implementations§
Source§impl SparseFeatures
impl SparseFeatures
Sourcepub fn from_sorted(values: Vec<(FeatureId, f64)>) -> Result<Self, RillError>
pub fn from_sorted(values: Vec<(FeatureId, f64)>) -> Result<Self, RillError>
Build from a Vec that is already sorted by FeatureId and contains
no duplicates.
Returns an error if the input is unsorted, has duplicates, or contains non-finite values.
Sourcepub fn from_unsorted(values: Vec<(FeatureId, f64)>) -> Result<Self, RillError>
pub fn from_unsorted(values: Vec<(FeatureId, f64)>) -> Result<Self, RillError>
Build from an unsorted Vec, sorting and merging duplicates by
summing their values.
Non-finite values are rejected after merging.
Sourcepub fn push(&mut self, id: FeatureId, value: f64) -> Result<(), RillError>
pub fn push(&mut self, id: FeatureId, value: f64) -> Result<(), RillError>
Append a single feature. The id must be strictly greater than the
last inserted id.
Sourcepub fn get(&self, id: FeatureId) -> Option<f64>
pub fn get(&self, id: FeatureId) -> Option<f64>
Look up the value for a given FeatureId via binary search.
Trait Implementations§
Source§impl Clone for SparseFeatures
impl Clone for SparseFeatures
Source§fn clone(&self) -> SparseFeatures
fn clone(&self) -> SparseFeatures
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SparseFeatures
impl Debug for SparseFeatures
Source§impl Default for SparseFeatures
impl Default for SparseFeatures
Source§fn default() -> SparseFeatures
fn default() -> SparseFeatures
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for SparseFeatures
impl RefUnwindSafe for SparseFeatures
impl Send for SparseFeatures
impl Sync for SparseFeatures
impl Unpin for SparseFeatures
impl UnsafeUnpin for SparseFeatures
impl UnwindSafe for SparseFeatures
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more