Skip to main content

HyperVec

Struct HyperVec 

Source
pub struct HyperVec {
    pub config: DimensionalConfig,
    pub dimensions: BTreeMap<usize, Tryte>,
}
Expand description

A hyperdimensional vector with configurable dimensional depth

Fields§

§config: DimensionalConfig

Configuration for this vector

§dimensions: BTreeMap<usize, Tryte>

Sparse storage: dimension index -> tryte value Only non-zero dimensions are stored

Implementations§

Source§

impl HyperVec

Source

pub fn new(config: DimensionalConfig) -> Self

Create a new zero vector

Source

pub fn from_dense(config: DimensionalConfig, values: &[i64]) -> Self

Create from dense representation

Source

pub fn get(&self, dim: usize) -> i64

Get value at dimension (returns 0 for unset dimensions)

Source

pub fn set(&mut self, dim: usize, value: i64)

Set value at dimension

Source

pub fn nnz(&self) -> usize

Number of non-zero dimensions (sparsity count)

Source

pub fn sparsity(&self) -> f64

Current sparsity ratio

Source

pub fn bundle(&self, other: &HyperVec) -> HyperVec

Bundle operation (⊕): Superposition via majority voting

Algebraic properties:

  • Associative: (A ⊕ B) ⊕ C = A ⊕ (B ⊕ C)
  • Commutative: A ⊕ B = B ⊕ A
  • Preserves similarity to inputs
Source

pub fn bind(&self, other: &HyperVec) -> HyperVec

Bind operation (⊙): Composition via trit-wise multiplication

Algebraic properties:

  • Self-inverse: A ⊙ A ≈ I (identity, up to sparsity)
  • Distributes over bundle: A ⊙ (B ⊕ C) = (A ⊙ B) ⊕ (A ⊙ C)
  • Creates quasi-orthogonal result
Source

pub fn permute(&self, shift: usize) -> HyperVec

Permute operation (ρ): Cyclic index shift for sequence encoding

Algebraic properties:

  • ρ^n(A) cycles through orthogonal representations
  • Preserves sparsity and magnitude
  • Enables positional encoding
Source

pub fn inverse_permute(&self, shift: usize) -> HyperVec

Inverse permute (ρ⁻¹): Reverse cyclic shift

Source

pub fn cosine(&self, other: &HyperVec) -> f64

Cosine similarity: Normalized dot product

Returns value in [-1, 1]:

  • 1.0: Identical vectors
  • 0.0: Orthogonal vectors
  • -1.0: Opposite vectors
Source

pub fn thin(&self, target_nnz: usize) -> HyperVec

Thin to target sparsity (Context-Dependent Thinning)

Reduces vector density while preserving signal structure

Source

pub fn expand_precision(&mut self, dim: usize, new_depth: u8)

Expand precision at specific dimension (adaptive depth)

Source

pub fn pack(&self) -> Vec<u8>

Pack to bytes for storage/transmission

Source

pub fn unpack(config: DimensionalConfig, bytes: &[u8]) -> Option<Self>

Unpack from bytes

Trait Implementations§

Source§

impl Clone for HyperVec

Source§

fn clone(&self) -> HyperVec

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HyperVec

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for HyperVec

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for HyperVec

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,