FHRROperations¶
FFT-based operations for complex hypervectors.
vsax.ops.FHRROperations
¶
Bases: AbstractOpSet
FHRR operations using FFT-based circular convolution.
Fourier Holographic Reduced Representation (FHRR) uses circular convolution for binding and complex addition for bundling. These operations work best with complex-valued hypervectors.
Binding is implemented via circular convolution in the frequency domain
bind(a, b) = IFFT(FFT(a) ⊙ FFT(b))
where ⊙ denotes element-wise multiplication.
Example
import jax import jax.numpy as jnp from vsax.representations import ComplexHypervector
ops = FHRROperations() key = jax.random.PRNGKey(0) a = jnp.exp(1j * jax.random.uniform(key, (512,), minval=0, maxval=2jnp.pi)) b = jnp.exp(1j * jax.random.uniform(key, (512,), minval=0, maxval=2jnp.pi))
bound = ops.bind(a, b) assert bound.shape == a.shape
Source code in vsax/ops/fhrr.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 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 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
Functions¶
bind(a, b)
¶
Bind two hypervectors using circular convolution.
Implemented via FFT: IFFT(FFT(a) * FFT(b))
This operation is: - Commutative: bind(a, b) = bind(b, a) - Associative: bind(a, bind(b, c)) = bind(bind(a, b), c) - Invertible: bind(bind(a, b), inverse(b)) ≈ a
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. |
Example
import jax.numpy as jnp ops = FHRROperations() a = jnp.exp(1j * jnp.array([0.5, 1.0, 1.5])) b = jnp.exp(1j * jnp.array([0.3, 0.7, 1.1])) result = ops.bind(a, b) assert jnp.iscomplexobj(result)
Source code in vsax/ops/fhrr.py
bundle(*vecs)
¶
Bundle multiple hypervectors using complex addition and normalization.
The bundled vector is similar to all input vectors and can be queried to retrieve the constituents.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*vecs
|
ndarray
|
Variable number of hypervectors as JAX arrays. |
()
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Bundled hypervector as JAX array, normalized to unit magnitude. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no vectors are provided. |
Example
import jax.numpy as jnp ops = FHRROperations() a = jnp.exp(1j * jnp.array([0.0, 0.5, 1.0])) b = jnp.exp(1j * jnp.array([0.3, 0.7, 1.1])) c = jnp.exp(1j * jnp.array([0.6, 0.9, 1.3])) result = ops.bundle(a, b, c) assert jnp.allclose(jnp.abs(result), 1.0, atol=0.1)
Source code in vsax/ops/fhrr.py
inverse(a)
¶
Compute the inverse for unbinding.
For circular convolution (FHRR), the inverse requires: - Complex vectors: inv(a) = ifft(conj(fft(a)) / (|fft(a)|² + ε)) - Real vectors: inv(a) = reversed vector (time-domain equivalent)
This ensures that bind(bind(x, a), inverse(a)) ≈ x with high accuracy.
The division by |fft(a)|² is essential for proper deconvolution. For unit-magnitude vectors in frequency domain (proper FHRR vectors), this reduces to approximately conj(fft(a)), but for general complex vectors, the normalization is necessary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
ndarray
|
Hypervector as JAX array. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Inverse hypervector as JAX array. |
Example
import jax.numpy as jnp from vsax.similarity import cosine_similarity ops = FHRROperations() a = jnp.exp(1j * jnp.array([0.5, 1.0, 1.5])) x = jnp.exp(1j * jnp.array([0.3, 0.7, 1.1])) inv_a = ops.inverse(a) bound = ops.bind(x, a) recovered = ops.bind(bound, inv_a)
recovered should be very similar to x (>99% similarity)¶
Source code in vsax/ops/fhrr.py
unbind(a, b)
¶
Unbind b from a using circular deconvolution.
Implements unbinding via FFT-based circular deconvolution
unbind(a, b) = ifft(fft(a) * conj(fft(b)) / (|fft(b)|² + ε))
This is equivalent to bind(a, inverse(b)) but more efficient as it performs only one FFT round-trip instead of two.
if c = a ⊛ b, then to recover a we need:
a = ifft(fft(c) * conj(fft(b)) / |fft(b)|²)
where ⊛ denotes circular convolution.
The division by |fft(b)|² is essential for proper deconvolution. A small epsilon (1e-10) is added for numerical stability.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
ndarray
|
Bound hypervector as JAX array. |
required |
b
|
ndarray
|
Hypervector to unbind as JAX array. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Recovered hypervector as JAX array. |
Example
import jax.numpy as jnp from vsax.similarity import cosine_similarity 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]))
Bind and unbind¶
bound = ops.bind(x, y) recovered = ops.unbind(bound, y)
Should recover x with high similarity¶
similarity = cosine_similarity(x, recovered)
similarity > 0.99 with corrected inverse¶
Source code in vsax/ops/fhrr.py
fractional_power(a, exponent)
¶
Raise complex hypervector to fractional power.
For complex vectors v = exp(iθ), this computes v^r = exp(ir*θ). This enables continuous encoding of scalar values using phase rotation.
Properties
- Continuous: small changes in exponent produce small output changes
- Compositional: (v^r1)^r2 = v^(r1*r2)
- Invertible: v^r ⊗ v^(-r) = identity
This operation is fundamental for
- Fractional Power Encoding (FPE)
- Spatial Semantic Pointers (SSP)
- Vector Function Architecture (VFA)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
ndarray
|
Complex hypervector as JAX array. |
required |
exponent
|
Union[float, ndarray]
|
Scalar or array of exponents to raise the vector to. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Hypervector raised to the given power as JAX array. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If input array is not complex-valued. |
Example
import jax.numpy as jnp ops = FHRROperations()
Create a unit complex vector¶
a = jnp.exp(1j * jnp.array([0.5, 1.0, 1.5]))
Raise to fractional power¶
powered = ops.fractional_power(a, 0.5)
Test compositionality: (a^0.5)^2 ≈ a¶
composed = ops.fractional_power(powered, 2.0) assert jnp.allclose(composed, a, atol=1e-6)
Source code in vsax/ops/fhrr.py
permute(a, shift)
¶
Permute a hypervector by circular rotation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
ndarray
|
Hypervector as JAX array. |
required |
shift
|
int
|
Number of positions to rotate (positive = right, negative = left). |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Permuted hypervector as JAX array. |
Example
import jax.numpy as jnp ops = FHRROperations() a = jnp.array([1, 2, 3, 4, 5]) rotated = ops.permute(a, 2) assert jnp.array_equal(rotated, jnp.array([4, 5, 1, 2, 3]))