Vector Spaces

Vector space definitions and operations.

holovec.spaces.create_space(space_type: str, dimension: int, backend: Backend | None = None, seed: int | None = None, **kwargs) DiscreteSpace | ContinuousSpace[source]

Factory function to create vector spaces.

Parameters:
  • space_type – One of ‘bipolar’, ‘binary’, ‘real’, ‘complex’, ‘sparse’

  • dimension – Dimensionality of vectors

  • backend – Computational backend

  • seed – Random seed

  • **kwargs – Space-specific arguments (e.g., sparsity for SparseSpace)

Returns:

Vector space instance

Examples

>>> space = create_space('bipolar', 10000)
>>> space = create_space('complex', 512)
>>> space = create_space('sparse', 10000, sparsity=0.01)
class holovec.spaces.VectorSpace(dimension: int, backend: Backend | None = None, seed: int | None = None)[source]

Bases: ABC

Abstract base class for vector spaces.

A vector space defines: - How random vectors are generated - What similarity metric is appropriate - How vectors are normalized - What algebraic operations are natural

Initialize vector space.

Parameters:
  • dimension – Dimensionality of vectors

  • backend – Computational backend to use (defaults to auto-detect)

  • seed – Random seed for reproducibility

__init__(dimension: int, backend: Backend | None = None, seed: int | None = None)[source]

Initialize vector space.

Parameters:
  • dimension – Dimensionality of vectors

  • backend – Computational backend to use (defaults to auto-detect)

  • seed – Random seed for reproducibility

abstractmethod random(seed: int | None = None) Any[source]

Generate a random vector in this space.

Parameters:

seed – Optional seed for this specific vector

Returns:

Random vector from the appropriate distribution

abstractmethod similarity(a: Any, b: Any) float[source]

Compute similarity between two vectors.

The similarity measure is space-specific: - Cosine similarity for real/complex spaces - Hamming distance for binary/bipolar spaces

Parameters:
  • a – First vector

  • b – Second vector

Returns:

Similarity score (higher means more similar)

abstractmethod normalize(vec: Any) Any[source]

Normalize a vector according to space conventions.

Parameters:

vec – Vector to normalize

Returns:

Normalized vector

abstract property dtype: str

Return the appropriate dtype for this space.

abstract property space_name: str

Return the name of this vector space.

See Also