Base Classes¶
Core abstract classes that define the VSA interface.
AbstractHypervector¶
vsax.core.base.AbstractHypervector
¶
Bases: ABC
Base class for all hypervector representations.
Wraps a JAX array and provides common operations for hypervectors. All concrete implementations must inherit from this class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vec
|
ndarray
|
The underlying JAX array representing the hypervector. |
required |
Source code in vsax/core/base.py
Attributes¶
vec
property
¶
Return the underlying JAX array.
Returns:
| Type | Description |
|---|---|
ndarray
|
The JAX array wrapped by this hypervector. |
shape
property
¶
Return the shape of the hypervector.
Returns:
| Type | Description |
|---|---|
tuple[int, ...]
|
Tuple representing the shape of the underlying array. |
dtype
property
¶
Return the data type of the hypervector.
Returns:
| Type | Description |
|---|---|
dtype
|
JAX dtype of the underlying array. |
Functions¶
normalize()
abstractmethod
¶
Normalize the hypervector.
The normalization method depends on the representation type. For example, complex vectors normalize to unit magnitude (phase-only), while real vectors use L2 normalization.
Returns:
| Type | Description |
|---|---|
AbstractHypervector
|
Normalized hypervector of the same type. |
Source code in vsax/core/base.py
to_numpy()
¶
Convert the hypervector to a NumPy array.
Returns:
| Type | Description |
|---|---|
ndarray
|
NumPy array representation of the hypervector. |
AbstractOpSet¶
vsax.core.base.AbstractOpSet
¶
Bases: ABC
Base class for VSA operation sets.
Defines the symbolic algebra operations for binding and bundling hypervectors. All operations work directly on JAX arrays, not on AbstractHypervector instances.
Concrete implementations (FHRR, MAP, Binary) must implement all abstract methods.
Source code in vsax/core/base.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
Functions¶
bind(a, b)
abstractmethod
¶
Bind two hypervectors together.
Binding creates a composite representation that is dissimilar to both inputs but can be unbound using the inverse operation. The specific binding operation depends on the algebra (e.g., circular convolution for FHRR, elementwise multiplication for MAP).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
ndarray
|
First hypervector as JAX array. |
required |
b
|
ndarray
|
Second hypervector as JAX array. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Bound hypervector as JAX array. |
Source code in vsax/core/base.py
bundle(*vecs)
abstractmethod
¶
Bundle multiple hypervectors into a single representation.
Bundling creates a superposition that is similar to all inputs. The bundled vector can be queried to retrieve the constituent vectors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*vecs
|
ndarray
|
Variable number of hypervectors as JAX arrays. |
()
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Bundled hypervector as JAX array. |
Source code in vsax/core/base.py
inverse(a)
abstractmethod
¶
Compute the inverse of a hypervector.
The inverse is used to unbind: if c = bind(a, b), then unbind(c, b) = bind(c, inverse(b)) ≈ a.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
ndarray
|
Hypervector as JAX array. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Inverse hypervector as JAX array. |
Source code in vsax/core/base.py
unbind(a, b)
¶
Unbind b from a to recover the original vector.
If c = bind(a, b), then unbind(c, b) ≈ a.
This provides an explicit, intuitive interface for unbinding operations. The default implementation uses: bind(a, inverse(b))
Concrete operation sets may override this for efficiency or to provide specialized unbinding behavior.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
ndarray
|
Bound hypervector (result of bind operation). |
required |
b
|
ndarray
|
Hypervector to unbind. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Recovered hypervector as JAX array. |
Example
import jax.numpy as jnp from vsax.ops import FHRROperations ops = FHRROperations() x = jnp.exp(1j * jnp.array([0.5, 1.0, 1.5])) y = jnp.exp(1j * jnp.array([0.3, 0.7, 1.1])) bound = ops.bind(x, y) recovered = ops.unbind(bound, y)
recovered ≈ x (with high similarity)¶
Source code in vsax/core/base.py
permute(a, shift)
¶
Permute a hypervector by circular shift.
This is an optional operation. The default implementation performs a circular shift, but concrete classes may override with different permutation strategies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
ndarray
|
Hypervector as JAX array. |
required |
shift
|
int
|
Number of positions to shift (positive = right, negative = left). |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Permuted hypervector as JAX array. |