Feed-Forward Neural Networks (MLPs) and Training Optimization

Foundations of Artificial Neural Networks and the Perceptron

An Artificial Neural Network (ANN) is an information processing paradigm inspired by biological nervous systems. The basic fundamental building block of an ANN is the Perceptron (or artificial neuron).

Perceptron architecture diagram showing inputs, weights, linear combination summation, non-linearity activation function, and output

Mathematical Formulation of a Perceptron

A perceptron receives a vector of input features, scales them by corresponding synaptic weights, introduces an additive bias term, and routes the accumulated linear combination through an activation function (non-linearity) to generate an output.

  • Inputs: A set of mm numerical features, denoted as x1,x2,…,xmx_1, x_2, \dots, x_m, represented as an input column vector:

X=[x1x2⋮xm]\mathbf{X} = \begin{bmatrix} x_1 \\ x_2 \\ \vdots \\ x_m \end{bmatrix}

  • Weights: Synaptic strengths corresponding to each input channel, denoted as w1,w2,…,wmw_1, w_2, \dots, w_m, organized as a row vector:

W=[w1w2…wm]\mathbf{W} = \begin{bmatrix} w_1 & w_2 & \dots & w_m \end{bmatrix}

  • Bias: An offset parameter bb, which can be conceptualized as a weight connected to a constant fixed input of 11.

  • Linear Combination (Summation): The pre-activation scalar zz is computed as the inner product of weights and inputs plus the bias:

z=b+∑i=1mxiwi=WX+bz = b + \sum_{i=1}^m x_i w_i = \mathbf{W}\mathbf{X} + b

  • Non-Linearity (Activation Function): A function g(⋅)g(\cdot) applied to the linear combination zz.

  • Output: The predicted output y^\hat{y} is defined as:

y^=g(z)=g(b+∑i=1mxiwi)=g(WX+b)\hat{y} = g(z) = g\left(b + \sum_{i=1}^m x_i w_i\right) = g(\mathbf{W}\mathbf{X} + b)

Geometrically, the equation WX+b=0\mathbf{W}\mathbf{X} + b = 0 establishes a hyperplane known as the decision boundary, which partitions the input feature space into two distinct regions.

Linear Separability and Logic Gate Implementation

A single perceptron functions as a linear classifier capable of learning linearly separable logical operators such as AND and OR.

The AND Logic Gate Implementation

An AND gate outputs 11 if and only if both binary inputs are 11, and outputs 00 otherwise.

  • Weight Vector:

W=[11]\mathbf{W} = \begin{bmatrix} 1 & 1 \end{bmatrix}

  • Bias:

b=−1.5b = -1.5

  • Pre-activation Equation:

z=WX+b=x1+x2−1.5z = \mathbf{W}\mathbf{X} + b = x_1 + x_2 - 1.5

  • Activation Function: The Heaviside step function:

