pub trait VSA: Sized + Clone {
type Elem: Copy + Debug + PartialEq + Into<f32>;
// Required methods
fn generate(dim: usize, rng: &mut impl Rng) -> Self;
fn bundle(
&self,
other: &Self,
tie_breaker: TieBreaker,
rng: &mut impl Rng,
) -> Self;
fn bind(&self, other: &Self) -> Self;
fn cosine_similarity(&self, other: &Self) -> f32;
fn hamming_distance(&self, other: &Self) -> f32;
fn to_vec(&self) -> Vec<f32>;
// Provided methods
fn bundle_many(
vectors: &[Self],
tie_breaker: TieBreaker,
rng: &mut impl Rng,
) -> Self { ... }
fn bind_many(vectors: &[Self]) -> Self { ... }
}Expand description
The VSA trait defines the interface for a Vector Symbolic Architecture.
New VSA implementations (such as SSP, MBAT, or FHRR) can be added by implementing this trait.
§Associated Types
Elem- The type used to represent each element in the hypervector.
Required Associated Types§
Required Methods§
Sourcefn generate(dim: usize, rng: &mut impl Rng) -> Self
fn generate(dim: usize, rng: &mut impl Rng) -> Self
Generates a random hypervector of the given dimension.
§Arguments
dim- The dimensionality of the hypervector.rng- A mutable reference to a random number generator.
Sourcefn bundle(
&self,
other: &Self,
tie_breaker: TieBreaker,
rng: &mut impl Rng,
) -> Self
fn bundle( &self, other: &Self, tie_breaker: TieBreaker, rng: &mut impl Rng, ) -> Self
Bundles (superposes) two hypervectors.
For example, for MBAT this is typically implemented as the element-wise sum followed by a sign function with tie-breaking.
§Arguments
other- The hypervector to bundle with.tie_breaker- The rule to resolve ties.rng- A mutable reference to a random number generator.
Sourcefn bind(&self, other: &Self) -> Self
fn bind(&self, other: &Self) -> Self
Binds two hypervectors.
For MBAT, this is implemented as the element-wise product.
§Arguments
other- The hypervector to bind with.
Sourcefn cosine_similarity(&self, other: &Self) -> f32
fn cosine_similarity(&self, other: &Self) -> f32
Computes the cosine similarity between two hypervectors.
§Arguments
other- The hypervector to compare with.
Sourcefn hamming_distance(&self, other: &Self) -> f32
fn hamming_distance(&self, other: &Self) -> f32
Computes the normalized Hamming distance between two hypervectors.
§Arguments
other- The hypervector to compare with.
Provided Methods§
Sourcefn bundle_many(
vectors: &[Self],
tie_breaker: TieBreaker,
rng: &mut impl Rng,
) -> Self
fn bundle_many( vectors: &[Self], tie_breaker: TieBreaker, rng: &mut impl Rng, ) -> Self
Bundles many hypervectors (folding a slice using the bundling operation).
§Panics
Panics if vectors is empty.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.