Artificial Intelligence ยท Unit 5 ยท 9 hrs
Machine Learning
Exam-focused notes for Machine Learning (Artificial Intelligence, CSC266): what the TU syllabus asks and how it has actually been tested, with 12 solved past questions from this unit.
Machine Learning in short
This unit is about learning: the general idea of an agent that improves with experience, the main categories of learning problem, a statistical learning method (Naive Bayes), a population-based search method (genetic algorithms), and neural networks, including the concrete learning rules used to train them.
What this unit covers
- Introduction to Machine Learning
- Concepts of Learning
- Supervised, Unsupervised and Reinforcement Learning
- Statistical-based Learning: Naive Bayes Model
- Learning by Genetic Algorithm
- Learning with Neural Networks: Introduction, Biological Neural Networks Vs. Artificial Neural Networks (ANN), Mathematical Model of ANN, Types of ANN: Feed-forward, Recurrent, Single Layered, Multi-Layered, Application of Artificial Neural Networks, Learning by Training ANN, Supervised vs. Unsupervised Learning, Hebbian Learning, Perceptron Learning, Back-propagation Learning
Learning with Neural Networks
2081 ยท 10 marks
How can you relate synapse, dendrite, and axon in biological neural networks with the elements of artificial neural networks? Create a multi-layer ANN with input layer, hidden layer, and output layer. Assume necessary inputs and weights to the ANN and illustrate a single iteration of backpropagation algorithm to train the ANN.[10]
Show solved answerHide answer
Artificial Neural Networks: Biological Analogy and Backpropagation
Given
The question requires us to assume inputs and weights, so the worked example below uses these values:
Inputs: $x_1 = 0.5$, $x_2 = 0.3$ Target: $t = 1.0$
Learning rate: $\alpha = 0.5$ Activation: Sigmoid $g(x) = \dfrac{1}{1+e^{-x}}$, derivative $g'(x) = g(x)(1-g(x))$ Biases: $0$
Initial weights:
| Weight | Connection | Value |
|---|---|---|
| $w_{13}$ | $x_1 \to h_1$ | 0.4 |
| $w_{23}$ | $x_2 \to h_1$ | 0.2 |
| $w_{14}$ | $x_1 \to h_2$ | 0.3 |
| $w_{24}$ | $x_2 \to h_2$ | 0.5 |
| $w_{35}$ | $h_1 \to o_1$ | 0.6 |
| $w_{45}$ | $h_2 \to o_1$ | 0.7 |
Part 1: Biological vs Artificial Neural Network Mapping
| Biological Element | Artificial Element | Function |
|---|---|---|
| Dendrite | Input connections carrying $x_j$ | Receive incoming signals |
| Synapse | Weight $w_{ij}$ | Modulate signal strength; learning adjusts these |
| Axon | Neuron output line | Transmits processed signal onward |
| Soma (cell body) | Summation $\Sigma$ + activation $g(\cdot)$ | Integrates weighted inputs and fires |
Summary: dendrites $\to$ inputs, synapses $\to$ weights, soma $\to$ summation + activation, axon $\to$ output. Learning in ANN = adjusting synaptic weights.
Part 2: Network Architecture
A 2-2-1 multilayer network:
x1 โw13โโ โโw35โโ
โโโ> h1 โโค โ
x2 โw23โโ โ โโโ> o1 โโ> y
โ โ
x1 โw14โโ โ โ
โโโ> h2 โโดโw45โโ
x2 โw24โโ
Part 3: Single Iteration of Backpropagation
Step 1: Forward pass - hidden layer
$$net_{h1} = 0.4(0.5) + 0.2(0.3) = 0.20 + 0.06 = 0.26$$ $$h_1 = g(0.26) = \frac{1}{1+e^{-0.26}} = \frac{1}{1.7711} = 0.5646$$
$$net_{h2} = 0.3(0.5) + 0.5(0.3) = 0.15 + 0.15 = 0.30$$ $$h_2 = g(0.30) = \frac{1}{1+e^{-0.30}} = \frac{1}{1.7408} = 0.5744$$
Step 2: Forward pass - output layer
$$net_{o1} = 0.6(0.5646) + 0.7(0.5744) = 0.3388 + 0.4021 = 0.7409$$ $$y = g(0.7409) = \frac{1}{1+e^{-0.7409}} = \frac{1}{1.4767} = 0.6772$$
Step 3: Output error and delta
$$\delta_{o1} = (t - y)\cdot y(1-y) = (1.0 - 0.6772)(0.6772)(1-0.6772)$$ $$= 0.3228 \times 0.6772 \times 0.3228 = 0.07057$$
Step 4: Hidden layer deltas
$$\delta_{h1} = h_1(1-h_1),(w_{35},\delta_{o1})$$ $$= 0.5646(0.4354)(0.6 \times 0.07057) = 0.2458 \times 0.04234 = 0.01041$$
$$\delta_{h2} = h_2(1-h_2),(w_{45},\delta_{o1})$$ $$= 0.5744(0.4256)(0.7 \times 0.07057) = 0.2445 \times 0.04940 = 0.01208$$
Step 5: Weight updates $;w^{new} = w^{old} + \alpha,\delta,(\text{input to that weight})$
Output layer: $$w_{35}^{new} = 0.6 + 0.5(0.07057)(0.5646) = 0.6 + 0.01992 = 0.6199$$ $$w_{45}^{new} = 0.7 + 0.5(0.07057)(0.5744) = 0.7 + 0.02027 = 0.7203$$
Hidden layer: $$w_{13}^{new} = 0.4 + 0.5(0.01041)(0.5) = 0.4 + 0.00260 = 0.4026$$ $$w_{23}^{new} = 0.2 + 0.5(0.01041)(0.3) = 0.2 + 0.00156 = 0.2016$$ $$w_{14}^{new} = 0.3 + 0.5(0.01208)(0.5) = 0.3 + 0.00302 = 0.3030$$ $$w_{24}^{new} = 0.5 + 0.5(0.01208)(0.3) = 0.5 + 0.00181 = 0.5018$$
Result of one iteration
| Weight | Old | New |
|---|---|---|
| $w_{13}$ | 0.4 | 0.4026 |
| $w_{23}$ | 0.2 | 0.2016 |
| $w_{14}$ | 0.3 | 0.3030 |
| $w_{24}$ | 0.5 | 0.5018 |
| $w_{35}$ | 0.6 | 0.6199 |
| $w_{45}$ | 0.7 | 0.7203 |
Output moved from $y = 0.6772$ toward target $t = 1.0$; repeating iterations reduces error.
Common mistake: treating $\delta = t - y = 0.3229$ as the output delta. The sigmoid derivative must be included, giving $\delta_{o1} = (t-y),y(1-y) = 0.0706$, and that is the value used in the weight updates. The forward pass gives $h_1 \approx 0.565$, $h_2 \approx 0.574$ and $y \approx 0.677$.
2081 ยท 5 marks
What is reinforcement learning? Configure an ANN neuron to simulate OR gate. [5]
Show solved answerHide answer
Reinforcement Learning and ANN Neuron for OR Gate
Given
This is a conceptual + design question. The relevant "data" is:
- Task 1: Define reinforcement learning.
- Task 2: Configure a single ANN neuron (perceptron) to implement the OR logic function.
- OR gate truth table (standard, not given but implied):
| $x_1$ | $x_2$ | $y$ |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
No numeric parameters are supplied; the weights, bias, and threshold must be chosen by design.
Solution
Part 1: Reinforcement Learning
Reinforcement Learning (RL) is a machine learning paradigm in which an agent learns to make decisions by interacting with an environment through trial and error. The agent performs actions, observes the resulting state, and receives a reward (positive) or penalty (negative) as feedback. Its goal is to learn a policy (a mapping from states to actions) that maximizes the cumulative reward over time.
Key elements:
| Element | Meaning |
|---|---|
| Agent | The learner / decision maker |
| Environment | The world the agent interacts with |
| State | Current situation of the agent |
| Action | Choice made by the agent |
| Reward | Feedback signal (reinforcement) |
| Policy | Strategy for choosing actions |
There is no labelled training data as in supervised learning; instead learning is guided by the reward signal.
Types:
- Positive reinforcement - a favourable outcome strengthens and increases the frequency of a behaviour.
- Negative reinforcement - removing an unfavourable condition strengthens a behaviour.
Examples: game-playing agents (chess, Go), robot navigation, recommendation systems.
Part 2: ANN Neuron (Perceptron) for OR Gate
A single neuron computes a weighted sum plus bias, then applies a step activation function:
$$ \text{Net} = w_1 x_1 + w_2 x_2 + b $$
$$ y = \begin{cases} 1 & \text{if } \text{Net} \ge 0 \ 0 & \text{if } \text{Net} < 0 \end{cases} $$
Chosen parameters:
$$ w_1 = 1,\qquad w_2 = 1,\qquad b = -0.5 $$
This is equivalent to using weights $w_1 = w_2 = 1$ with a threshold $\theta = 0.5$ (since $\text{Net} \ge 0 \Leftrightarrow w_1x_1 + w_2x_2 \ge 0.5$).
Verification:
| $x_1$ | $x_2$ | $\text{Net}=x_1+x_2-0.5$ | $\text{Net}\ge 0$? | Output $y$ | Required |
|---|---|---|---|---|---|
| 0 | 0 | $-0.5$ | No | 0 | 0 โ |
| 0 | 1 | $0.5$ | Yes | 1 | 1 โ |
| 1 | 0 | $0.5$ | Yes | 1 | 1 โ |
| 1 | 1 | $1.5$ | Yes | 1 | 1 โ |
All four outputs match the OR truth table.
Neuron diagram:
w1 = 1
x1 โโโโโโโโโโโโโ
โโโโบ[ ฮฃ + b ]โโโบ Step โโโบ y
x2 โโโโโโโโโโโโโ (b = -0.5)
w2 = 1
Result: With $w_1 = w_2 = 1$ and bias $b = -0.5$ (threshold $\theta = 0.5$), a single perceptron correctly realizes the OR gate.
Common mistake: stating bias $b = 0$ together with threshold $\theta = 0.5$. These are inconsistent: $b = 0$ corresponds to $\theta = 0$, and the bias matching $\theta = 0.5$ is $b = -0.5$. Applying the $\theta = 0.5$ rule in the verification table still gives the correct logical behaviour and weights.
2080 ยท 10 marks
What is the role of activation function in ANN. How sigmoid function works? Discuss about perceptron learning.[10]
2079 ยท 5 marks
Give an example of reinforcement learning. Explain the types of ANN. [5]
2078 ยท 10 marks
Describe mathematical model of neural network. What does it means to train a neural network? Write algorithm for preceptron learning.[10]
2076 ยท 10 marks
Define mathematical model of artificial neural network. Discuss how Hebbian learning algorithm can be used to train a neural network. Support your answer with an example.[10]
Supervised, Unsupervised and Reinforcement Learning
2081 ยท 5 marks
What is reinforcement learning? Configure an ANN neuron to simulate OR gate. [5]
Show solved answerHide answer
Reinforcement Learning and ANN Neuron for OR Gate
Given Data
- Task 1: Define reinforcement learning (conceptual).
- Task 2: Configure a single ANN neuron (perceptron) to simulate the OR gate.
- OR gate truth table (standard, boolean logic):
| $x_1$ | $x_2$ | $y = x_1 \lor x_2$ |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
No numeric parameters are supplied, so weights, bias, and threshold are to be designed.
Part 1: Reinforcement Learning
Reinforcement Learning (RL) is a machine learning paradigm in which an agent learns to make decisions by interacting with an environment. The agent performs actions, observes the resulting state, and receives feedback in the form of a reward (for good actions) or a penalty/punishment (for bad actions). The goal of the agent is to learn a policy (a mapping from states to actions) that maximizes the cumulative reward over time.
Unlike supervised learning, there is no labelled dataset; the agent learns purely by trial and error guided by reward signals.
Key elements:
| Component | Meaning |
|---|---|
| Agent | The learner / decision maker |
| Environment | The system the agent interacts with |
| State ($s$) | Current situation of the environment |
| Action ($a$) | Choice made by the agent |
| Reward ($r$) | Feedback signal (positive or negative) |
| Policy ($\pi$) | Strategy mapping states to actions |
Types of reinforcement:
- Positive reinforcement: rewarding desirable behaviour so it occurs more often.
- Negative reinforcement: removing an unpleasant condition to strengthen desirable behaviour.
Examples: game-playing agents (Chess, Go), robot navigation, recommendation systems.
Part 2: ANN Neuron (Perceptron) for OR Gate
A single neuron computes:
$$y = f!\left(\sum_i w_i x_i + b\right) = f(w_1 x_1 + w_2 x_2 + b)$$
Using a step activation function with threshold $\theta$:
$$f(net) = \begin{cases} 1 & \text{if } net \geq \theta \ 0 & \text{otherwise} \end{cases}$$
Chosen parameters
- $w_1 = 1$
- $w_2 = 1$
- Threshold $\theta = 1$ (equivalently bias $b = -1$ with firing condition $net \geq 0$)
Verification against truth table
Case 1: $x_1=0,\ x_2=0$ $$net = (1)(0)+(1)(0) = 0 < 1 \Rightarrow y = 0\ \checkmark$$
Case 2: $x_1=0,\ x_2=1$ $$net = (1)(0)+(1)(1) = 1 \geq 1 \Rightarrow y = 1\ \checkmark$$
Case 3: $x_1=1,\ x_2=0$ $$net = (1)(1)+(1)(0) = 1 \geq 1 \Rightarrow y = 1\ \checkmark$$
Case 4: $x_1=1,\ x_2=1$ $$net = (1)(1)+(1)(1) = 2 \geq 1 \Rightarrow y = 1\ \checkmark$$
All four outputs match the OR gate truth table.
Neuron diagram
x1 ---(w1=1)---\
(ฮฃ) --> net --> [Step, ฮธ=1] --> y
x2 ---(w2=1)---/
Conclusion
A single perceptron with $w_1 = 1$, $w_2 = 1$, and threshold $\theta = 1$ (bias $b = -1$) correctly simulates the OR gate.
2080.1 ยท 10 marks
Differentiate supervised learning from unsupervised? Discuss how Naive Bayes Model can be used for machine learning? Support your answer with example.[10]
Learning by Genetic Algorithm
2080 ยท 5 marks
Define selection, crossover, and mutation operations in genetic algorithm. [5]
2078 ยท 5 marks
What is iscrossver operation in genetic algorithm? Given following chromosomes show the result of one-point and two point crossover. C1 = 01100010, C2 = 10101100. Choose appropriate crossover points as per your own suggestions. [5]
Show solved answerHide answer
Crossover Operation in Genetic Algorithm
Given Data
- Chromosome $C_1 = 01100010$
- Chromosome $C_2 = 10101100$
- Each chromosome has 8 bits.
- Crossover points to be chosen by student.
Position indexing:
C1 = 0 1 1 0 0 0 1 0
C2 = 1 0 1 0 1 1 0 0
1 2 3 4 5 6 7 8
Definition of Crossover
Crossover (also called recombination) is a genetic operator in a Genetic Algorithm that combines the genetic material of two parent chromosomes to produce one or more offspring. Two parents are selected from the mating pool, one or more crossover points are chosen, and the segments of the parents are exchanged around these points. Crossover is the primary operator responsible for exploring new regions of the search space by recombining good building blocks (schemas) from both parents, thereby helping the population converge toward better solutions.
One-Point Crossover
Chosen crossover point: after position 4.
Split at position 4:
| Chromosome | Head (pos 1-4) | Tail (pos 5-8) |
|---|---|---|
| $C_1$ | 0110 | 0010 |
| $C_2$ | 1010 | 1100 |
Swap the tails:
C1 = 0110 | 0010
C2 = 1010 | 1100
^ (cut after position 4)
O1 = 0110 | 1100 = 01101100
O2 = 1010 | 0010 = 10100010
Offspring: $O_1 = 01101100$, $O_2 = 10100010$.
Verification of bit copy:
- O1 head = C1 head
0110โ; O1 tail = C2 tail1100โ - O2 head = C2 head
1010โ; O2 tail = C1 tail0010โ
Two-Point Crossover
Chosen crossover points: after position 2 and after position 6.
Split into three segments:
| Chromosome | Seg 1 (1-2) | Seg 2 (3-6) | Seg 3 (7-8) |
|---|---|---|---|
| $C_1$ | 01 | 1000 | 10 |
| $C_2$ | 10 | 1011 | 00 |
Check the middle segment of C1 (pos 3-6): C1 = 0 1 1 0 0 0 1 0 โ 1000 โ
Middle segment of C2 (pos 3-6): C2 = 1 0 1 0 1 1 0 0 โ 1011 โ
Swap the middle segment:
C1 = 01 | 1000 | 10
C2 = 10 | 1011 | 00
^ ^
cut after 2 cut after 6
O1 = 01 | 1011 | 10 = 01101110
O2 = 10 | 1000 | 00 = 10100000
Offspring: $O_1 = 01101110$, $O_2 = 10100000$.
Summary Table
| Operation | Crossover Points | Offspring 1 | Offspring 2 |
|---|---|---|---|
| One-Point | after pos 4 | 01101100 | 10100010 |
| Two-Point | after pos 2 & 6 | 01101110 | 10100000 |
Crossover recombines features of both parents to generate new candidate solutions, which is essential for the genetic algorithm to search effectively and converge toward an optimal solution.
2076 ยท 5 marks
Write an algorithm for learning by Genetic Approach. [5]
Make Unit 5 stick
Practice CSC266 with flashcards & quizzes