Artificial Neural Network
Artificial Neural Network
Dipesh Koirala
INTRODUCTION TO DEEP LEARNING
▪ is a subset of machine learning that uses neural networks to model complex patterns in data.
2
INTRODUCTION TO DEEP LEARNING
▪ A neuron is a cell in brain whose principle function is the collection, processing, and dissemination of
electrical signals.
3
NEURAL NETWORK
4
NEURAL NETWORK
5
NEURAL NETWORK
1 if x c
( x) =
0 if x c
Example: Consider following neuron and compute its output by assume activation function F(x)=1 if x>5
and F(x)=0, otherwise
b=1
u = x1 * w1 + x2 * w2 + x3 * w3
v=u+b=6+1=7 w2=2
x2=1 y
Now, w3=0.5
x3=2
y=f(v)=1
6
NEURAL NETWORK
E.g.,
7
NEURAL NETWORK
8
STRUCTURE OF NEURAL NETWORK
9
STRUCTURE OF NEURAL NETWORK
10
STRUCTURE OF NEURAL NETWORK
Example: Consider following Neural Network and compute its output using activation function
f(x) = 2x-1. Weights of synaptic links are provided above each link.
For Node 1
u1 = 2 * 0.8 + 3 * 1 = 4.6 => y1 = f(u1) = 2 * 4.6 – 1 = 8.2
For Node 2
u2 = 2 * 0.4 + 3 * 0.6 = 2.6 => y2 = f(u2) = 4.2
11
LEARNING IN NEURAL NETWORKS
12
LEARNING IN NEURAL NETWORKS
Perceptron Learning
▪ The term "Perceptron" was coined by Frank RosenBlatt
in 1962.
13
LEARNING IN NEURAL NETWORKS
14
LEARNING IN NEURAL NETWORKS
Perceptron Training
Example
Train the following perceptron by using given training set
x1 x2 t
x1 w1
1 1 1
w2 f y 1 -1 -1
x2
-1 1 -1
b -1 -1 -1
15
LEARNING IN NEURAL NETWORKS
Solution: =1
Epoch #1
1 𝑖𝑓 𝑥 > 0
𝜙(𝑥) = −1 𝑖𝑓 𝑥 < 0 𝐴𝑠𝑠𝑢𝑚𝑒𝑑 ℎ𝑎𝑟𝑑 𝐿𝑖𝑚𝑖𝑡𝑒𝑟 𝐴𝑐𝑡𝑖𝑣𝑎𝑡𝑖𝑜𝑛 𝑓𝑢𝑛𝑐𝑡𝑖𝑜𝑛
0 𝑖𝑓 𝑥 = 0
16
INTRODUCTION TO DEEP LEARNING
Epoch #2
17
BACKPROPAGATION ALGORITHM
18
BACKPROPAGATION ALGORITHM
• Deep
19
BACKPROPAGATION ALGORITHM
20
BACKPROPAGATION ALGORITHM
𝑧𝑗 = 𝑏 + 𝑤𝑗𝑖 𝑦𝑖
𝑖
compute the output of each unit j 1
𝑦𝑗 =
1 + 𝑒 −𝑧𝑗
21
BACKPROPAGATION ALGORITHM
22
BACKPROPAGATION ALGORITHM
𝛿𝑗 = 𝜙𝑗′ (𝑡𝑗 − 𝑦𝑗 )
𝛿𝑗 = 𝜙𝑗′ 𝛿𝑘 𝑤𝑗𝑘
k
23
BACKPROPAGATION ALGORITHM
Example
▪ Consider a MLP given below. Let the learning rate be 1. The initial weights of the network are given in the
table below. Assume that first training tuple is (1, 0, 1) and its target output is 1. Calculate weight updates by
using back-propagation algorithm.
1
Assume ( x) =
1 + e− x
w14 w15 w24 w25 w34 w35 w46 w47 w56 w57 w68 w78
0.6 0.4 0.2 -0.3 0.7 -0.6 0.4 0.7 0.1 0.8 0.2 0.5
24
BACKPROPAGATION ALGORITHM
Solution
Forward Pass
z4=1*0.6+0*0.2+1*0.7=1.3 y4=1/1+e-1.3=0.786
z5=1*0.4+0*(-0.3)+1*(-0.6)=-0.2 y5=1/1+e0.2=0.45
z6=0.786*0.4+0.45*0.1=0.36 y6=1/1+e-0.36=0.59
z7=0.786*0.7+0.45*0.8=0.91 y7=1/1+e-0.91=0.71
z8=0.59*0.2+0.71*0.5=0.47 y8=1/1+e-0.47=0.61
25
BACKPROPAGATION ALGORITHM
Solution
Backward Pass
Solution
Update Weights
27
EXTRA MATERIALS
▪ Gradient Descent
28
GRADIENT DESCENT
▪ In machine learning, gradient descent is used to update the parameters or weights of the model.
29
GRADIENT DESCENT
▪ Said it more mathematically, a gradient is a partial derivative with respect to its inputs.
▪ The higher the gradient, the steeper the slope and the faster a model can learn. But if the slope is
zero, the model stops learning.
▪ How big the steps are that Gradient Descent takes into the direction of the local minimum are
determined by the learning rate.
30
LINEAR REGRESSION
𝑦 = 𝑤0 + 𝑤1 𝑥
▪ Let us suppose that { 𝑥1 , 𝑦1 , 𝑥2 , 𝑦2 , … 𝑥𝑛 , 𝑦𝑛 } are given data points. Loss function for the n
data points is given by:
𝑛
1
𝐿= 𝑒𝑖2
2𝑛
𝑖=1
𝑛
1
𝐿= (𝑦𝑖 − 𝑤0 − 𝑤1 𝑥𝑖 )2
2𝑛
𝑖=1
31
LINEAR REGRESSION
▪ Now, coefficients or weights can be determined or updated using gradient decent method as
below:
𝑛
𝜕𝐸 1
𝒘𝟎 = 𝑤0 − 𝛼 = 𝑤0 + 𝛼 (𝑦𝑖 −𝑤0 − 𝑤1 𝑥𝑖 )
𝜕𝑤0 𝑛
𝑖=1
𝜕𝐸 1
𝒘𝟏 = 𝑤1 − 𝛼 𝜕𝑤 = 𝑤1 + 𝛼 𝑛 σ𝑛𝑖=1(𝑦𝑖 −𝑤0 − 𝑤1 𝑥𝑖 )𝑥𝑖
1
32
LINEAR REGRESSION
▪ E.g., Fit a straight line through the following data using SGD. Show one epoch of training.
Solution
General form of linear regression equation is: 𝑦 = 𝑤0 + 𝑤1 𝑥
Let us assume that initial values of parameters are:
𝑤0 = 𝑤1 = 0
33
LINEAR REGRESSION
34
THANK YOU