pub struct SparseTsetlinMachine { /* private fields */ }Expand description
Sparse Tsetlin Machine for memory-efficient inference.
Inference-only model with 5-100x memory reduction compared to dense
TsetlinMachine. Create via TsetlinMachine::to_sparse() after training.
§Example
use tsetlin_rs::{Config, TsetlinMachine};
let config = Config::builder().clauses(20).features(2).build().unwrap();
let mut tm = TsetlinMachine::new(config, 10);
let x = vec![vec![0, 0], vec![0, 1], vec![1, 0], vec![1, 1]];
let y = vec![0, 1, 1, 0];
tm.fit(&x, &y, 200, 42);
// Convert to sparse for deployment
let sparse = tm.to_sparse();
// Same predictions, less memory
assert_eq!(tm.predict(&x[0]), sparse.predict(&x[0]));Implementations§
Source§impl SparseTsetlinMachine
impl SparseTsetlinMachine
Sourcepub fn from_clauses(
clauses: &[Clause],
n_features: usize,
threshold: f32,
) -> Self
pub fn from_clauses( clauses: &[Clause], n_features: usize, threshold: f32, ) -> Self
Creates from dense clauses.
§Arguments
clauses- Dense clauses to convertn_features- Number of featuresthreshold- Classification threshold
Sourcepub fn new(clauses: SparseClauseBank, threshold: f32) -> Self
pub fn new(clauses: SparseClauseBank, threshold: f32) -> Self
Creates from pre-built sparse clause bank.
Sourcepub const fn n_features(&self) -> usize
pub const fn n_features(&self) -> usize
Returns number of features.
Sourcepub fn predict_packed(&self, x: &[u64]) -> u8
pub fn predict_packed(&self, x: &[u64]) -> u8
Predicts using packed u64 input.
Sourcepub fn memory_stats(&self) -> SparseMemoryStats
pub fn memory_stats(&self) -> SparseMemoryStats
Returns memory statistics.
Sourcepub fn compression_ratio(&self) -> f32
pub fn compression_ratio(&self) -> f32
Returns compression ratio compared to dense model.
Trait Implementations§
Source§impl Clone for SparseTsetlinMachine
impl Clone for SparseTsetlinMachine
Source§fn clone(&self) -> SparseTsetlinMachine
fn clone(&self) -> SparseTsetlinMachine
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 SparseTsetlinMachine
impl RefUnwindSafe for SparseTsetlinMachine
impl Send for SparseTsetlinMachine
impl Sync for SparseTsetlinMachine
impl Unpin for SparseTsetlinMachine
impl UnwindSafe for SparseTsetlinMachine
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