Neural Network Framework exposes exactly three layer classes:Documentation 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, and OutputLayer. Every network is composed exclusively from these three building blocks, placed in a Python list in data-flow order. This page documents each class’s constructor signature, the attributes it exposes after construction and after a forward/backward pass, and the methods available on each instance.
InputLayer
InputLayer is always the first element in the network list. Its sole responsibility is to accept raw feature vectors and, optionally, apply an activation before passing values downstream.
Number of input neurons — must equal the number of features in each input sample.
Activation function applied to the raw inputs before they are read by the next layer.
Accepted values:
'sigmoid', 'relu', 'tanh', 'none'.Attributes
Attributes
| Attribute | Type | Description |
|---|---|---|
length | int | Number of neurons; equals the n argument passed to the constructor. |
inputs | np.ndarray | Raw feature vector set by put_values. Shape (1, n) before forward, empty array at construction. |
pre_activations | np.ndarray | Equals inputs (squeezed to 1-D). Set during forward(). |
activations | np.ndarray | Result of applying actfn to pre_activations. Read by the next layer during its own forward(). |
Methods
Methods
put_values(values)Stores a feature vector inside the layer. values must be a list or array whose length equals n; if the length does not match, the method prints an error message and leaves inputs unchanged.forward()Copies inputs into pre_activations (squeezing any leading dimension) and applies the chosen activation function, writing the result to activations. Call this as part of the left-to-right sweep over ANN.HiddenLayer
HiddenLayer sits between the input and output. It owns a weight matrix and a bias vector, applies an activation function, and can participate in both forward and backward passes. A network may contain any number of hidden layers.
Number of neurons in this hidden layer.
Activation function. Accepted values:
'sigmoid', 'relu', 'tanh', 'none'.Attributes
Attributes
| Attribute | Type | Available after | Description |
|---|---|---|---|
length | int | construction | Number of neurons (n). |
W | np.ndarray | set_weights() | Weight matrix of shape (n, prev.length). |
Bias | np.ndarray | set_biases() | Bias vector of shape (1, n). |
pre_activations | np.ndarray | forward() | Linear combination W @ prev.activations + Bias, squeezed to 1-D. |
activations | np.ndarray | forward() | actfn(pre_activations). Read by the next layer. |
dLda | np.ndarray | backward() | Gradient of loss w.r.t. this layer’s pre-activation. Shape (n, 1). |
dLdW | np.ndarray | backward() | Gradient of loss w.r.t. W. Shape (n, prev.length). Used for the weight update step. |
Methods
Methods
attach_after(layer)Links this layer to its predecessor. Sets self.previous = layer and layer.next = self. Must be called before set_weights, set_biases, or forward.set_weights(method)Allocates and initialises the weight matrix W of shape (self.length, self.previous.length). See Weight Initialization for the full list of method strings and their formulas.set_biases(method)Allocates and initialises the bias vector Bias of shape (1, self.length).forward()Computes pre_activations = W @ previous.activations + Bias (squeezed to 1-D) and then activations = actfn(pre_activations). Called during the left-to-right sweep.backward()Reads self.next.dLda and self.next.W, computes the chain-rule gradient through the activation function, and stores the result in self.dLda and self.dLdW. Called during the right-to-left sweep — after the next layer’s backward() has already run.OutputLayer
OutputLayer is always the last element in the network list. It owns its own weight matrix and bias, applies an output activation, computes the scalar loss, and provides the starting point for backpropagation.
Number of output neurons — one per class for classification, one for scalar regression.
Output activation. Accepted values:
'sigmoid', 'relu', 'tanh', 'softmax', 'none'.Loss function used to train the network. Accepted values:
'MSE', 'bincrossentropy', 'crossentropy'.Attributes
Attributes
| Attribute | Type | Available after | Description |
|---|---|---|---|
length | int | construction | Number of output neurons. |
W | np.ndarray | set_weights() | Weight matrix of shape (n, prev.length). |
Bias | np.ndarray | set_biases() | Bias vector of shape (1, n). |
actual | np.ndarray | set_actual() | Ground-truth label stored for loss and gradient computation. |
pre_activations | np.ndarray | forward() | Linear combination before the output activation. |
activations | np.ndarray | forward() | Output activation applied to pre_activations. |
dLda | np.ndarray | backward() | Gradient of loss w.r.t. this layer’s pre-activation. Shape (n, 1). Used by HiddenLayer.backward() of the previous layer. |
dLdW | np.ndarray | backward() | Gradient of loss w.r.t. W. Used in the weight update step. |
Methods
Methods
attach_after(layer)Same contract as HiddenLayer.attach_after. Must be called before weight initialisation or any forward pass.set_weights(method)Allocates W of shape (self.length, self.previous.length). Accepts the same method strings as HiddenLayer.set_weights.set_biases(method)Allocates Bias of shape (1, self.length). Accepts the same method strings as HiddenLayer.set_biases.set_actual(actual)Stores the ground-truth label for the current sample. Must be called before loss() or backward().forward()Computes pre_activations = W @ previous.activations + Bias and then activations = outputfn(pre_activations).backward()Computes the gradient of the chosen loss function w.r.t. activations, then chains through the output activation’s derivative, and finally calculates dLdW using the previous layer’s activations. This is the first call in the right-to-left sweep.output()Returns self.activations — the network’s raw prediction for the current sample.loss()Calls the stored loss function with (self.activations, self.actual) and returns a scalar. Useful for monitoring training progress.Quick-Reference Summary
InputLayer
Accepts raw features via
put_values. No weights or biases. Optional activation on inputs. Always index 0 in the ANN list.HiddenLayer
Owns
W and Bias. Supports forward() and backward(). Stack as many as needed between input and output.OutputLayer
Owns
W and Bias. Computes loss via loss(), exposes predictions via output(), and seeds backprop via backward(). Always the last element in the ANN list.