pub struct SmallTsetlinMachine<const N: usize, const C: usize> { /* private fields */ }Expand description
Binary classification Tsetlin Machine with compile-time known dimensions.
Stack-allocated with zero heap allocations. All loops unrolled at compile time.
§Type Parameters
N- Number of features (compile-time constant)C- Number of clauses (compile-time constant, must be even)
§Performance
Up to 3x faster than dynamic TsetlinMachine
for small dimensions due to:
- No heap allocations
- Full loop unrolling
- Better cache locality
§Example
use tsetlin_rs::SmallTsetlinMachine;
// XOR with 2 features and 20 clauses
let mut tm: SmallTsetlinMachine<2, 20> = SmallTsetlinMachine::new(100, 15);
let x = [[0, 0], [0, 1], [1, 0], [1, 1]];
let y = [0u8, 1, 1, 0];
tm.fit(&x, &y, 200, 42);
assert!(tm.evaluate(&x, &y) >= 0.75);Implementations§
Source§impl<const N: usize, const C: usize> SmallTsetlinMachine<N, C>
impl<const N: usize, const C: usize> SmallTsetlinMachine<N, C>
Sourcepub fn new(n_states: i16, threshold: i32) -> Self
pub fn new(n_states: i16, threshold: i32) -> Self
Creates new machine with given states and threshold.
Half clauses get +1 polarity, half get -1.
§Panics
Debug-asserts that C is even.
Sourcepub fn with_s(n_states: i16, threshold: i32, s: f32) -> Self
pub fn with_s(n_states: i16, threshold: i32, s: f32) -> Self
Creates machine with custom specificity parameter.
Sourcepub const fn n_features(&self) -> usize
pub const fn n_features(&self) -> usize
Returns the number of features (compile-time constant).
Sourcepub const fn clauses(&self) -> &[SmallClause<N>; C]
pub const fn clauses(&self) -> &[SmallClause<N>; C]
Returns read-only access to clauses.
Trait Implementations§
Source§impl<const N: usize, const C: usize> Clone for SmallTsetlinMachine<N, C>
impl<const N: usize, const C: usize> Clone for SmallTsetlinMachine<N, C>
Source§fn clone(&self) -> SmallTsetlinMachine<N, C>
fn clone(&self) -> SmallTsetlinMachine<N, C>
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<const N: usize, const C: usize> Freeze for SmallTsetlinMachine<N, C>
impl<const N: usize, const C: usize> RefUnwindSafe for SmallTsetlinMachine<N, C>
impl<const N: usize, const C: usize> Send for SmallTsetlinMachine<N, C>
impl<const N: usize, const C: usize> Sync for SmallTsetlinMachine<N, C>
impl<const N: usize, const C: usize> Unpin for SmallTsetlinMachine<N, C>
impl<const N: usize, const C: usize> UnwindSafe for SmallTsetlinMachine<N, C>
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