pub struct SparseCode {
pub dimension: usize,
pub active: HashMap<usize, f64>,
pub target_sparsity: f64,
}Expand description
Sparse code representation
Fields§
§dimension: usizeDimension of the code
active: HashMap<usize, f64>Active indices and their values
target_sparsity: f64Target sparsity level
Implementations§
Source§impl SparseCode
impl SparseCode
Sourcepub fn from_dense(values: &[f64], target_sparsity: f64) -> Self
pub fn from_dense(values: &[f64], target_sparsity: f64) -> Self
Create from dense vector
Sourcepub fn dot(&self, other: &SparseCode) -> f64
pub fn dot(&self, other: &SparseCode) -> f64
Dot product with another sparse code
Sourcepub fn cosine_similarity(&self, other: &SparseCode) -> f64
pub fn cosine_similarity(&self, other: &SparseCode) -> f64
Cosine similarity with another sparse code
Sourcepub fn add(&self, other: &SparseCode) -> SparseCode
pub fn add(&self, other: &SparseCode) -> SparseCode
Add two sparse codes
Sourcepub fn scale(&self, factor: f64) -> SparseCode
pub fn scale(&self, factor: f64) -> SparseCode
Scale sparse code
Trait Implementations§
Source§impl Clone for SparseCode
impl Clone for SparseCode
Source§fn clone(&self) -> SparseCode
fn clone(&self) -> SparseCode
Returns a duplicate of the value. Read more
1.0.0 · 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 SparseCode
impl Debug for SparseCode
Source§impl<'de> Deserialize<'de> for SparseCode
impl<'de> Deserialize<'de> for SparseCode
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for SparseCode
impl RefUnwindSafe for SparseCode
impl Send for SparseCode
impl Sync for SparseCode
impl Unpin for SparseCode
impl UnwindSafe for SparseCode
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