pub struct SparseProjection { /* private fields */ }Expand description
Sparse random projection matrix for dimensionality expansion
Uses a sparse random matrix to project low-dimensional inputs into high-dimensional space while maintaining computational efficiency.
§Properties
- Sparse connectivity (typically 10-20% connections)
- Gaussian-distributed weights
- Deterministic (seeded) for reproducibility
§Performance
- Time complexity: O(input_dim × output_dim × sparsity)
- Space complexity: O(input_dim × output_dim)
Implementations§
Source§impl SparseProjection
impl SparseProjection
Sourcepub fn new(
input_dim: usize,
output_dim: usize,
sparsity: f32,
seed: u64,
) -> Result<Self>
pub fn new( input_dim: usize, output_dim: usize, sparsity: f32, seed: u64, ) -> Result<Self>
Create a new sparse random projection
§Arguments
input_dim- Input vector dimensionoutput_dim- Output vector dimension (should be >> input_dim)sparsity- Connection probability (typically 0.1-0.2)seed- Random seed for reproducibility
§Example
use ruvector_nervous_system::SparseProjection;
let projection = SparseProjection::new(128, 10000, 0.15, 42);Sourcepub fn project(&self, input: &[f32]) -> Result<Vec<f32>>
pub fn project(&self, input: &[f32]) -> Result<Vec<f32>>
Project input vector to high-dimensional space
§Arguments
input- Input vector of size input_dim
§Returns
Output vector of size output_dim
§Example
use ruvector_nervous_system::SparseProjection;
let projection = SparseProjection::new(128, 10000, 0.15, 42).unwrap();
let input = vec![1.0; 128];
let output = projection.project(&input).unwrap();
assert_eq!(output.len(), 10000);Sourcepub fn output_dim(&self) -> usize
pub fn output_dim(&self) -> usize
Get output dimension
Trait Implementations§
Source§impl Clone for SparseProjection
impl Clone for SparseProjection
Source§fn clone(&self) -> SparseProjection
fn clone(&self) -> SparseProjection
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for SparseProjection
impl RefUnwindSafe for SparseProjection
impl Send for SparseProjection
impl Sync for SparseProjection
impl Unpin for SparseProjection
impl UnwindSafe for SparseProjection
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more