neural_engine library

Pure Dart neural models with explicit contracts and composable training.

Classes

Adam
Adam with bias-corrected first and second moments.
AsyncTrainingRequest
Immutable worker input. Models, optimizer state and datasets are copied; workers never mutate the caller's model. Use the result checkpoint to restore.
AsyncTrainingResult
A resumable snapshot, including optimizer moments and absolute shuffle seed.
AsyncTrainingTask
An owned worker lifecycle: subscribe immediately, await result, cancel safely. Cancelling a progress subscription does not cancel training; call cancel.
BinaryCrossEntropy
Binary cross entropy over probabilities; use with a sigmoid output. Training fuses sigmoid + BCE in logit space for numerical stability.
CategoricalCrossEntropy
Categorical cross entropy for softmax outputs and distributions summing to 1. Training fuses softmax + CCE using log-sum-exp.
CellCache
Per-step cache is supplied by the cell, never stored as cross-call model state.
CheckpointOptimizer
Optional extension: serializable configuration and explicit state restoration. Custom optimizers can supply their own checkpoint decoder to TrainingSession.
CheckpointOptimizerState
ClassificationMetrics
Confusion rows are targets, columns predictions. Undefined ratios are zero.
Conv2D
Trainable 2D cross-correlation (the convention used by CNN libraries).
ConvolutionalNetwork
A stack of Conv2D/MaxPool2D layers, implicit Flatten and a dense head. Backpropagation trains convolution kernels and the dense head together.
Dense
Immutable specification; weights belong to each network, not this object.
DifferentiableModel<I>
A supervised model usable by a trainer independently of its input shape.
EvaluationProgress
Evaluation progress is separate from committed-epoch TrainingProgress. Partial chunks do not report an averaged loss; only a complete dataset does.
FeatureTransform
A fitted, immutable transform. Fit on training data only.
GruCell
Reset-before GRU: n=tanh(Wx+U(r*h)); h=(1-z)n+zh_previous. Gate order: update, reset, candidate. Not Keras reset-after weight compatible.
ImageTensor
Immutable height × width × channels tensor, flattened in HWC order.
JsonModel
A versioned JSON-compatible inference model. IO belongs to applications.
Loss
Loss extension point. Gradients are with respect to predicted outputs.
LstmCell
LSTM without peepholes. Gate order: input, forget, output, candidate.
MaxPool2D
Nontrainable valid max pooling per channel; ties route to first HWC position.
MeanSquaredError
Mean squared error, averaged over output coordinates.
MiniBatchTrainer<I>
Shared supervised training lifecycle; model math stays in model executors.
MinMaxScaler
Maps training min/max to 0/1 without clipping held-out values.
NeuralNetwork
Dense feedforward facade. Training uses the same trainer as CNN/recurrent models.
Optimizer
An optimizer configuration creates isolated state for each fit invocation.
OptimizerCodec
Built-in optimizer configuration dispatch; custom loaders stay application-owned.
OptimizerState
Updates a flat parameter vector once per mini-batch.
ParameterizedModel
Flat, finite parameter snapshots; setters must copy and validate input.
Predictor<I>
Stateless inference boundary: each call returns an independent output.
RecurrentCell
A differentiable recurrent transition; owns weights, not inference sessions.
RecurrentDerivatives
RecurrentNetwork
Many-to-one recurrent model with a dense projection of the final hidden state. Each sequence starts at zero state; full BPTT, no truncation or padding/masks.
RecurrentState
Immutable state; memory is the LSTM cell state (zero for RNN/GRU).
RecurrentStep
RegressionMetrics
Scalar metrics; flatten coordinates first to report reconstruction errors.
SampleLossModel<I>
Optional incremental-evaluation contract. Dataset loss must be the arithmetic mean of these finite per-sample losses, added in input order, divided once. Models with a different reduction should keep their existing evaluate method.
SelfOrganizingMap
Kohonen self-organizing map with Euclidean BMU and Gaussian neighborhood. Initialize with unit-range weights; scale each input feature before training.
SGD
Stochastic (or mini-batch) gradient descent without momentum.
SimpleRnnCell
Elman tanh cell: h = tanh(Wx + Uh_previous + b).
SomHistory
Immutable post-epoch average Euclidean quantization errors.
SomMatch
Best matching unit on a rectangular, non-toroidal SOM grid.
SpatialLayer
Spatial feature extractor specification; flattening before Dense is implicit.
StandardScaler
Population mean/std fitted with Welford's algorithm; constant scales are 1.
TrainingCancellation
Cooperative cancellation, committed at the next complete epoch boundary.
TrainingCheckpoint
Snapshot of a fixed-epoch training session. Dataset/loss remain caller-owned. JSON getters return deep copies; no live weights/moments are shared.
TrainingHistory
Immutable losses measured after each completed epoch.
TrainingProgress
Measurements after a complete epoch. Epoch counts are absolute (resume-safe).
TrainingSession<I>
Retains optimizer state across fixed-epoch fits, using absolute-epoch shuffles. Restore with the same data order, loss, batch size and clipping for exact replay. Built-in early stopping is intentionally handled by ordinary model.fit instead.
TrainingStep
UnsupervisedModel<I>
Quality evaluation without labels; SOM uses mean BMU distance.

Enums

Activation
Built-in dense layer activation functions.
ConvolutionPadding
Same uses zero padding, with extra padding at bottom/right for odd totals.
RecurrentKind
TrainingExecution
Automatic selects an isolate on native Dart and cooperative batches on web.
TrainingLoss
Serializable built-in loss for a portable worker. Custom losses use fitAsync.
TrainingPhase
Explicit safe scheduling units of the common numerical executor.

Exceptions / Errors

TrainingWorkerException
Worker failures carry a remote message and stack; they produce no checkpoint.