pub struct EmlModel { /* private fields */ }Expand description
Multi-head EML model for O(1) function approximation.
§Architecture
The model uses a shared trunk of EML operators that feeds into multiple output heads. Each head produces one scalar prediction.
Level 0: 8 affine combinations of input features (24 params)
Level 1: 4 EML nodes (no params — pure EML pairing)
Level 2: mixing + EML (depth-dependent params)
...
Level D: multi-head output (2 params per head)Supported depths: 2, 3, 4, 5.
§Training
Training uses gradient-free random restart + coordinate descent,
suitable for the modest parameter counts (typically 30-80 params).
Call [record] to accumulate training data, then [train] to
optimize parameters.
Implementations§
Source§impl EmlModel
impl EmlModel
Sourcepub fn param_count(&self) -> usize
pub fn param_count(&self) -> usize
Total number of trainable parameters.
Sourcepub fn params_slice(&self) -> &[f64]
pub fn params_slice(&self) -> &[f64]
Read-only view of the trainable parameters.
Intended for composed models (e.g., [crate::ToyEmlAttention]) that
need to run coordinate descent over the union of several EmlModels’
parameters. Prefer Self::train for single-model training.
Sourcepub fn params_slice_mut(&mut self) -> &mut [f64]
pub fn params_slice_mut(&mut self) -> &mut [f64]
Mutable view of the trainable parameters.
Intended for composed models running joint coordinate descent. Callers are responsible for restoring parameters they perturb if a candidate is rejected.
Sourcepub fn mark_trained(&mut self, trained: bool)
pub fn mark_trained(&mut self, trained: bool)
Mark the model as trained (or not). Used by composed models after joint coordinate descent converges.
Sourcepub fn is_trained(&self) -> bool
pub fn is_trained(&self) -> bool
Whether the model has been trained to convergence.
Sourcepub fn training_sample_count(&self) -> usize
pub fn training_sample_count(&self) -> usize
Number of training samples collected so far.
Sourcepub fn input_count(&self) -> usize
pub fn input_count(&self) -> usize
Number of input features.
Sourcepub fn head_count(&self) -> usize
pub fn head_count(&self) -> usize
Number of output heads.
Sourcepub fn set_model_name(&mut self, name: impl Into<String>)
pub fn set_model_name(&mut self, name: impl Into<String>)
Set the model name used in emitted events.
Should be called once by the domain-specific wrapper after creation.
Sourcepub fn model_name(&self) -> &str
pub fn model_name(&self) -> &str
Get the model name.
Sourcepub fn drain_events(&mut self) -> Vec<EmlEvent>
pub fn drain_events(&mut self) -> Vec<EmlEvent>
Drain all accumulated lifecycle events, returning them.
The caller is responsible for forwarding these to the ExoChain or other audit sinks.
Sourcepub fn push_event(&mut self, event: EmlEvent)
pub fn push_event(&mut self, event: EmlEvent)
Push a custom event into the event log.
Sourcepub fn pending_event_count(&self) -> usize
pub fn pending_event_count(&self) -> usize
Number of pending (undrained) events.
Sourcepub fn predict(&self, inputs: &[f64]) -> Vec<f64>
pub fn predict(&self, inputs: &[f64]) -> Vec<f64>
Predict all heads from input features.
Returns a Vec with one f64 per head. Values are clamped to be non-negative.
Sourcepub fn predict_primary(&self, inputs: &[f64]) -> f64
pub fn predict_primary(&self, inputs: &[f64]) -> f64
Predict only the primary (first) head.
Sourcepub fn record(&mut self, inputs: &[f64], targets: &[Option<f64>])
pub fn record(&mut self, inputs: &[f64], targets: &[Option<f64>])
Record a training sample.
§Arguments
inputs: Input feature values.targets: Target values for each head. UseNonefor heads without ground truth in this sample (they are skipped in the loss function).
Sourcepub fn train(&mut self) -> bool
pub fn train(&mut self) -> bool
Train the model using random restart + coordinate descent.
Requires at least 50 training samples. Returns true if the
model converged (MSE < 0.01).
Sourcepub fn distill(&self, target_depth: usize, num_samples: usize) -> EmlModel
pub fn distill(&self, target_depth: usize, num_samples: usize) -> EmlModel
Distill this (teacher) model to a shallower student model.
Creates a new EmlModel with target_depth (must be less than
the teacher’s depth) and trains it to mimic the teacher’s outputs
on num_samples synthetic inputs drawn uniformly from [0, 1].
The student learns from the teacher’s predictions, not from the original training data. This preserves accuracy while reducing computation for constrained devices (WASM, ESP32).
§Panics
Panics if target_depth >= self.depth or target_depth is not
in {2, 3, 4, 5}.