8 Machine Learning And Neural Networks

Artificial Intelligence · Unit 8

Machine Learning and Neural Networks

Exam-focused notes for Machine Learning and Neural Networks (Artificial Intelligence, BIT252): what the TU syllabus asks and how it has actually been tested, with 7 solved past questions from this unit.

Machine Learning and Neural Networks in short

Machine learning lets a program improve from data instead of fixed rules. This chapter covers the idea of learning, and the artificial neural network, which is a main learning model inspired by the brain.

Machine Learning and Neural Networks: notes

Machine learning definition

Machine learning (ML) is the study of programs that improve their performance on a task through experience. Tom Mitchell's definition: a program learns from experience $E$ for a task $T$ if its performance on $T$ improves with $E$. Performance is measured by $P$.

Types of learning:

  • Supervised learning: learn from labeled examples (input and correct output). Examples: spam detection, price prediction.
  • Unsupervised learning: find patterns in unlabeled data. Example: grouping customers.
  • Reinforcement learning: learn by trial and reward from the environment.

Artificial neural network mathematical model

An artificial neural network (ANN) is a set of simple connected units called neurons. Each connection has a weight. Learning means adjusting the weights.

The model of one neuron (McCulloch and Pitts style, with weights):

$$y = f\left(\sum_{i=1}^{n} w_i x_i + b\right)$$

Here $x_i$ are inputs, $w_i$ are weights, $b$ is the bias, and $f$ is the activation function. The sum $net = \sum w_i x_i + b$ is the net input.

Numerical example. Inputs $x = (1, 0, 1)$, weights $w = (0.5, -0.3, 0.8)$, bias $b = -0.2$, sigmoid activation.

$$\begin{aligned} net &= (0.5)(1) + (-0.3)(0) + (0.8)(1) - 0.2 \ &= 0.5 + 0 + 0.8 - 0.2 = 1.1 \ y &= \frac{1}{1 + e^{-1.1}} = 0.7503 \end{aligned}$$

Feed-forward vs feed-back networks:

Feed-forward networkFeed-back (recurrent) network
Signals move in one direction, input to outputSignals can loop back to earlier units
No cyclesHas cycles and feedback connections
No memory of earlier inputsKeeps memory through its internal state
Output depends only on the current inputOutput depends on current and past inputs
Used for classification and regressionUsed for sequences, such as text and speech

Neuron structure and activation functions

A biological neuron has dendrites that receive signals, a cell body that adds them, and an axon that carries the output. Synapses are the connections, and their strength is like a weight. An artificial neuron copies this: inputs are dendrites, weights are synapses, the sum is the cell body, and the activation is the firing.

The activation function decides the output of a neuron from its net input. Its task is to add non-linearity, so that the network can learn complex patterns. Without it, many layers would act like a single linear layer. It also limits the output range.

FunctionFormulaOutput range
Step (threshold)$1$ if $net \ge 0$, else $0$0 or 1
Sigmoid$\dfrac{1}{1 + e^{-net}}$0 to 1
Tanh$\dfrac{e^{net} - e^{-net}}{e^{net} + e^{-net}}$$-1$ to 1
ReLU$\max(0, net)$0 to infinity
Linear$net$any

Sigmoid has a handy derivative: $f'(net) = f(net),(1 - f(net))$. ReLU is popular in deep networks because it is simple and avoids slow learning for large inputs.

What this unit covers

  • Machine learning definition
  • Artificial neural network mathematical model
  • Neuron structure and activation functions
  • Feed-forward neural networks
  • Recurrent neural networks
  • Back-propagation algorithm
  • Learning rules and learning rates
  • Neural network types and architectures

Back-propagation algorithm

2082 · 10 marks

What is learning rule?How learning is done in ANN using back propagation algorithm?[2+8]

Show solved answer

Learning Rule and Backpropagation in ANN


Part 1: What is a Learning Rule? [2 marks]

