pub struct TernaryMLP {
pub w1: TritMatrix,
pub w2: TritMatrix,
pub in_features: usize,
pub hidden_size: usize,
pub out_features: usize,
}Expand description
A 2-layer ternary multi-layer perceptron.
Architecture: input (in_features) → hidden (hidden_size) → output (out_features)
All weights are ternary {-1, 0, +1}. Forward pass uses sparse_matmul. No bias terms (ternary bias adds nothing that weight magnitude can’t cover).
Fields§
§w1: TritMatrix§w2: TritMatrix§in_features: usize§out_features: usizeImplementations§
Source§impl TernaryMLP
impl TernaryMLP
Sourcepub fn new(w1: TritMatrix, w2: TritMatrix) -> Self
pub fn new(w1: TritMatrix, w2: TritMatrix) -> Self
Construct from pre-quantized weight matrices.
Sourcepub fn from_f32(
in_features: usize,
hidden_size: usize,
out_features: usize,
w1_f32: &[f32],
w2_f32: &[f32],
) -> Self
pub fn from_f32( in_features: usize, hidden_size: usize, out_features: usize, w1_f32: &[f32], w2_f32: &[f32], ) -> Self
Initialise from f32 weight slices using BitNet threshold quantization.
Sourcepub fn forward(&self, input: &TritMatrix) -> (TritMatrix, usize, usize)
pub fn forward(&self, input: &TritMatrix) -> (TritMatrix, usize, usize)
Forward pass: input [1 × in_features] → output [1 × out_features].
Returns (output_row, layer1_skips, layer2_skips).
Sourcepub fn predict(&self, input: &TritMatrix) -> usize
pub fn predict(&self, input: &TritMatrix) -> usize
Classify a single input row: returns the column index of the max activated output (most +1, breaking ties by column index).
pub fn layer1_sparsity(&self) -> f64
pub fn layer2_sparsity(&self) -> f64
Auto Trait Implementations§
impl Freeze for TernaryMLP
impl RefUnwindSafe for TernaryMLP
impl Send for TernaryMLP
impl Sync for TernaryMLP
impl Unpin for TernaryMLP
impl UnsafeUnpin for TernaryMLP
impl UnwindSafe for TernaryMLP
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> 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