BinaryHypervector¶
Binary hypervector with bipolar or binary encoding.
vsax.representations.BinaryHypervector
¶
Bases: AbstractHypervector
Binary hypervector with bipolar {-1, +1} or binary {0, 1} values.
BinaryHypervector represents hypervectors using discrete binary values. It supports two modes: - Bipolar: values in {-1, +1} (default, recommended) - Binary: values in {0, 1}
Binary hypervectors are efficient for hardware implementation and provide good performance with XOR binding and majority bundling operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vec
|
ndarray
|
JAX array containing binary values. |
required |
bipolar
|
bool
|
If True, expects {-1, +1} values. If False, expects {0, 1} values. |
True
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If vec contains values outside the expected binary set. |
Example
import jax.numpy as jnp vec = jnp.array([1, -1, 1, -1]) hv = BinaryHypervector(vec, bipolar=True) normalized = hv.normalize() # No-op for binary assert jnp.array_equal(normalized.vec, vec)
Source code in vsax/representations/binary_hv.py
8 9 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 | |
Attributes¶
bipolar
property
¶
Check if hypervector uses bipolar {-1, +1} encoding.
Returns:
| Type | Description |
|---|---|
bool
|
True if bipolar, False if binary {0, 1}. |
Functions¶
__init__(vec, bipolar=True)
¶
Initialize binary hypervector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vec
|
ndarray
|
JAX array with binary values. |
required |
bipolar
|
bool
|
If True, values should be {-1, +1}. If False, values should be {0, 1}. |
True
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If vec contains invalid values for the chosen mode. |
Source code in vsax/representations/binary_hv.py
normalize()
¶
No-op normalization for binary hypervectors.
Binary hypervectors are already in their normalized form.
Returns:
| Type | Description |
|---|---|
BinaryHypervector
|
A new BinaryHypervector with the same values. |
Example
import jax.numpy as jnp vec = jnp.array([1, -1, 1]) hv = BinaryHypervector(vec) normalized = hv.normalize() assert jnp.array_equal(normalized.vec, vec)
Source code in vsax/representations/binary_hv.py
to_bipolar()
¶
Convert to bipolar {-1, +1} representation.
Returns:
| Type | Description |
|---|---|
BinaryHypervector
|
New BinaryHypervector in bipolar form. |
Example
import jax.numpy as jnp vec = jnp.array([0, 1, 0, 1]) hv = BinaryHypervector(vec, bipolar=False) bipolar_hv = hv.to_bipolar() assert jnp.array_equal(bipolar_hv.vec, jnp.array([-1, 1, -1, 1]))
Source code in vsax/representations/binary_hv.py
to_binary()
¶
Convert to binary {0, 1} representation.
Returns:
| Type | Description |
|---|---|
BinaryHypervector
|
New BinaryHypervector in binary form. |
Example
import jax.numpy as jnp vec = jnp.array([-1, 1, -1, 1]) hv = BinaryHypervector(vec, bipolar=True) binary_hv = hv.to_binary() assert jnp.array_equal(binary_hv.vec, jnp.array([0, 1, 0, 1]))