Note: This document explains neural network training theory (backpropagation, loss functions, gradient descent). netkit is inference-only — it runs forward passes on pre-trained float32 weights and does not implement training. For netkit usage, start with GETTING_STARTED.md and NK_FORMAT.md.
A neural network, at its core, is just a composable function approximator.
From an engineering perspective:
- You are building a system that maps inputs → outputs
- That system is composed of repeated simple computational blocks
- Each block does:
- a linear transformation (like a weighted sum / FIR filter)
- followed by a nonlinear function (like a saturation or lookup table)
So an MLP is nothing more than:
A stack of parameterized nonlinear functions trained to approximate a mapping from
$\mathbb{R}^n \to \mathbb{R}^m$
A single neuron computes:
Where:
-
$x \in \mathbb{R}^n$ : input vector -
$w \in \mathbb{R}^n$ : weights (learned parameters) -
$b \in \mathbb{R}$ : bias (learned offset) -
$z$ : linear combination -
$a$ : output activation -
$\sigma(\cdot)$ : nonlinear activation function
Think of this like:
- A weighted sum → like a DSP dot product (FIR filter tap)
- Bias → DC offset
- Activation → nonlinear saturation or transfer curve
Without the activation function, stacking layers collapses into a single linear transform. That would be equivalent to:
One giant matrix multiply → no expressive power
Activation functions introduce nonlinearity, which is what makes neural networks useful.
Properties:
- Output range: (0, 1)
- Historically used for probabilities
Engineering issue:
- Saturates for large |x|
- Causes vanishing gradients
Properties:
- Output range: (-1, 1)
- Zero-centered (better than sigmoid)
Still suffers from saturation.
Properties:
- Simple
- Efficient (important in embedded systems)
- Sparse activations
Engineering analogy:
- Like a diode: blocks negative values, passes positive
Why it dominates:
- Avoids saturation in positive region
- Cheap computation (no exponentials)
Without nonlinearities:
All layers collapse into one matrix.
So depth becomes useless.
Nonlinearity is what turns the system into a universal function approximator.
An MLP is a sequence of layers:
Each layer:
Where:
$a^{(0)} = x$ $a^{(L)} = \hat{y}$
The forward pass is just evaluation of the function.
For each layer:
This is equivalent to:
- Matrix multiplication pipeline
- Followed by elementwise nonlinear transform
- Repeated N times
If you were implementing this on embedded hardware:
- This is GEMM + vector activation kernel
- Highly parallelizable
- Cache/memory bound in practice
The loss function defines how wrong the network is.
Interpretation:
- Penalizes squared deviation
- Equivalent to L2 energy of error signal
For binary classification:
Engineering intuition:
- Measures divergence between probability distributions
- Strong penalty for confident wrong predictions
We want to adjust weights to minimize loss:
But:
- The function is nested
- Many layers depend on each other
- Direct differentiation is expensive without structure
So we use:
Chain rule + dynamic programming = backpropagation
Backprop computes gradients efficiently:
Instead of recomputing partial derivatives repeatedly, we reuse intermediate results.
If:
Then:
For deep networks:
- You apply this repeatedly across layers
Recall:
Loss:
We want:
Define:
This is the key object in backprop.
It represents:
“How much this layer contributed to the final error”
Interpretation:
- Outer product of error signal and input activation
- Very similar to correlation in signal processing
Where:
-
$\odot$ = elementwise product -
$\sigma'(z)$ = derivative of activation
Engineering note:
- ReLU derivative is basically a mask operation
For each layer:
- Compute:
- Apply activation:
- Compute output error:
- For each layer going backward:
- Gradients:
Once gradients are computed:
Where:
-
$\eta$ = learning rate
Training is:
A feedback control system
- Forward pass = system response
- Loss = error measurement
- Backprop = sensitivity analysis
- Gradient descent = control law update
This is very similar to:
- adaptive filters (LMS algorithm)
- system identification loops
Depth allows:
- hierarchical feature extraction
- composition of nonlinear transforms
- exponential reuse of intermediate representations
Mathematically:
- each layer composes functions
- composition increases expressiveness exponentially
- derivatives shrink through layers
- sigmoid/tanh worsen this
- derivatives grow uncontrollably
- activations stuck near limits
ReLU helps because:
- derivative is constant (1 or 0)
- avoids saturation in positive region
- keeps gradient flow stable
An MLP is:
- A chain of affine transforms:
- Interleaved with nonlinearities:
- Trained using:
- chain rule
- gradient descent
- error propagation backward through graph
If you're coming from embedded/DSP:
| Neural Net Concept | DSP Equivalent |
|---|---|
| Layer | Filter stage |
| Weights | FIR coefficients |
| Activation | Nonlinear amplifier |
| Forward pass | Signal propagation |
| Backprop | Sensitivity / adjoint system |
| Loss | Error energy |
| Training | Adaptive filtering |