{
"cells": [
{
"cell_type": "markdown",
"id": "20fce00f",
"metadata": {},
"source": [
"### Deep Learning\n",
"#### Multi-layer perceptron (MLP) for regression (from scratch)\n",
"A Multilayer Perceptron (MLP) for regression is a feedforward neural network with:\n",
"- Input Layer: Receives feature vectors.\n",
"- Hidden Layers: Use nonlinear activations (e.g., ReLU) to learn patterns.\n",
"- Output Layer: Single or multiple neurons with linear activations to predict continuous values.\n",
"- Loss Function: Here, the Mean Squared Error (MSE) to minimize prediction errors.\n",
"\n",
"The pseudo-code of training a three-layer MLP (generally any MLP) for regression with **backpropagation** is specified as: \n",
"
1. **Initialize** weights $W_1$,$b_1$,$W_2$,$b_2$.\n",
"
2. For each epoch:\n",
" - **Shuffle** training data.\n",
" - **Split** into mini-batches of size batch_size.\n",
" - For each mini-batch:\n",
" - **Forward pass:** Compute predictions $A_2$.\n",
" - **Compute loss:** MSE using $Y−A_2$.\n",
" - **Backward pass:** Compute gradients.\n",
" - **Update weights:** With gradient descent.\n",
"3. **Evaluate** on validation set periodically.\n",
"\n",
"Here, $A_2$ is the output of the output layer. $Y$ is the matrix of desired output such that each row $i$ is the desired vector $\\boldsymbol{y}_i$ for the the input vector $\\boldsymbol{x}_i$. We assume that we are given $n$ data pairs $(\\boldsymbol{x}_i,\\boldsymbol{y}_i)$ \n",
"\n",
"**Hint:** For the hidden layer, we use activation functions sush as: *Logistic*, *ReLU*, and *Tanh*.\n",
"\n",
"