Hypervector
Hypervector is a Rust crate that implements hyperdimensional vectors for hyperdimensional computing and Vector Symbolic Architectures (VSAs). It provides multiple implementations including:
- MBAT: Bipolar vectors (elements in {-1, +1}).
- SSP: Semantic Spatial Pointers.
- FHRR: Fourier Holographic Reduced Representations.
The crate offers a generic hypervector type with high-level operations such as generation, bundling, binding, similarity checks, and conversion to a plain vector. It also provides an object encoder to map JSON objects into hypervector representations.
Features
- Multiple VSA Implementations: MBAT, SSP, and FHRR.
- Generic Hypervector API: Create, bundle, bind, and compare hypervectors.
- Object Encoder: Encode JSON objects into hypervectors using a codebook approach.
- Reproducible Randomness: Set a global RNG seed with
set_global_seed
. - Well-Documented and Tested: Comprehensive tests and inline documentation.
Installation
Add the following to your Cargo.toml
:
[]
= "0.1.0"
## Usage
```rust
{set_global_seed, Hypervector, TieBreaker};
mbat::MBAT;
encoder::ObjectEncoder;
json;
{
// Set the global RNG seed for reproducibility.
// Generate a random MBAT hypervector of dimension 1000.
= Hypervector::<MBAT>::generate(1000);
"Generated MBAT hypervector: {:?}", hv);
// Create an object encoder for MBAT hypervectors.
= ObjectEncoder::<MBAT>::new(1000, TieBreaker::AlwaysPositive);
// Define a JSON object.
= json!({
"Alice",
"Smith",
true,
["reading", "cycling"]
});
// Encode the JSON object into a hypervector.
= encoder.encode_object(&json_obj);
"Encoded JSON object: {:?}", encoded);
}
You can also use SSP or FHRR by importing the corresponding modules (e.g. hypervector::ssp::SSP or hypervector::fhrr::FHRR).
Documentation
Full API documentation is available on docs.rs/hypervector.
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for details on how to get started.
License
This project is licensed under either the MIT license or the Apache License (Version 2.0), at your option. See the LICENSE file for details.