Skip to content
Antonino Calderone edited this page Aug 7, 2026 · 2 revisions

Implementation Map

Use this page when moving from a concept to the code. Each row links the public contract, implementation, focused test, and smallest relevant example. Header-only templates show “header” in place of a separate source file.

Core training primitives

Topic Public contract / implementation Tests or use
numeric vector nu_vector.h · nu_vector.cc test_vector.cc
activations nu_activation.h test_mlpnn_activations.cc
cost functions nu_costfuncs.h · nu_costfuncs.cc test_costfuncs.cc
generic epoch trainer nu_trainer.h test_trainer.cc
neuron state nu_neuron.h used by Perceptron and MlpNN

The smallest complete read is: activation and vector helpers, Perceptron::feedForward(), Perceptron::backPropagate(), its test, then and_test.

Feedforward networks

Model Header Implementation Tests Example
Perceptron nu_perceptron.h nu_perceptron.cc test_perceptron.cc and_test.cc
MlpNN nu_mlpnn.h nu_mlpnn.cc test_mlpnn.cc xor_test.cc
MlpMatrixNN nu_mlpmatrixnn.h nu_mlpmatrixnn.cc test_mlpmatrixnn.cc mnist_test.cc
base model abstraction nu_nn_model.h nu_nn_model.cc persistence tests above model loaders

To compare the two MLP implementations, trace these operations in both source files:

constructor -> weight initialization
setInputVector -> feedForward
output delta -> hidden deltas
weight/bias update
calcMSE / calcCrossEntropy
toJson -> loadJson

MlpMatrixNN additionally contains batch matrix assembly, backend selection, Adam state, and host/device synchronization.

Recurrent networks

Model Header Implementation Tests Examples
VanillaRnn nu_rnn.h nu_rnn.cc test_rnn.cc rnn_sine, rnn_char
Gru nu_gru.h nu_gru.cc test_gru.cc same shared-interface demos
Lstm nu_lstm.h nu_lstm.cc test_lstm.cc rnn_adding

Read step() before bptt(). In the backward path, identify saved per-time-step intermediates, truncation boundaries, gradient clipping, and when state is advanced or reset.

Convolution and transformer

Component Header Implementation Tests Example
Conv1DLayer / MaxPool1DLayer nu_conv.h nu_conv.cc test_cnn.cc cnn_seq.cc
ConvNet nu_convnet.h nu_convnet.cc test_cnn.cc same
LayerNorm / SelfAttentionLayer / TransformerBlock / MiniTransformer nu_transformer.h nu_transformer.cc test_transformer.cc transformer_char.cc

For convolution, trace channel-major flattening, im2col, activation, saved max indices, and reverse gradient routing. For attention, trace shapes through Q/K/V projection, causal masking, row softmax, head concatenation, residuals, and output logits.

Classical, associative, and representation models

Model Header Implementation Tests Example
LinearRegression nu_linear_regression.h nu_linear_regression.cc test_linear_regression.cc demo
KMeans nu_kmeans.h nu_kmeans.cc test_kmeans.cc demo
Pca nu_pca.h nu_pca.cc test_pca.cc demo
HopfieldNN nu_hopfieldnn.h nu_hopfieldnn.cc MLP/persistence suite and demo assertions hopfield_test.cc
Autoencoder nu_autoencoder.h nu_autoencoder.cc test_autoencoder.cc demo
Rbf nu_rbf.h nu_rbf.cc test_rbf.cc demo
Rbm nu_rbm.h nu_rbm.cc test_rbm.cc demo
Vae nu_vae.h nu_vae.cc test_vae.cc demo
Som nu_som.h nu_som.cc test_som.cc demo

For these models, start with fit() or train() and identify exactly which parameters are learned. For example, Rbf::fitCenters() fixes centers and widths before train() changes only output weights.

Reinforcement learning

Component Header / implementation Tests Example
Q-learning template nu_qlearn.h test_rl.cc maze.cc
SARSA template nu_sarsa.h test_rl.cc maze.cc
epsilon-greedy policy nu_e_greedy_policy.h test_rl.cc maze
softmax policy nu_softmax_policy.h test_rl.cc maze
graph Q-learning nu_qlgraph.h · nu_qlgraph.cc test_qmatrix.cc path_finder.cc
replay buffer nu_replay_buffer.h test_dqn.cc DQN maze
DQN nu_dqn.h · nu_dqn.cc test_dqn.cc dqn_maze.cc

The tabular learners are templates, so their update code lives in the headers. Read the example's Agent contract before the learner: state transition and reward semantics belong to the environment, not to QLearn or Sarsa.

MNIST, persistence, and tools

Area Source Related executable/test
IDX parsing and normalized digit vectors mnist.h · mnist.cc mnist_test.cc
OCR training and recognition ocr_test.cpp ocr_test on Windows
OCR runtime fallback ocr_launcher.cpp packaged launcher
legacy-to-JSON conversion net2json.cc net2json
topology extraction and Graphviz output nunn_topo.cc nunn_topo
persistence behavior each model source test_mlpnn.cc, test_mlpmatrixnn.cc, test_perceptron.cc

A productive reading order

For any algorithm:

  1. Read the public header until you can state input shape, output shape, learned parameters, and error conditions.
  2. Open the smallest example and trace construction, training, and evaluation.
  3. Follow one forward pass in the source.
  4. Follow one update backward, writing down every saved intermediate.
  5. Read tests for invalid shapes, numerical behavior, and round trips.
  6. Change one example parameter and predict the result before running it.

Keep reading

Return to Theory Notes for equations, or Examples Gallery for executable-centered study paths.

Clone this wiki locally