A learning rule is a method or procedure that modifies the weights and biases of a neural network in order to improve its performance on a given task. It defines how the network learns from training data by updating connection weights based on the error between the actual output and the desired output.

Common types of learning rules include:

  • Hebbian Learning Rule - weights are updated based on the correlation of input and output activations
  • Perceptron Learning Rule - weights are updated when the output is incorrect
  • Delta (Widrow-Hoff) Rule - weights are updated proportional to the error
  • Backpropagation Rule - generalized delta rule for multilayer networks

General form: $$\Delta w_{ij} = \eta \cdot \delta_j \cdot x_i$$ where $\eta$ is the learning rate, $\delta_j$ is the error signal, and $x_i$ is the input.


Part 2: Learning Using Backpropagation Algorithm [8 marks]

Overview

Backpropagation (BP) is a supervised learning algorithm used to train multilayer feedforward neural networks. It works by:

  1. Forward pass - computing the output
  2. Backward pass - propagating the error backward and updating weights

Network Architecture

Consider a three-layer network:

  • Input layer - nodes indexed $i$
  • Hidden layer - nodes indexed $j$
  • Output layer - nodes indexed $k$

Step-by-Step Backpropagation Algorithm

Step 1: Initialize Weights

Set all weights $w_{ij}$ and $w_{jk}$ to small random values (typically between -0.5 and 0.5).


Step 2: Forward Pass (Feed Forward)

At the hidden layer, compute the net input and activation for each hidden neuron $j$:

$$net_j = \sum_i w_{ij} \cdot x_i + b_j$$

$$y_j = f(net_j) = \frac{1}{1 + e^{-net_j}} \quad \text{(sigmoid activation)}$$

At the output layer, compute the net input and activation for each output neuron $k$:

$$net_k = \sum_j w_{jk} \cdot y_j + b_k$$

$$o_k = f(net_k) = \frac{1}{1 + e^{-net_k}}$$


Step 3: Compute Output Error

For each output neuron $k$, compute the error signal $\delta_k$:

$$E = \frac{1}{2} \sum_k (t_k - o_k)^2$$

where $t_k$ is the target (desired) output and $o_k$ is the actual output.

The error gradient at the output layer:

$$\delta_k = (t_k - o_k) \cdot f'(net_k)$$

For sigmoid activation: $f'(net_k) = o_k(1 - o_k)$

$$\boxed{\delta_k = (t_k - o_k) \cdot o_k(1 - o_k)}$$


Step 4: Backpropagate Error to Hidden Layer

Compute the error signal $\delta_j$ for each hidden neuron $j$:

$$\delta_j = \left(\sum_k \delta_k \cdot w_{jk}\right) \cdot f'(net_j)$$

$$\boxed{\delta_j = \left(\sum_k \delta_k \cdot w_{jk}\right) \cdot y_j(1 - y_j)}$$

The error is propagated backward from output to hidden layer using the weights.


Step 5: Update Weights

Update weights between hidden and output layer:

$$\Delta w_{jk} = \eta \cdot \delta_k \cdot y_j$$

$$w_{jk}^{new} = w_{jk}^{old} + \Delta w_{jk}$$

Update weights between input and hidden layer:

$$\Delta w_{ij} = \eta \cdot \delta_j \cdot x_i$$

$$w_{ij}^{new} = w_{ij}^{old} + \Delta w_{ij}$$

where $\eta$ is the learning rate (typically 0.01 to 0.9).


Step 6: Repeat

Repeat Steps 2 to 5 for all training patterns until the total error $E$ is minimized below a threshold or the maximum number of epochs is reached.


Summary Diagram

Input Layer      Hidden Layer      Output Layer
   x_i  ---w_ij---> y_j ---w_jk---> o_k
                                      |
                              Error = (t_k - o_k)
                                      |
              <--- delta_j <--- delta_k (backpropagated)
              Weight update          Weight update

Key Points

