Modue 2 - Back Propagation Algorithm-Updated
Modue 2 - Back Propagation Algorithm-Updated
NETWORK
BY
ASST. PROF. S. S. SONTAKKE
&
ASST. PROF. N. L. MUDEGOL
HOW BPN WORKS?
• inputs x, arrive through the preconnected path
• input is modeled using real weights W. the weights are
usually randomly selected.
• calculate the output for every neuron from the input layer,
to the hidden layers, to the output layer.
• calculate the error in the outputs
error= actual output – desired output
• travel back from the output layer to the hidden layer to
adjust the weights such that the error is decreased.
• keep repeating the process until the desired output is
achieved
WHY WE NEED
BACKPROPAGATION?
• It is fast, simple and easy to program
• It has no parameters to tune apart from the numbers of input
• It is a flexible method as it does not require prior knowledge
about the network
• It is a standard method that generally works well
• It does not need any special mention of the features of the
function to be learned.
• It is especially useful for deep neural networks working on
error-prone projects, such as image or speech recognition.
• It takes advantage of the chain and power rules allows it to
function with any number of outputs.
MULTI LAYER FEED
FORWARD NETWORK (BPN)
Input Layer Hidden Layer Output Layer
. . .
. . .
. . .
OI No 4
Output of 4
Input Neuron
IH1 No 1
Input of
Hidden Neuron
OH5 No 5
Output of
Hidden Neuron
IO1 No 1
Input of
Output Neuron
OO3 No 3
Output of
Output Neuron
MULTI LAYER FEED
FORWARD NETWORK (BPN)
Input Layer Hidden Layer Output Layer
V21 W12
II2 OO2
2
V22 2 W22 2
V32 W23
II3 V33 W33 OO3
3 3 3
V is the weight on the link from ith input neuron to jth hidden neuron.
Weight
Between Input
Vij jth Hidden
Neuron
and Hidden
Neuron ith input
Neuron
Weight
Between Input
V25 5th Hidden
Neuron
and Hidden
Neuron 2nd input
Neuron
W is the weight on the link from ith Hidden neuron to jth Output neuron.
Weight
Between
Wij jth Output
Neuron
Hidden and
Output Neuron ith Hidden
Neuron
Weight
Between
W43 3rd Output
Neuron
Hidden and
Output Neuron 4th Hidden
Neuron
INTRODUCTION
• THREE PHASES:
• FEED FORWARD
• BACK PROPAGATION OF ERROR
• WEIGHT UPDATION
STEP 1:
Initialize weights and learning rate to a small random
values.
STEP 2:
Perform steps 3-17 until stopping condition is false.
STEP 3:
Perform steps 4-16 for each training pair.
PHASE – 1
FEED-FORWARD
PHASE-1: FEED-FORWARD PHASE
STEP 4: OUTPUT OF INPUT LAYER
Present each input pair to input layer. Apply linear
activation function to it.
i.e. 𝜙 𝐼 =𝑥 𝑓𝑜𝑟 𝑎𝑙𝑙 𝑥
p = 1, 2, . . ., m
We shall have ‘m’ such outputs which will be passed to the output
layer.
PHASE-1: FEED-FORWARD PHASE
STEP 7: INPUT FOR OUTPUT LAYER
Compute the net Input for each output neuron.
σ𝑛
𝐼𝑂𝑞 = 𝑖=1 𝑊𝑖𝑗 𝑂𝐻𝑖
j = q and q = 1, 2, . . .n
Note: Bias can be same for all inputs or different for each hidden
layer.
PHASE-1: FEED-FORWARD PHASE
STEP 8: OUTPUT OF OUTPUT LAYER
Output of output layer can be computed by applying binary
sigmoidal function on it’s input.
We shall have ‘n’ such outputs which will be passed to the output
layer.
(In case of logic gates n = 1)
PHASE – 2
ERROR BACK-PROPAGATION
PHASE-2: ERROR BACK-PROPAGATION PHASE
STEP 9: ERROR CALCULATION
For given training pair, calculate the difference between desired
output and actual output.
r = 1, 2, …, n
PHASE-2: ERROR BACK-PROPAGATION PHASE
STEP 10: CALCULATION OF DERIVATIVE OF OUTPUT
Calculate the derivative of the output of output layer.
r = 1, 2, …, n
𝐸𝑂𝑟 = 𝑒𝑟 𝑑𝑂𝑟
= (𝑂𝑡𝑎𝑟𝑔𝑒𝑡𝑟 − 𝑂𝑎𝑐𝑡𝑢𝑎𝑙𝑟 )(1 − 𝑂𝑂𝑟 )(𝑂𝑂𝑟 )
r = 1, 2, …, n
And
Where,
𝛼 = Learning rate
PHASE-2: ERROR BACK-PROPAGATION PHASE
STEP 13: DELTA INPUTS TO HIDDEN LAYER
Compute the delta inputs to every hidden layer.
Where,
We shall have ‘m’ such a delta inputs which will be passed to hidden
layer.
PHASE-2: ERROR BACK-PROPAGATION PHASE
STEP 14: CHANGE IN WEIGHTS AND BIAS
Calculate change in weights and bias between input and hidden
layer.
And
Where,
𝛼 = Learning rate
PHASE – 3
WEIGHT AND BIAS UPDATE
PHASE-3: WEIGHT UPDATION PHASE
STEP 15: UPDATE WEIGHTS AND BIAS
Update the weights and bias between hidden and output layer.
And
PHASE-3: WEIGHT UPDATION PHASE
STEP 16: UPDATE WEIGHTS AND BIAS
Update the weights and bias between input and hidden layer.
And
PHASE-3: WEIGHT UPDATION PHASE
STEP 17:
Check for the stopping condition.
A stopping condition may be certain number of epochs (iterations) or
when actual output matches with the targets output.
STOPPING CONDITION:
Compute the Error Norm as follows:
𝐸𝑁𝑘 = 1ൗ2 𝑒𝑘 2
For every training pair,
n = total outputs
n = total outputs
SOLVED EXAMPLE:
I1 0.1
0.2
0.4 -0.2
O
I2 -0.5
0.2
Given:
I1 = 0.4, I2 = -0.7
V11 = 0.1, V12 = 0.4, V21 = -0.2, V22 = 0.2
W11 = 0.2, W21 = -0.5
a=1
1. Output of Input Layer will be same as its Input
because of Linear Activation Function.
OH2 = 1 / (1 + 𝑒 −0.02)
= 0.505
4. Input to Output Layer
IO1 = W11 * OH1 + W21 * OH2
= (0.2 * 0.5448) + (-0.5 * 0.505)
= 0.10896 - 0.2525
IO1 = -0.14354
∆𝑊 21 = a * E * OH2
= 1 * (-0.09258) * 0.505
∆𝑾21 = -0.0457
10. Derivative of output of Hidden Layer
dH1 = (1 – OH1) * OH1
= (1-0.5448) * 0.5448
= 0.4552 * 0.5448
dH1 = 0.2479
dH2 = (1 – OH2) * OH2
= (1-0.505) * 0.505
= 0.495 * 0.505
dH2 = 0.2499
10. Delta inputs to Hidden Layer
d1 = dH1 * W11 * E
= 0.2479 * 0.2 * -0.09058
d1 = -0.00449
d2 = dH2 * W21 * E
= 0.2499 * -0.5 * -0.09058
d2 = 0.01131
11. Change in weights of I-H layer
∆𝑉11 = a * d1 * OI1
= 1 * (-0.00449) * 0.4
∆𝑽11 = -0.001796
∆𝑉21 = a * d1 * OI2
= 1 * (-0.00449) * (-0.7)
∆𝑽12 = 0.003143
∆𝑉12 = a * d2 * OI1
= 1 * (0.01131) * 0.4
∆𝑽21 = 0.004524
∆𝑉22 = a * d2 * OI2
= 1 * (0.01131) * (-0.7)
∆𝑽22 = -0.007917
12. Weight Update (H-O layer)
W11 = W11 + ∆W11
= 0.2 – 0.0493
W11 = 0.1507
EN = ½ * e * e
= ½ * (-0.3642) * (-0.3642)
= ½ * 0.13264
EN = 0.06632
ADDING MOMENTUM IN WEIGHTS
And