Skip to main content

Crate tsetlin_rs

Crate tsetlin_rs 

Source
Expand description

§Tsetlin Machine

A professional Rust implementation of the Tsetlin Machine algorithm for interpretable machine learning.

§Models

§Clause Types

TypeHeapBest For
ClauseYesDynamic dimensions, serde
SmallClauseNoN ≤ 64, maximum speed
BitwiseClauseYesN ≥ 64, 25-92x speedup
SmallBitwiseClauseNo64-256 features, no heap
SparseClauseInlineInference, 5-100x compression
SparseClauseBankYesCSR batch inference

§Advanced Features

  • Weighted Clauses - Clauses learn weights based on accuracy
  • Adaptive Threshold - Dynamic T adjustment during training
  • Clause Pruning - Automatic reset of dead/ineffective clauses
  • Const Generics - Zero-allocation stack types with loop unrolling
  • Lock-Free Parallel Training - Async local voting tallies (ICML 2021)

§Feature Flags

  • std (default): Standard library support
  • simd: SIMD-optimized evaluation (requires nightly)
  • parallel: Parallel training via rayon
  • serde: Serialization support

§Quick Start

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);
assert!(tm.evaluate(&x, &y) >= 0.75);

Re-exports§

pub use error::Error;
pub use error::Result;

Modules§

error
Error types for Tsetlin Machine.
feedback
Type I and Type II feedback mechanisms.
utils
Utility functions for random number generation and helpers.

Structs§

AdvancedOptions
Overview
Automaton
Overview
BitPlaneBank
Bit-plane storage for automata states.
BitwiseClause
Overview
Clause
A clause with 2*n_features automata, weight, and activation tracking.
ClauseBank
Structure of Arrays storage for Tsetlin Machine clauses.
ClauseFilter
Bloom filter for fast clause rejection.
ClauseFilterStats
Statistics about a clause filter.
Config
Overview
ConfigBuilder
Overview
ConvConfig
Overview
Convolutional
Overview
EarlyStop
Early stopping configuration.
FitOptions
Options for training a Tsetlin Machine.
FitResult
Result of training.
MultiClass
Multi-class Tsetlin Machine using one-vs-all strategy.
Regressor
Overview
Rule
Overview
SmallBitwiseClause
Bitwise clause with compile-time known feature count.
SmallClause
A clause with compile-time known feature count.
SmallTsetlinMachine
Binary classification Tsetlin Machine with compile-time known dimensions.
SparseClause
Sparse clause representation storing only active literal indices.
SparseClauseBank
Sparse clause bank using CSR (Compressed Sparse Row) format.
SparseMemoryStats
Memory usage breakdown for sparse clause bank.
SparseTsetlinMachine
Sparse Tsetlin Machine for memory-efficient inference.
TsetlinMachine
Overview

Traits§

TsetlinModel
Unified interface for all Tsetlin Machine variants.
VotingModel
Extension trait for models with vote-based predictions.

Functions§

pack_batch
Overview
pack_input
Overview
pack_input_small
Packs binary input into u64 array for bitwise evaluation.

Type Aliases§

BitwiseClause64
Bitwise clause for 64 features (1 u64 word).
BitwiseClause128
Bitwise clause for 128 features (2 u64 words).
BitwiseClause256
Bitwise clause for 256 features (4 u64 words).
Clause2
Type alias for 2-feature clause.
Clause4
Type alias for 4-feature clause (XOR problems).
Clause8
Type alias for 8-feature clause.
Clause16
Type alias for 16-feature clause.
Clause32
Type alias for 32-feature clause.
Clause64
Type alias for 64-feature clause.
TM2x20
2-feature, 20-clause machine (XOR).
TM4x40
4-feature, 40-clause machine.
TM8x80
8-feature, 80-clause machine.
TM16x160
16-feature, 160-clause machine.