AspectDetail
TypeSupervised learning
DirectionForward (compute output) + Backward (update weights)
ActivationSigmoid (differentiable)
Error functionMean Squared Error (MSE)
Weight updateGradient Descent
Learning rate $\eta$Controls step size of weight update

Advantages and Limitations

Advantages:

  • Can learn complex nonlinear mappings
  • Works for multilayer networks

Limitations:

  • May get stuck in local minima
  • Slow convergence for large networks
  • Requires labeled training data
  • Sensitive to learning rate choice
Open this answer on its own page →

0 · 10 marks

Why do we need recurrent neural network? How does back propagation learn to minimize the error? Explain[10]

Standard feedforward neural networks (FNN) have a fundamental limitation: they assume all inputs are independent of each other. Each input is processed in isolation, and the network has no memory of previous inputs. This creates problems for sequential data, where the current output depends on pr...

Open this answer on its own page →

Artificial neural network mathematical model

2082 · 5 marks

Describe the mathematical model of ANN. Differentiate feed-forward ANN from feed-back ANN. [2+3]

--- An Artificial Neural Network (ANN) is inspired by biological neurons. The mathematical model of a single artificial neuron consists of the following components: 1. Inputs and Weights: Each neuron receives n inputs x₁, x₂, ..., xₙ with corresponding weights w₁, w₂, ..., wₙ. 2. Net Input (Weigh...

Open this answer on its own page →

2080.2 · 10 marks

Express the mathematical model of a neuron. Distinguish between learning rule and learning rate. How Back-propagation algorithm is used in learning? Explain.[10]

Show solved answer

Mathematical Model of a Neuron, Learning Rule vs Learning Rate, and Back-Propagation Algorithm

Note: No specific curriculum notes were provided for this question. The answer below is based on standard, correct Artificial Neural Networks (ANN) theory as taught in BSc CSIT Neural Networks / AI courses.


1. Mathematical Model of a Neuron (McCulloch-Pitts Model)

A biological neuron is mathematically modelled as a processing unit that receives multiple inputs, weights them, sums them, and passes the result through an activation function.

Structure

x1 --w1--|
x2 --w2--|
x3 --w3--|--> [Σ Weighted Sum] --> [Activation f] --> Output y
  ...     |
xn --wn--|
         |
        bias (b)

Mathematical Expression

Step 1: Weighted Sum (Net Input)

$$net = \sum_{i=1}^{n} w_i x_i + b$$

Where:

  • $x_i$ = input signals ($x_1, x_2, \ldots, x_n$)
  • $w_i$ = synaptic weights corresponding to each input
  • $b$ = bias term (threshold)
  • $net$ = net activation value

Step 2: Activation Function

$$y = f(net) = f\left(\sum_{i=1}^{n} w_i x_i + b\right)$$

Where $f(\cdot)$ is the activation function. Common choices:

Activation FunctionFormula
Step / Threshold$f(net) = 1$ if $net \geq \theta$, else $0$
Sigmoid$f(net) = \dfrac{1}{1+e^{-net}}$
Tanh$f(net) = \tanh(net)$
ReLU$f(net) = \max(0, net)$

Vector Form

$$y = f(\mathbf{w}^T \mathbf{x} + b)$$

Where $\mathbf{w} = [w_1, w_2, \ldots, w_n]^T$ and $\mathbf{x} = [x_1, x_2, \ldots, x_n]^T$.


2. Distinction Between Learning Rule and Learning Rate

AspectLearning RuleLearning Rate
DefinitionA mathematical procedure or algorithm that specifies how the weights of a neural network are updated during trainingA scalar hyperparameter ($\alpha$ or $\eta$) that controls the size of the weight update step
NatureA qualitative strategy / algorithmA quantitative numerical value
PurposeDefines the direction and method of weight adjustmentControls the magnitude of weight adjustment
ExamplesHebbian rule, Perceptron rule, Delta rule, Backpropagation, Competitive learning$\eta = 0.01$, $\eta = 0.1$, $\eta = 0.5$
Effect if wrongWrong rule leads to incorrect convergence or divergenceToo large $\eta$: oscillation/divergence; Too small $\eta$: very slow convergence
Formula roleDetermines the form of $\Delta w$Scales the update: $\Delta w = \eta \cdot \delta \cdot x$

Example (Delta Rule):

$$\Delta w_i = \eta \cdot (t - y) \cdot x_i$$

  • Learning rule here is the Delta Rule (error-correction rule)
  • Learning rate is $\eta$ (e.g., 0.1)

3. Back-Propagation Algorithm in Learning

What is Back-Propagation?

Back-propagation (BP) is a supervised learning algorithm used to train multi-layer feedforward neural networks (MLPs). It works by propagating the output error backward through the network to compute gradients and update weights using gradient descent.

Network Architecture

Input Layer    Hidden Layer    Output Layer
  x1 ------>  h1 ------>  o1
  x2 ------>  h2 ------>  o2
  x3 ------>  h3

Algorithm Steps

Phase 1: Forward Pass

  1. Present input $\mathbf{x}$ to the network.
  2. Compute net input and output at each hidden neuron $j$:

$$net_j = \sum_i w_{ij} x_i + b_j, \quad h_j = f(net_j)$$

  1. Compute net input and output at each output neuron $k$:

$$net_k = \sum_j w_{jk} h_j + b_k, \quad o_k = f(net_k)$$

Phase 2: Compute Output Error

For each output neuron $k$, compute the error:

$$E = \frac{1}{2} \sum_k (t_k - o_k)^2$$

Where $t_k$ is the target (desired) output and $o_k$ is the actual output.

Phase 3: Backward Pass (Error Propagation)

At Output Layer:

Compute error signal (delta) for output neuron $k$:

$$\delta_k = (t_k - o_k) \cdot f'(net_k)$$

For sigmoid: $f'(net_k) = o_k(1 - o_k)$

So: $\delta_k = (t_k - o_k) \cdot o_k(1 - o_k)$

At Hidden Layer:

Propagate error back to hidden neuron $j$:

$$\delta_j = \left(\sum_k \delta_k \cdot w_{jk}\right) \cdot f'(net_j)$$

$$\delta_j = \left(\sum_k \delta_k \cdot w_{jk}\right) \cdot h_j(1 - h_j)$$

Phase 4: Update the Weights

Each weight is adjusted against its own delta and the activation feeding it, where $\eta$ is the learning rate:

$$w_{jk} \leftarrow w_{jk} + \eta \cdot \delta_k \cdot h_j$$

$$w_{ij} \leftarrow w_{ij} + \eta \cdot \delta_j \cdot x_i$$

The forward and backward passes repeat for every training pattern until the total error $E$ falls below the chosen tolerance or the epoch limit is reached.

Open this answer on its own page →

Neural network types and architectures

2080 · 5 marks

Discuss different types of Neural Network. [5]

Note: Reference notes were not available for this topic. The following answer is based on standard Computer Science / AI curriculum content appropriate for BSc CSIT. --- A Neural Network is a computational model inspired by the human brain, consisting of interconnected nodes (neurons) organized i...

Open this answer on its own page →

Machine learning definition

2080 · 5 marks

What is machine learning? Describe about NLU and NLG. [5]

--- Machine Learning (ML) is a subfield of Artificial Intelligence (AI) that enables computers to learn from data and experience without being explicitly programmed for every task. Instead of writing fixed rules, a machine learning system: - Takes input data - Identifies patterns from that data -...

Open this answer on its own page →

Neuron structure and activation functions

2079 · 5 marks

What is the task of activation function? What are its types? [5]

An activation function is a mathematical function applied to the output of each neuron in a neural network. Its main tasks are: 1. Introduces Non-linearity: Without an activation function, a neural network (no matter how many layers) would behave like a simple linear model. Activation functions a...

Open this answer on its own page →