Lecture 4 ANN PDF
Lecture 4 ANN PDF
Lecture 4 ANN PDF
Lecture 4
Content
-Leaning Rule
Multilayer Perceptron
1
3/22/2023
x2 wi2
wTi x( k ) yi( k ) a wTi x ( k )
.
.
.
xm wim
1 p (k ) 1 p
2
Minimize E (w) d ( k ) a(wT x( k ) )
(k ) 2
( d y )
2 k 1 2 k 1
E (w ) p
(d ( k ) y ( k ) )x (jk ) y ( k ) (1 y ( k ) )
T
E (w ) E (w ) E (w )
w E (w ) , , , w j k 1
w1 w2 wm p
( k ) x(jk ) y ( k ) (1 y ( k ) )
k 1
w w E(w) p
w j ( k ) x (jk ) y ( k ) (1 y ( k ) )
k 1
Faculty of Engineering-Cairo University 3
Training Set
T (x(1) , d(1) ), (x( 2) , d( 2) ),, (x( p ) , d( p ) )
o1 o2 on
d1 d2 dn
Output Layer . . .
. . .
Hidden Layer
. . .
Input Layer . . .
x1 x2 xs
Faculty of Engineering-Cairo University 5
2
3/22/2023
Supervised Learning
Training Set
T (x(1) , d(1) ), (x( 2) , d( 2) ),, (x( p ) , d( p ) )
Sum of Squared Errors o1 o2 on
d1 d2 dn
. . .
E (l )
2 j 1
1 n (l )
d j o (jl ) 2
. . .
n: Number of outputs
Goal: . . .
p
Minimize E E (l )
. . .
l 1
x1 x2 xs
p: Number of patterns`
1 n (l )
p
d j o (jl ) E E (l )
(l ) 2
E
2 j 1 l 1
o1 o2 on
d1 d2 dn
Learning on Output Neurons . . .
Learning on Hidden Neurons
. . .
. . .
. . .
x1 x2 xs
Faculty of Engineering-Cairo University 7
3
3/22/2023
1 n
d (jl ) o (jl )
p
E
2
E (l ) E (l )
2 j 1 l 1
1 n
d (jl ) o (jl )
p
E
2
E (l ) E (l )
2 j 1 l 1
net (jl ) o (jl ) net (jl )
. . . . . .
depends on the
(d (jl ) o (jl ) ) activation function
Faculty of Engineering-Cairo University 9
4
3/22/2023
1 n
d (jl ) o (jl )
p
E
2
E (l ) E (l )
2 j 1 l 1
net (jl ) o (jl ) net (jl )
. . . . . . Using sigmoid,
E (l )
(j l ) (d (j l ) o(jl ) ) o(jl ) (1 o(jl ) )
net (jl )
o1 oj on o (jl ) a(net (jl ) )
net (jl ) ( l ) w o(l )
ji i
d1 dj dn j
. . . j . . . E p p
E (l )
w ji w ji
E
l 1
(l )
l 1 w ji
wji
E (l ) E (l ) net j
(l )
. . . i . . .
w ji net (jl ) w ji
. . . . . . E (l ) E (l ) o j
(l )
net (jl ) o (jl ) net (jl )
. . . . . . Using sigmoid,
5
3/22/2023
1 n
d (jl ) o (jl )
p
E
2
E (l ) E (l )
2 j 1 l 1
E
2
E (l ) E (l )
2 j 1 l 1
w ji net (jl ) w ji
E p oi(l )
.
. . j . o.i .
(l ) (l )
w ji l 1 E ( l )
(j l ) oi( l )
w ji
. . . p
w ji (j l ) oi(l )
. . .
(d (j l ) o(jl ) ) o(jl ) (1 o(jl ) )oi(l )
l 1
Faculty of Engineering-Cairo University 13
6
3/22/2023
1 n
d (jl ) o (jl )
p
E
2
E (l ) E (l )
2 j 1 l 1
E p p
E (l )
. . . j . . .
wik wik
E (l )
l 1 l 1 wik
wji E E net
(l ) (l ) (l )
i
wik neti(l ) wik
. . . i . . .
wik
. . .k . . .
? ?
. . . . . .
1 n
d (jl ) o (jl )
p
E
2
E (l ) E (l )
2 j 1 l 1
i(l )
E p p
E (l )
. . . j . . .
wik wik
E (l )
l 1 l 1 wik
wji E (l ) E (l ) neti(l )
wik neti(l ) wik
. . . i . . . ok(l )
wik
. . . k . . .
. . . . . .
7
3/22/2023
E
2
E (l ) E (l )
2 j 1 l 1
i(l )
E p p
E (l )
. . . j . . .
wik wik
E (l )
l 1 l 1 wik
wji E E net
(l ) (l ) (l )
i
wik neti(l ) wik
. . . i . . . ok(l )
wik E (l ) E (l ) oi(l )
. . .k . . . neti(l ) oi(l ) neti(l )
? oi(l ) (1 oi(l ) )
. . . . . .
i(l )
E (l )
oi( l ) (1 oi( l ) ) w ji (j l ) i(l )
neti(l )
E E (l )
j p p
. . . j . . .
wik wik
E
l 1
(l )
l 1 wik
wji E (l ) E (l ) neti(l )
wik neti(l ) wik
. . . i . . . ok(l )
wik E (l ) E (l ) oi(l )
(l )
. . .k . . . neti (l )
oi neti(l )
oi(l ) (1 oi(l ) )
E E net
(l ) (l ) (l )
j
. . . . . .
oi
(l )
j net j
(l )
o (l )
i
(lj ) w ji
Faculty of Engineering-Cairo University 17
8
3/22/2023
E (l )
i(l ) oi( l ) (1 oi( l ) ) w ji (j l )
neti(l )
E E (l )
j p p
. . . j . . .
wik wik
E
l 1
(l )
l 1 wik
wji E (l ) E (l ) neti(l )
wik neti(l ) wik
. . . i . . . ok(l )
wik E p
. . .k . . . i(l ) ok(l )
wik l 1
. . . . . . p
wik i(l ) ok(l )
l 1
Back Propagation
o1 oj on
d1 dj dn
. . . j . . .
. . . i . . .
. . . k . . .
. . . . . .
x1 . . . xs
Faculty of Engineering-Cairo University 19
9
3/22/2023
Back Propagation
E (l )
(j l ) (d (j l ) o(jl ) )o(jl ) (1 o(jl ) )
net (jl )
o1 oj on
d1 dj dn
. . . j . . . p
w ji (j l ) oi(l )
l 1
. . . i . . .
. . . k . . .
. . . . . .
x1 . . . xs
Faculty of Engineering-Cairo University 20
Back Propagation
E (l )
(j l ) (d (j l ) o(jl ) )o(jl ) (1 o(jl ) )
net (jl )
o1 oj on
d1 dj dn
. . . j . . . p
w ji (j l ) oi(l )
l 1
. . . i . . . p
wik i(l ) ok(l )
l 1
. . . k . . .
. . . E (l )
oi( l ) (1 oi( l ) ) w ji (j l )
. . .
i(l )
neti(l ) j
x1 . . . xs
Faculty of Engineering-Cairo University 21
10
3/22/2023
Step 1: Initialisation
Set all the weights and threshold levels of the
network to random numbers. You can use MATLAB
command “randn”: X = randn(n,m)
s
Oi ( p ) sigmoid xk ( p ) wik ( p ) i
k 1
where s is the number of inputs to neuron i in the hidden layer.
(b) Calculate the actual outputs of the neurons in the output layer:
m
O j ( p ) sigmoid Oi ( p ) w ji ( p ) j
i 1
11
3/22/2023
12
3/22/2023
Step 4: Iteration
Increase iteration p by one, go back to Step 2 and
repeat the process until the selected error criterion is
satisfied.
Initialize all
weights &biases Last pattern?
No
yes
Enter
Calculate total 𝐸
pattern{X(p),𝑑𝑗 } No
Calculate 𝑂𝑗 , 𝑂𝑖 𝐸 < 𝜖?
Calculate 𝛿𝑗 , 𝛿𝑖 yes
Stop
Update weights
𝑤𝑗𝑖 , 𝑤𝑖𝑘
13
3/22/2023
Example : XOR
3
w13 1
x1 1 3 w35
w23 5
5 y5
W14
x2 2 4 w45
w24
Input 4 Output
layer layer
1
Hidden layer
Faculty of Engineering-Cairo University 28
Example : XOR
14
3/22/2023
Example : XOR
We consider a training set where inputs x1 and x2 are
equal to 1 and desired output yd,5 is 0. The actual
outputs of neurons 3 and 4 in the hidden layer are
calculated as
y3 sigmoid( x1w13 x2 w23 3 ) 1 / 1 e(10.510.410.8) 0.5250
y4 sigmoid( x1w14 x2 w24 ) 1 / 1 e
4
(10.9 11.0 10.1)
0.8808
Now the actual output of neuron 5 in the output layer is
determined as:
y5 sigmoid( y3w35 y4 w45 5 ) 1 / 1 e (0.52501.20.88081.110.3) 0.5097
e yd ,5 y5 0 0.5097 0.5097
Faculty of Engineering-Cairo University 30
Example : XOR
15
3/22/2023
Example : XOR
Example : XOR
16
3/22/2023
Example : XOR
100
Sum-Squared Error
10-1
10-2
10-3
10-4
0 50 100 150 200
Epoch
Example : XOR
17
3/22/2023
+1.5
1
+1.0
x1 1 3 2.0 +0.5
+1.0
5 y5
+1.0
x2 2 +1.0
4
+1.0
+0.5
1
Faculty of Engineering-Cairo University 36
18
3/22/2023
Accelerated learning
w jk ( p) w jk ( p 1) y j ( p) k ( p)
100
Sum-Squared Error
1
10
10-3
100
10-1
10-4
0 50 100 150 200
Epoch 10-2
10-3
Without momentum term 10-4
0 20 40 60 80 100 120
Epoch
1.5
1
Learning Rate
0.5
-0.5
-1
0 20 40 60 80 100 120 140
Epoch
19
3/22/2023
101
100
10-1
10-2
10-3
10-4
0 10 20 30 40 50 60 70 80 90 100
Epoch
1
0.8
Learning Rate
0.6
0.4
0.2
0
0 20 40 60 80 100 120
Epoch
20
3/22/2023
2
Learning Rate
1.5
0.5
0
0 10 20 30 40 50 60 70 80 90
Epoch
Learning Factors
Initial Weights
Learning Constant ()
Cost Functions
Update Rules
Training Data and Generalization
Number of Layers
Number of Hidden Nodes
21