Trait VSA

Source
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§

Source

type Elem: Copy + Debug + PartialEq + Into<f32>

The type used to represent each element in the hypervector.

Required Methods§

Source

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.
Source

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.
Source

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.
Source

fn cosine_similarity(&self, other: &Self) -> f32

Computes the cosine similarity between two hypervectors.

§Arguments
  • other - The hypervector to compare with.
Source

fn hamming_distance(&self, other: &Self) -> f32

Computes the normalized Hamming distance between two hypervectors.

§Arguments
  • other - The hypervector to compare with.
Source

fn to_vec(&self) -> Vec<f32>

Converts the hypervector into a plain Vec<f32>.

Provided Methods§

Source

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.

Source

fn bind_many(vectors: &[Self]) -> Self

Binds many hypervectors (folding a slice using the binding 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.

Implementors§