Neural Network Framework represents a feedforward (multilayer perceptron) network as an ordinary Python list of layer objects. Each element in that list is either anDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/adi3120/Neural-Network-Framework/llms.txt
Use this file to discover all available pages before exploring further.
InputLayer, HiddenLayer, or OutputLayer instance. The framework keeps layers aware of their neighbours through a doubly-linked structure set up at build time, and training is carried out by iterating over that list in the forward direction to produce predictions and in the reverse direction to propagate gradients.
Network as a Python List
The canonical way to hold a network in Neural Network Framework is a plain list:Model or Sequential wrapper; the list itself is the model.
Linking Layers with attach_after
Before a HiddenLayer or OutputLayer can compute anything it must know which layer feeds it. Calling attach_after(prev_layer) establishes this relationship by writing two back-references:
attach_after is called, set_weights and set_biases can be invoked because the layer now knows its own size (self.length) and the size of its predecessor (self.previous.length), which together define the weight-matrix shape (n_out, n_in).
Always call
attach_after before set_weights or set_biases. If previous is None when those methods run, no matrix will be allocated and the subsequent forward pass will raise an AttributeError.Assembling a 3-Layer Network
The following snippet builds a network with 3 input features, one hidden layer of 4 neurons (ReLU), and a 2-neuron softmax output for binary classification:Forward Pass
During a forward pass every layer reads theactivations attribute of its predecessor and writes its own computed activations. The InputLayer.forward() call applies the (optional) input activation directly to the raw values stored via put_values.
ANN[-1].activations holds the network’s prediction for the current sample.
Backward Pass
Gradient computation walks the list in reverse, starting from the output layer. Each layer computes three quantities and stores them as attributes:| Attribute | Meaning |
|---|---|
dLda | Gradient of the loss with respect to this layer’s pre-activation output (used by the layer to the left) |
dLdW | Gradient of the loss with respect to this layer’s weight matrix |
InputLayer has no weights and no backward method — the loop therefore starts at len(ANN)-1 and stops before index 0:
Weight Update (Gradient Descent)
After gradients have been computed for every layer, weights and biases are nudged in the direction that reduces the loss:1 to skip the InputLayer, which owns no weight matrix.
Full Training Loop
Putting all the pieces together, a bare-bones epoch loop looks like this:gradient_descent_epoch (fixed number of epochs) and gradient_descent_threshold (stops when loss drops below a threshold) — that implement exactly this loop.
Data Flow Diagram
forward() call pushes activations one step to the right. Each backward() call pulls gradients one step to the left. The weight update then consumes those gradients in place.