This is an introduction to artificial neural networks (ANNs) including the idea of classification and how ANNs can classify data into number of distinct classes based on some features.
A basic neural network example is given that uses a single layer perceptron with three inputs and one output to classify data linearly using the Signum activation function.
The presented example is about classifying data about colors into two categories (Red and Blue).
Artificial neural networks (ANNs) or connectionist systems are a computational model used in machine learning, computer science and other research disciplines, which is based on a large collection of connected simple units called artificial neurons, loosely analogous to axons in a biological brain. Connections between neurons carry an activation signal of varying strength. If the combined incoming signals are strong enough, the neuron becomes activated and the signal travels to other neurons connected to it. Such systems can be trained from examples, rather than explicitly programmed, and excel in areas where the solution or feature detection is difficult to express in a traditional computer program. Like other machine learning methods, neural networks have been used to solve a wide variety of tasks, like computer vision and speech recognition, that are difficult to solve using ordinary rule-based programming.
Find me on:
AFCIT
http://www.afcit.xyz
YouTube
https://www.youtube.com/channel/UCuewOYbBXH5gwhfOrQOZOdw
Google Plus
https://plus.google.com/u/0/+AhmedGadIT
SlideShare
https://www.slideshare.net/AhmedGadFCIT
LinkedIn
https://www.linkedin.com/in/ahmedfgad/
ResearchGate
https://www.researchgate.net/profile/Ahmed_Gad13
Academia
https://www.academia.edu/
Google Scholar
https://scholar.google.com.eg/citations?user=r07tjocAAAAJ&hl=en
Mendelay
https://www.mendeley.com/profiles/ahmed-gad12/
ORCID
https://orcid.org/0000-0003-1978-8574
StackOverFlow
http://stackoverflow.com/users/5426539/ahmed-gad
Twitter
https://twitter.com/ahmedfgad
Facebook
https://www.facebook.com/ahmed.f.gadd
Pinterest
https://www.pinterest.com/ahmedfgad/
Introduction to Artificial Neural Networks (ANNs) - Step-by-Step Training & Testing Example
1. Artificial Neural Networks (ANNs)
Step-By-Step Training & Testing Example
MENOUFIA UNIVERSITY
FACULTY OF COMPUTERS AND INFORMATION
ALL DEPARTMENTS
ARTIFICIAL INTELLIGENCE
المنوفية جامعة
والمعلومات الحاسبات كلية
األقسام جميع
الذكاءاإلصطناعي
المنوفية جامعة
Ahmed Fawzy Gad
ahmed.fawzy@ci.menofia.edu.eg
27. Activation Function
Inputs
B (BLUE)G (GREEN)R (RED)
00255
RED
6880248
25500
BLUE
2101567
Input Output
R
G
B
RED/BLUE
W1
W2
W3
ss=SOP(𝑿𝒊, 𝑾𝒊)
𝑿𝒊=Inputs 𝑾𝒊=Weights
𝒀𝒋
28. Activation Function
Inputs
B (BLUE)G (GREEN)R (RED)
00255
RED
6880248
25500
BLUE
2101567
Input Output
R
G
B
RED/BLUE
W1
W2
W3
ss=SOP(𝑿𝒊, 𝑾𝒊)
𝑿𝒊=Inputs 𝑾𝒊=Weights
𝑿 𝟏
𝑿 𝟐
𝑿 𝟑
𝒀𝒋
29. Activation Function
Inputs
B (BLUE)G (GREEN)R (RED)
00255
RED
6880248
25500
BLUE
2101567
Input Output
R
G
B
RED/BLUE
W1
W2
W3
ss=SOP(𝑿𝒊, 𝑾𝒊)
𝑿𝒊=Inputs 𝑾𝒊=Weights
𝑿 𝟏
𝑿 𝟐
𝑿 𝟑 S= 𝟏
𝒎
𝑿𝒊 𝑾𝒊
𝒀𝒋
30. Activation Function
Inputs
B (BLUE)G (GREEN)R (RED)
00255
RED
6880248
25500
BLUE
2101567
Input Output
R
G
B
RED/BLUE
W1
W2
W3
ss=SOP(𝑿𝒊, 𝑾𝒊)
𝑿𝒊=Inputs 𝑾𝒊=Weights
𝑿 𝟏
𝑿 𝟐
𝑿 𝟑
s=(𝑿 𝟏 𝑾 𝟏+𝑿 𝟐 𝑾 𝟐+𝑿 𝟑 𝑾 𝟑)
S= 𝟏
𝒎
𝑿𝒊 𝑾𝒊
𝒀𝒋
31. Activation Function
Outputs
B (BLUE)G (GREEN)R (RED)
00255
RED
6880248
25500
BLUE
2101567
Input Output
R
G
B
RED/BLUE
W1
W2
W3
F(s)s
𝑿 𝟏
𝑿 𝟐
𝑿 𝟑
Class Label
𝒀𝒋
33. Activation Functions
Which activation function to use?
B (BLUE)G (GREEN)R (RED)
00255
RED
6880248
25500
BLUE
2101567
Outputs
Class
Labels
Activation
Function
TWO Class
Labels
TWO
Outputs
One that gives two outputs.
B (BLUE)G (GREEN)R (RED)
00255
RED 6880248
25500
BLUE 2101567
Which activation function to use?
𝑪𝒋𝒀𝒋
67. Neural Networks Training Steps
Weights Initialization
Inputs Application
Sum of Inputs-Weights Products
Activation Function Response Calculation
Weights Adaptation
Back to Step 2
1
2
3
4
5
6
68. Regarding 5th Step: Weights Adaptation
• If the predicted output Y is not the same as the desired output d,
then weights are to be adapted according to the following equation:
𝑾 𝒏 + 𝟏 = 𝑾 𝒏 + η 𝒅 𝒏 − 𝒀 𝒏 𝑿(𝒏)
Where
𝑾 𝒏 = [𝒃 𝒏 , 𝑾 𝟏(𝒏), 𝑾 𝟐(𝒏), 𝑾 𝟑(𝒏), … , 𝑾 𝒎(𝒏)]
69. Neural Networks
Training Example
Step n=0
• In each step in the solution, the parameters of the neural network
must be known.
• Parameters of step n=0:
η = .001
𝑋 𝑛 = 𝑋 0 = +1, 255, 0, 0
𝑊 𝑛 = 𝑊 0 = −1, −2, 1, 6.2
𝑑 𝑛 = 𝑑 0 = −1
B (BLUE)G (GREEN)R (RED)
00255
RED = -1
6880248
25500
BLUE = +1
2101567
70. Neural Networks
Training Example
Step n=0
255
0
0
-2
1
6.2
𝑿 𝟏
𝑿 𝟐
𝑿 𝟑
F(s)s sgn
=+1𝑿 𝟎
-1
RED/BLUE
𝒀(𝒏)
B (BLUE)G (GREEN)R (RED)
00255
RED = -1
6880248
25500
BLUE = +1
2101567
73. Neural Networks
Training Example
Step n=0 - Output
255
0
0
-2
1
6.2
𝑿 𝟏
𝑿 𝟐
𝑿 𝟑
-511 −𝟏
=+1𝑿 𝟎
-1
𝒀 𝒏 = 𝒀 𝟎
= 𝑺𝑮𝑵 𝒔
= 𝑺𝑮𝑵 −𝟓𝟏𝟏
= −𝟏
-1
RED
B (BLUE)G (GREEN)R (RED)
00255
RED = -1
6880248
25500
BLUE = +1
2101567
74. Neural Networks
Training Example
Step n=0
Predicted Vs. Desired
255
0
0
-2
1
6.2
𝑿 𝟏
𝑿 𝟐
𝑿 𝟑
-511 −𝟏
=+1𝑿 𝟎
-1
-1
𝒀 𝒏 = 𝒀 𝟎 = −𝟏
𝐝 𝒏 = 𝒅 𝟎 = −𝟏
∵ 𝒀 𝒏 = 𝒅 𝒏
∴ Weights are Correct.
No Adaptation
B (BLUE)G (GREEN)R (RED)
00255
RED = -1
6880248
25500
BLUE = +1
2101567
75. Neural Networks
Training Example
Step n=1
• In each step in the solution, the parameters of the neural network
must be known.
• Parameters of step n=1:
η = .001
𝑋 𝑛 = 𝑋 1 = +1, 248, 80, 68
𝑊 𝑛 = 𝑊 1 = 𝑊 0 = −1, −2, 1, 6.2
𝑑 𝑛 = 𝑑 1 = −1
B (BLUE)G (GREEN)R (RED)
00255
RED = -1
6880248
25500
BLUE = +1
2101567
76. Neural Networks
Training Example
Step n=1
248
80
68
RED/BLUE
-2
1
6.2
𝑿 𝟏
𝑿 𝟐
𝑿 𝟑
F(s)s sgn
=+1𝑿 𝟎
-1
𝒀(𝒏)
B (BLUE)G (GREEN)R (RED)
00255
RED = -1
6880248
25500
BLUE = +1
2101567
82. Neural Networks
Training Example
Step n=2
• In each step in the solution, the parameters of the neural network
must be known.
• Parameters of step n=2:
η = .001
𝑋 𝑛 = 𝑋 2 = +1, 0, 0, 255
𝑊 𝑛 = 𝑊 2 = −1.002, −2.496, .84, 6.064
𝑑 𝑛 = 𝑑 2 = +1
B (BLUE)G (GREEN)R (RED)
00255
RED = -1
6880248
25500
BLUE = +1
2101567
83. Neural Networks
Training Example
Step n=2
0
0
255
RED/BLUE
𝑿 𝟏
𝑿 𝟐
𝑿 𝟑
F(s)s sgn
=+1𝑿 𝟎
𝒀(𝒏)
B (BLUE)G (GREEN)R (RED)
00255
RED = -1
6880248
25500
BLUE = +1
2101567
6.064
.84
-2.496
-1.002
86. Neural Networks
Training Example
Step n=2 - Output
0
0
255
𝑿 𝟏
𝑿 𝟐
𝑿 𝟑
1545
.32 +𝟏
=+1𝑿 𝟎
𝒀 𝒏 = 𝒀 𝟐
= 𝑺𝑮𝑵 𝒔
= 𝑺𝑮𝑵 1545.32
= +𝟏
+1
BLUE
B (BLUE)G (GREEN)R (RED)
00255
RED = -1
6880248
25500
BLUE = +1
2101567
6.064
.84
-2.496
-1.002
87. Neural Networks
Training Example
Step n=2
Predicted Vs. Desired
0
0
255
𝑿 𝟏
𝑿 𝟐
𝑿 𝟑
1545
.32 +𝟏
=+1𝑿 𝟎
+1
𝒀 𝒏 = 𝒀 𝟐 = +𝟏
𝐝 𝒏 = 𝒅 𝟐 = +𝟏
∵ 𝒀 𝒏 = 𝒅 𝒏
∴ Weights are Correct.
No Adaptation
B (BLUE)G (GREEN)R (RED)
00255
RED = -1
6880248
25500
BLUE = +1
2101567
6.064
.84
-2.496
-1.002
88. Neural Networks
Training Example
Step n=3
• In each step in the solution, the parameters of the neural network
must be known.
• Parameters of step n=3:
η = .001
𝑋 𝑛 = 𝑋 3 = +1, 67, 15, 210
𝑊 𝑛 = 𝑊 3 = 𝑊 2 = −1.002, −2.496, .84, 6.064
𝑑 𝑛 = 𝑑 3 = +1
B (BLUE)G (GREEN)R (RED)
00255
RED = -1
6880248
25500
BLUE = +1
2101567
89. Neural Networks
Training Example
Step n=3
67
15
210
RED/BLUE
𝑿 𝟏
𝑿 𝟐
𝑿 𝟑
F(s)s sgn
=+1𝑿 𝟎
𝒀(𝒏)
B (BLUE)G (GREEN)R (RED)
00255
RED = -1
6880248
25500
BLUE = +1
2101567
6.064
.84
-2.496
-1.002
92. Neural Networks
Training Example
Step n=3 - Output
𝑿 𝟏
𝑿 𝟐
𝑿 𝟑
1349
.542 +𝟏
=+1𝑿 𝟎
𝒀 𝒏 = 𝒀 𝟑
= 𝑺𝑮𝑵 𝒔
= 𝑺𝑮𝑵 1349.542
= +𝟏
+1
BLUE
B (BLUE)G (GREEN)R (RED)
00255
RED = -1
6880248
25500
BLUE = +1
2101567
6.064
.84
-2.496
-1.002
67
15
210
93. Neural Networks
Training Example
Step n=3
Predicted Vs. Desired
𝑿 𝟏
𝑿 𝟐
𝑿 𝟑
1349
.542 +𝟏
=+1𝑿 𝟎
+1
𝒀 𝒏 = 𝒀 𝟑 = +𝟏
𝐝 𝒏 = 𝒅 𝟑 = +𝟏
∵ 𝒀 𝒏 = 𝒅 𝒏
∴ Weights are Correct.
No Adaptation
B (BLUE)G (GREEN)R (RED)
00255
RED = -1
6880248
25500
BLUE = +1
2101567
6.064
.84
-2.496
-1.002
67
15
210
94. Neural Networks
Training Example
Step n=4
• In each step in the solution, the parameters of the neural network
must be known.
• Parameters of step n=4:
η = .001
𝑋 𝑛 = 𝑋 4 = +1, 255, 0, 0
𝑊 𝑛 = 𝑊 4 = 𝑊 3 = −1.002, −2.496, .84, 6.064
𝑑 𝑛 = 𝑑 4 = −1
B (BLUE)G (GREEN)R (RED)
00255
RED = -1
6880248
25500
BLUE = +1
2101567
95. Neural Networks
Training Example
Step n=4
255
0
0
𝑿 𝟏
𝑿 𝟐
𝑿 𝟑
F(s)s sgn
=+1𝑿 𝟎
RED/BLUE
𝒀(𝒏)
B (BLUE)G (GREEN)R (RED)
00255
RED = -1
6880248
25500
BLUE = +1
2101567
6.064
.84
-2.496
-1.002
98. Neural Networks
Training Example
Step n=4 - Output
255
0
0
𝑿 𝟏
𝑿 𝟐
𝑿 𝟑
-
637.
482
−𝟏
=+1𝑿 𝟎
𝒀 𝒏 = 𝒀 𝟒
= 𝑺𝑮𝑵 𝒔
= 𝑺𝑮𝑵 −637.482
= −𝟏
-1
RED
B (BLUE)G (GREEN)R (RED)
00255
RED = -1
6880248
25500
BLUE = +1
2101567
6.064
.84
-2.496
-1.002
99. Neural Networks
Training Example
Step n=4
Predicted Vs. Desired
255
0
0
𝑿 𝟏
𝑿 𝟐
𝑿 𝟑
-
637.
482
−𝟏
=+1𝑿 𝟎
-1
𝒀 𝒏 = 𝒀 𝟒 = −𝟏
𝐝 𝒏 = 𝒅 𝟒 = −𝟏
∵ 𝒀 𝒏 = 𝒅 𝒏
∴ Weights are Correct.
No Adaptation
B (BLUE)G (GREEN)R (RED)
00255
RED = -1
6880248
25500
BLUE = +1
2101567
6.064
.84
-2.496
-1.002
100. Neural Networks
Training Example
Step n=5
• In each step in the solution, the parameters of the neural network
must be known.
• Parameters of step n=5:
η = .001
𝑋 𝑛 = 𝑋 5 = +1, 248, 80, 68
𝑊 𝑛 = 𝑊 5 = 𝑊 4 = −1.002, −2.496, .84, 6.064
𝑑 𝑛 = 𝑑 5 = −1
B (BLUE)G (GREEN)R (RED)
00255
RED = -1
6880248
25500
BLUE = +1
2101567
101. Neural Networks
Training Example
Step n=5
248
80
68
𝑿 𝟏
𝑿 𝟐
𝑿 𝟑
F(s)s sgn
=+1𝑿 𝟎
RED/BLUE
𝒀(𝒏)
B (BLUE)G (GREEN)R (RED)
00255
RED = -1
6880248
25500
BLUE = +1
2101567
6.064
.84
-2.496
-1.002
104. Neural Networks
Training Example
Step n=5 - Output
𝑿 𝟏
𝑿 𝟐
𝑿 𝟑
-
31.3
06
−𝟏
=+1𝑿 𝟎
𝒀 𝒏 = 𝒀 𝟓
= 𝑺𝑮𝑵 𝒔
= 𝑺𝑮𝑵 −31.306
= −𝟏
-1
RED
B (BLUE)G (GREEN)R (RED)
00255
RED = -1
6880248
25500
BLUE = +1
2101567
6.064
.84
-2.496
-1.002
248
80
68
105. Neural Networks
Training Example
Step n=5
Predicted Vs. Desired
𝑿 𝟏
𝑿 𝟐
𝑿 𝟑
-
637.
482
−𝟏
=+1𝑿 𝟎
-1
𝒀 𝒏 = 𝒀 𝟓 = −𝟏
𝐝 𝒏 = 𝒅 𝟓 = −𝟏
∵ 𝒀 𝒏 = 𝒅 𝒏
∴ Weights are Correct.
No Adaptation
B (BLUE)G (GREEN)R (RED)
00255
RED = -1
6880248
25500
BLUE = +1
2101567
6.064
.84
-2.496
-1.002
248
80
68
106. Correct Weights
• After testing the weights across all samples and results were correct
then we can conclude that current weights are correct ones for
training the neural network.
• After training phase we come to testing the neural network.
• What is the class of the unknown color of values of R=150, G=100,
B=180?