g(z)={1if z≥00if z<0g(z) = \begin{cases} 1 & \text{if } z \ge 0 \\ 0 & \text{if } z < 0 \end{cases}

Truth Table and Verification
x1x_1x2x_2z=x1+x2−1.5z = x_1 + x_2 - 1.5Predicted Output y^=g(z)\hat{y} = g(z)Target Output
0000−1.5-1.50000
0011−0.5-0.50000
1100−0.5-0.50000
11110.50.51111

The decision boundary is given by x1+x2−1.5=0x_1 + x_2 - 1.5 = 0, cleanly separating the point (1,1)(1, 1) from the set of points {(0,0),(0,1),(1,0)}\{(0,0), (0,1), (1,0)\}.

Limitations of a Single Perceptron: The XOR Problem

The Exclusive-OR (XOR) logic gate outputs 11 when inputs differ and 00 when they are identical:

  • (0,0)→0(0, 0) \rightarrow 0
  • (0,1)→1(0, 1) \rightarrow 1
  • (1,0)→1(1, 0) \rightarrow 1
  • (1,1)→0(1, 1) \rightarrow 0

A single linear decision boundary cannot isolate the diagonal points (0,1)(0, 1) and (1,0)(1, 0) from (0,0)(0, 0) and (1,1)(1, 1). The XOR problem is not linearly separable and requires drawing two lines instead of one.

Decision boundaries for the XOR problem in original input space showing two separating lines

Multi-Layer Perceptrons and the XOR Architecture

To separate non-linearly separable functions, multiple perceptrons are connected hierarchically. A Two-Layer Perceptron consists of one hidden layer and one output layer.

Transformation of the XOR problem into a transformed feature space where classes are linearly separable

By introducing a hidden layer, the network maps the original non-linearly separable input vectors x\mathbf{x} into an intermediate transformed representation y\mathbf{y}. The output layer then applies a final linear decision boundary on this transformed space.

Two-layer perceptron neural network wiring diagram for XOR representation

Mathematical Formulation of the XOR Two-Layer Network
1. Hidden Layer Parameters
  • Hidden unit 1 linear combination:

z1=w1X+b1=x1+x2−1.5z_1 = \mathbf{w}_1 \mathbf{X} + b_1 = x_1 + x_2 - 1.5

  • Hidden unit 2 linear combination:

z2=w2X+b2=x1+x2−0.5z_2 = \mathbf{w}_2 \mathbf{X} + b_2 = x_1 + x_2 - 0.5

  • Matrix Representation:

W(1)=[w1w2]=[1111]\mathbf{W}^{(1)} = \begin{bmatrix} \mathbf{w}_1 \\ \mathbf{w}_2 \end{bmatrix} = \begin{bmatrix} 1 & 1 \\ 1 & 1 \end{bmatrix}

b(1)=[b1b2]=[−1.5−0.5]\mathbf{b}^{(1)} = \begin{bmatrix} b_1 \\ b_2 \end{bmatrix} = \begin{bmatrix} -1.5 \\ -0.5 \end{bmatrix}

Z(1)=[z1z2]=W(1)x+b(1)\mathbf{Z}^{(1)} = \begin{bmatrix} z_1 \\ z_2 \end{bmatrix} = \mathbf{W}^{(1)}\mathbf{x} + \mathbf{b}^{(1)}

[y^1y^2](1)=g(Z(1))=g(W(1)x+b(1))\begin{bmatrix} \hat{y}_1 \\ \hat{y}_2 \end{bmatrix}^{(1)} = g\left(\mathbf{Z}^{(1)}\right) = g\left(\mathbf{W}^{(1)}\mathbf{x} + \mathbf{b}^{(1)}\right)

2. Output Layer Parameters
  • Output weights:

W(2)=[1−2]\mathbf{W}^{(2)} = \begin{bmatrix} 1 & -2 \end{bmatrix}

  • Output bias:

b(2)=−0.5b^{(2)} = -0.5

  • Final output pre-activation and activation:

y^(2)=g(Z(2))=g(W(2)[y^1y^2]+b(2))=g(y^1−2y^2−0.5)\hat{y}^{(2)} = g\left(Z^{(2)}\right) = g\left(\mathbf{W}^{(2)} \begin{bmatrix} \hat{y}_1 \\ \hat{y}_2 \end{bmatrix} + b^{(2)}\right) = g\left(\hat{y}_1 - 2\hat{y}_2 - 0.5\right)

Truth Table for the XOR Network
x1x_1x2x_2y^1\hat{y}_1y^2\hat{y}_2Predicted Output y^\hat{y}Target Output
000000000000
001111001111
110011001111
111111110000

General Multi-Layer Perceptron (MLP) Formulation

A Feed-Forward Neural Network (FFNN) or Multi-Layer Perceptron (MLP) extends the two-layer architecture to arbitrary depths and widths.

Two-layer neural network general structure with input, hidden, and output units

Two-Layer General Formulation

For a two-layer neural network with mm input features, d1d_1 hidden units, and multiple outputs:

  • Hidden Layer Linear Combinations: For each hidden node i∈{1,…,d1}i \in \{1, \dots, d_1\}:

zi=w0,i(1)+∑j=1mxjwj,i(1)z_i = w_{0,i}^{(1)} + \sum_{j=1}^m x_j w_{j,i}^{(1)}

  • Vectorized Hidden Output:

Y^(1)=g(1)(Z(1))=g(1)(W(1)X+b(1))\mathbf{\hat{Y}}^{(1)} = g^{(1)}\left(\mathbf{Z}^{(1)}\right) = g^{(1)}\left(\mathbf{W}^{(1)}\mathbf{X} + \mathbf{b}^{(1)}\right)

  • Final Output Units: For each output node ii:

y^i=g(w0,i(2)+∑j=1d1g(zj)wj,i(2))\hat{y}_i = g\left(w_{0,i}^{(2)} + \sum_{j=1}^{d_1} g(z_j) w_{j,i}^{(2)}\right)

  • Vectorized Output Layer:

Y^(2)=g(2)(W(2)y(1)+b(2))\mathbf{\hat{Y}}^{(2)} = g^{(2)}\left(\mathbf{W}^{(2)}\mathbf{y}^{(1)} + \mathbf{b}^{(2)}\right)

Generalized deep multi-layer perceptron topology across arbitrary layer depths

Arbitrary Layer (Deep) Formulation

For an arbitrary hidden or output layer kk containing nkn_k units, receiving activations from the preceding layer k−1k-1 having nk−1n_{k-1} units:

  • Unit-Level Linear Combination:

zk,i=w0,i(k)+∑j=1nk−1g(zk−1,j)wj,i(k)z_{k,i} = w_{0,i}^{(k)} + \sum_{j=1}^{n_{k-1}} g\left(z_{k-1,j}\right) w_{j,i}^{(k)}

  • Matrix Form:

Y^(k)=g(k)(W(k)y(k−1)+b(k))\mathbf{\hat{Y}}^{(k)} = g^{(k)}\left(\mathbf{W}^{(k)}\mathbf{y}^{(k-1)} + \mathbf{b}^{(k)}\right)

Worked Numerical Example: Forward Propagation

A two-layer feed-forward neural network is defined with the following structural parameters and inputs:

  • Input Vector:

x=[1−32]T=[1−32]\mathbf{x} = \begin{bmatrix} 1 & -3 & 2 \end{bmatrix}^T = \begin{bmatrix} 1 \\ -3 \\ 2 \end{bmatrix}

  • Hidden Layer Weight Matrix W(1)\mathbf{W}^{(1)} and Bias Vector b(1)\mathbf{b}^{(1)}:

W(1)=[1−25321−154231],b(1)=[54−21]\mathbf{W}^{(1)} = \begin{bmatrix} 1 & -2 & 5 \\ 3 & 2 & 1 \\ -1 & 5 & 4 \\ 2 & 3 & 1 \end{bmatrix}, \quad \mathbf{b}^{(1)} = \begin{bmatrix} 5 \\ 4 \\ -2 \\ 1 \end{bmatrix}

  • Output Layer Weight Vector W(2)\mathbf{W}^{(2)} and Bias Scalar b(2)b^{(2)}:

W(2)=[5312],b(2)=−3\mathbf{W}^{(2)} = \begin{bmatrix} 5 & 3 & 1 & 2 \end{bmatrix}, \quad b^{(2)} = -3

  • Activation Function: Linear activation is employed at all layers (g(z)=zg(z) = z).
Step 1: Compute Hidden Layer Activations Y^(1)\mathbf{\hat{Y}}^{(1)}

Y^(1)=g(1)(W(1)x+b(1))=W(1)x+b(1)\mathbf{\hat{Y}}^{(1)} = g^{(1)}\left(\mathbf{W}^{(1)}\mathbf{x} + \mathbf{b}^{(1)}\right) = \mathbf{W}^{(1)}\mathbf{x} + \mathbf{b}^{(1)}

W(1)x=[1−25321−154231][1−32]=[1(1)+(−2)(−3)+5(2)3(1)+2(−3)+1(2)−1(1)+5(−3)+4(2)2(1)+3(−3)+1(2)]=[1+6+103−6+2−1−15+82−9+2]=[17−1−8−5]\mathbf{W}^{(1)}\mathbf{x} = \begin{bmatrix} 1 & -2 & 5 \\ 3 & 2 & 1 \\ -1 & 5 & 4 \\ 2 & 3 & 1 \end{bmatrix} \begin{bmatrix} 1 \\ -3 \\ 2 \end{bmatrix} = \begin{bmatrix} 1(1) + (-2)(-3) + 5(2) \\ 3(1) + 2(-3) + 1(2) \\ -1(1) + 5(-3) + 4(2) \\ 2(1) + 3(-3) + 1(2) \end{bmatrix} = \begin{bmatrix} 1 + 6 + 10 \\ 3 - 6 + 2 \\ -1 - 15 + 8 \\ 2 - 9 + 2 \end{bmatrix} = \begin{bmatrix} 17 \\ -1 \\ -8 \\ -5 \end{bmatrix}

Adding the bias vector b(1)\mathbf{b}^{(1)}:

Y^(1)=[1−25321−154231][1−32]+[54−21]=[233−10−4]\mathbf{\hat{Y}}^{(1)} = \begin{bmatrix} 1 & -2 & 5 \\ 3 & 2 & 1 \\ -1 & 5 & 4 \\ 2 & 3 & 1 \end{bmatrix} \begin{bmatrix} 1 \\ -3 \\ 2 \end{bmatrix} + \begin{bmatrix} 5 \\ 4 \\ -2 \\ 1 \end{bmatrix} = \begin{bmatrix} 23 \\ 3 \\ -10 \\ -4 \end{bmatrix}

Step 2: Compute Final Output Y^(2)\mathbf{\hat{Y}}^{(2)}

Y^(2)=g(2)(W(2)y(1)+b(2))=W(2)y(1)+b(2)\mathbf{\hat{Y}}^{(2)} = g^{(2)}\left(\mathbf{W}^{(2)}\mathbf{y}^{(1)} + b^{(2)}\right) = \mathbf{W}^{(2)}\mathbf{y}^{(1)} + b^{(2)}

Y^(2)=[5312][233−10−4]−3\mathbf{\hat{Y}}^{(2)} = \begin{bmatrix} 5 & 3 & 1 & 2 \end{bmatrix} \begin{bmatrix} 23 \\ 3 \\ -10 \\ -4 \end{bmatrix} - 3

Y^(2)=5(23)+3(3)+1(−10)+2(−4)−3\mathbf{\hat{Y}}^{(2)} = 5(23) + 3(3) + 1(-10) + 2(-4) - 3

Y^(2)=115+9−10−8−3=103\mathbf{\hat{Y}}^{(2)} = 115 + 9 - 10 - 8 - 3 = 103

The final computed scalar output of the network is 103103.

Neural Network Operational Modes and Training

Neural networks operate under two fundamental operational modes:

  1. Forward Direction (Inference / Feed-Forward):

    • Presenting an input pattern to the input units.
    • Feeding signals forward sequentially through hidden layers via affine transformations and non-linear activation functions.
    • Producing the computed output predictions at the final layer.
  2. Learning / Backward Direction (Supervised Training):

    • Calculating the discrepancy (error or cost) between computed outputs and target labels.
    • Propagating error signals backward across network layers.
    • Iteratively updating network parameters (weights and biases) to minimize the distance between actual and desired outputs.

Loss Functions

The loss incurred by a neural network measures the penalty incurred from incorrect predictions.

Single-Instance Loss vs. Empirical Loss
  • Single-Instance Loss: For an individual sample ii, the loss is given by:

L(f(x(i);W),y(i))\mathcal{L}\left(f(\mathbf{x}^{(i)}; \mathbf{W}), y^{(i)}\right)

where f(x(i);W)=y^(i)f(\mathbf{x}^{(i)}; \mathbf{W}) = \hat{y}^{(i)} is the predicted output and y(i)y^{(i)} is the true ground-truth target.

  • Empirical Loss (Cost Function / Objective Function / Empirical Risk): The average cost across an entire dataset consisting of nn training samples:

J(W)=1n∑i=1nL(f(x(i);W),y(i))J(\mathbf{W}) = \frac{1}{n} \sum_{i=1}^n \mathcal{L}\left(f(\mathbf{x}^{(i)}; \mathbf{W}), y^{(i)}\right)

Mean Squared Error (MSE) Loss for Regression

MSE loss is utilized in regression tasks where the network predicts continuous real-valued quantities:

J(W)=1n∑i=1n(y(i)−f(x(i);W))2J(\mathbf{W}) = \frac{1}{n} \sum_{i=1}^n \left(y^{(i)} - f(\mathbf{x}^{(i)}; \mathbf{W})\right)^2

Regression Case Study: Worker Savings Prediction

A dataset containing worker financial metrics is designed to predict savings based on income and national minimum wage:

| Income in ∣Minimumwage∣Savingsin| Minimum wage | Savings in (Target yy) | | :---: | :---: | :---: | | 10001000 | 400400 | 450450 | | 21002100 | 11001100 | 850850 | | 500500 | 400400 | 100100 | | 900900 | 500500 | 300300 | | 950950 | 600600 | 330330 | | 15001500 | 800800 | 590590 | | 18001800 | 10001000 | 650650 | | 12001200 | 600600 | 480480 | | 16001600 | 900900 | 600600 | | 25002500 | 15001500 | 10001000 |

For the first sample x(1)=[1000400]\mathbf{x}^{(1)} = \begin{bmatrix} 1000 \\ 400 \end{bmatrix}, with actual target y(1)=450y^{(1)} = 450, an unoptimized network with randomly initialized weights outputs y^(1)=50\hat{y}^{(1)} = 50. This substantial error demonstrates the need for weight optimization.

Cross-Entropy Loss for Classification

In classification tasks, exact continuous values are not required; the network outputs probabilities in the range [0,1][0, 1], which are thresholded or rounded to binary labels {0,1}\{0, 1\}.

Classification problem setup and binary cross-entropy loss function representation

Binary Cross-Entropy Loss is defined as:

J(W)=−1n∑i=1n[y(i)log⁡(f(x(i);W))+(1−y(i))log⁡(1−f(x(i);W))]J(\mathbf{W}) = -\frac{1}{n} \sum_{i=1}^n \left[ y^{(i)} \log\left(f(\mathbf{x}^{(i)}; \mathbf{W})\right) + \left(1 - y^{(i)}\right) \log\left(1 - f(\mathbf{x}^{(i)}; \mathbf{W})\right) \right]

Loss Optimization and Gradient Descent

The Optimization Objective

The goal of neural network training is to determine the optimal set of parameters W∗\mathbf{W}^* that minimizes the total cost across all training examples:

W∗=arg⁡min⁡WJ(W)=arg⁡min⁡W1n∑i=1nL(f(x(i);W),y(i))\mathbf{W}^* = \arg\min_{\mathbf{W}} J(\mathbf{W}) = \arg\min_{\mathbf{W}} \frac{1}{n} \sum_{i=1}^n \mathcal{L}\left(f(\mathbf{x}^{(i)}; \mathbf{W}), y^{(i)}\right)

where W={W(0),W(1),… }\mathbf{W} = \{\mathbf{W}^{(0)}, \mathbf{W}^{(1)}, \dots\} represents the collection of all weight matrices and bias vectors across the entire network architecture.

The Loss Landscape and the Gradient

The cost function J(W)J(\mathbf{W}) defines a high-dimensional loss surface over the parameter space (e.g., J(w0,w1)J(w_0, w_1)). This landscape exhibits complex topography, including local minima, global minima, plateaus, and saddle points.

  • Definition of Gradient: The gradient of a scalar-valued function ff of several variables is the vector ∇f\nabla f whose value at any given point gives the direction and the rate of fastest increase.

To minimize the objective function, the weights must be adjusted in the direction opposite to the gradient.

3D loss surface topography illustrating the iterative trajectory of gradient descent optimization

Gradient Descent Algorithm

The optimization procedure executes iteratively according to the following algorithmic routine:

  1. Weight Initialization: Initialize all network weights randomly from a normal distribution:

W∼N(0,σ2)\mathbf{W} \sim \mathcal{N}(0, \sigma^2)

  1. Optimization Loop: Repeat until convergence criteria are met:

  2. Gradient Computation: Compute the partial derivatives of the cost function with respect to every parameter:

∂J(W)∂W\frac{\partial J(\mathbf{W})}{\partial \mathbf{W}}

  1. Weight Update: Take a step in the direction opposite to the gradient, scaled by the learning rate η\eta:

W←W−η∂J(W)∂W\mathbf{W} \leftarrow \mathbf{W} - \eta \frac{\partial J(\mathbf{W})}{\partial \mathbf{W}}

  1. Return Parameters: Return the optimized parameter configuration W∗\mathbf{W}^*.