| Crates.io | hypervector |
| lib.rs | hypervector |
| version | 0.1.3 |
| created_at | 2025-02-08 20:18:13.878727+00 |
| updated_at | 2025-02-08 21:43:55.052055+00 |
| description | A crate that implements hyperdimensional vectors and VSAs. |
| homepage | |
| repository | https://github.com/rishikanthc/hypervector |
| max_upload_size | |
| id | 1548378 |
| size | 105,197 |
Hypervector is a Rust crate that implements hyperdimensional vectors for hyperdimensional computing and Vector Symbolic Architectures (VSAs). It provides multiple implementations including:
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.
set_global_seed.Add the following to your Cargo.toml:
[dependencies]
hypervector = "0.1.0"
Replace "0.1.0" with the current version if needed.
## Usage
Here is a basic example demonstrating how to generate a hypervector using the MBAT implementation and encode a JSON object:
```rust
use hypervector::{set_global_seed, Hypervector, TieBreaker};
use hypervector::mbat::MBAT;
use hypervector::encoder::ObjectEncoder;
use serde_json::json;
fn main() {
// Set the global RNG seed for reproducibility.
set_global_seed(42);
// Generate a random MBAT hypervector of dimension 1000.
let hv = Hypervector::<MBAT>::generate(1000);
println!("Generated MBAT hypervector: {:?}", hv);
// Create an object encoder for MBAT hypervectors.
let mut encoder = ObjectEncoder::<MBAT>::new(1000, TieBreaker::AlwaysPositive);
// Define a JSON object.
let json_obj = json!({
"firstName": "Alice",
"lastName": "Smith",
"isActive": true,
"hobbies": ["reading", "cycling"]
});
// Encode the JSON object into a hypervector.
let encoded = encoder.encode_object(&json_obj);
println!("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).
Full API documentation is available on docs.rs/hypervector.
Contributions are welcome! Please see CONTRIBUTING.md for details on how to get started.
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.