Sie sind auf Seite 1von 33


International Baccalaureate (IB)


Artificial Neural Networks - #1
Classification using Single Layer Perceptron Model

Click here to see the video http://youtu.be/S3iQgcoQVbc

http://scholastictutors.webs.com
(ANN-001) 2
as
Classification Example

• The following table shows sample data obtained from two


different fruits.
Weight (grams) Length (cm)
Fruit 1 (Class 121 16.8
C1) 114 15.2
Fruit 2 (Class 210 9.4
C2) 195 8.1

• Train a single layer perceptron model using the above parameters


to classify the two fruits.
• Using the model parameters you have obtained classify the fruit
with weight 140gm and length 17.9cm.

http://scholastictutors.webs.com 3
Classification Example

Weight (grams) Length (cm)


Fruit 1 (Class 121 16.8
C1) 114 15.2
Fruit 2 (Class 210 9.4
C2) 195 8.1

X2(Length in cm)
Class C1
20
(121,16.8)
16 (114,15.2)

12
(210,9.4)
8 (195,8.1)

4 Class C2
X1(Weight
http://scholastictutors.webs.com 50 100 150 200 250 in grams)
Artificial Neural Networks Theory

Click here to see the video http://youtu.be/S3iQgcoQVbc

This space is left for


sponsors/advertisements
from
US$ 999 per advert
(Multi-book & Multi-page adverts with
web links to divert traffic to your web
sites/videos are also available)

5
http://scholastictutors.webs.com
Artificial Neural Networks Theory

• Artificial Neural Networks (ANN) are computers


whose architecture is modeled after the brain.
• They typically consist of many hundreds of simple
processing units which are wired together in a
complex communication network.
• Each unit or node is a simplified model of a real
neuron which fires (sends off a new signal) if it
receives a sufficiently strong input signal from the
other nodes to which it is connected.

6
http://scholastictutors.webs.com
Intelligent Machine

• The strength of these connections may be


varied in order for the network to perform
different tasks corresponding to different
patterns of node firing activity.
• This structure is very different from traditional
computers and hence make way to Intelligent
Machines.

7
http://scholastictutors.webs.com
Model of a Neuron

• The model consists of a set of synapses each of


which is characterized by a weight or strength of
its own.
• An adder, an activation function and a bias.
Bias
wk1 Activation
x1
bk Function

wk2
 (.)
Input Signals

x2 vk

Output

wk3 yk
x3
Summing

x4 wk4 Junction

Synaptic Weights 8

http://scholastictutors.webs.com
Some Mathematics

• In mathematical terms, a neuron k can be


described by: m
uk   wk j x j
j 1
and
yk    uk  bk 
where uk is the linear combiner output due to
input signals.
• Also .vk  uk  bk 9

http://scholastictutors.webs.com
Bias as an Input

• The bias is an external parameter of artificial


neuron and can be included into the equations as
follows: m
vk   wk j x j
j 0

• and
yk    vk 
• Note the change of limits of j from 1 to 0. 10

http://scholastictutors.webs.com
Modified Neuron Structure

Fixed Input
wk0 wk0=bk (bias)
x0 = +1
x1 wk1 Activation
Function

wk2
 (.)
x2
 vk Output

wk3 yk
x3
Summing
Junction
x4 wk4
Synaptic Weights
(including bias)

11
http://scholastictutors.webs.com
Types of Activation Functions

• Threshold Function or Heaviside Function:


1 if v  0
 (v )  
0 if v  0
1.0
 (v )
0.8

0.6

0.4

0.2

0
-2.0 -1.5 -1.0 -0.5 0 0.5 1.0 1.5 2.0 12

http://scholastictutors.webs.com
Types of Activation Functions (cont…)

 1
• Piecewise-Linear Function:  1, v
2

 1 1
 (v )  v,  v
 2 2
 1
 0, v
2
1.0
 (v )
0.8

0.6

0.4

0.2
0
-2.0 -1.5 -1.0 -0.5 0 0.5 1.0 1.5 2.0 13

http://scholastictutors.webs.com
Types of Activation Functions (cont…)

1
• Sigmoid Function:  (v ) 
1  exp  av 
where a is the slope parameter of the sigmoid
function.
1.0
 (v )
0.8

0.6 Increasing a
0.4

0.2

0
-8.0 -6.0 -4.0 -2.0 0 2.0 4.0 6.0 8.0 14

http://scholastictutors.webs.com
Single Layer Perceptron

• The neuronal model we have just discussed is


also known as a perceptron.
• The perceptron is the simplest form of a
neural network used for the classification of
patterns said to be linearly separable.
• Basically, it consists of a single neuron with
adjustable synaptic weights and bias.
• Now we will look at a method of achieving
learning in our model we have formulated.
15

http://scholastictutors.webs.com
Perceptron Convergence (Learning)
Algorithm

• Variables and Parameters


x( n )  ( m  1)  1 input vector
  1, x1 ( n ), x2 ( n ), , xm ( n )
T

w( n)  ( m  1)  1 weight vector
 b( n ), w1 ( n ), w2 ( n ), , wm ( n )
T

b( n )  bias
y( n )  actual response
d ( n )  desired response
  learning-rate parameter, a postive constant less than unity

16

http://scholastictutors.webs.com
Perceptron Convergence (Learning)
Algorithm (cont…)

1. Initialization. Set w(0)  0. Then perform the following


computations for time step n = 1,2, …
2. Activation. At time step n, activate the perceptron by
applying input vector x( n)and desired response d ( n) .
3. Computation of Actual Response. Compute the actual
response of the perceptron:

y( n)  sgn[wT ( n)x( n)]


where sgn(.) is the signum function.
1, if x0
sgn( x )  
1, if x0 17

http://scholastictutors.webs.com
Perceptron Convergence (Learning)
Algorithm (cont…)
4. Adaptation of Weight Vector. Update the
weight vector of the perceptron:
w( n  1)  w( n)    d ( n)  y( n) x( n)

where
 1 if x( n) belongs to class C1
d ( n)  
1 if x( n) belongs to class C2

5. Continuation. Increment time step n by one


and go back to step 2.
18

http://scholastictutors.webs.com
Decision Boundary

• The hyper-plane
x2
m

w x  b  0
i 1
i i
Class C1
or
w1 x1  w2 x2  b  0 0 x1

is the decision Class C2


boundary for a two
class classification
problem. 19

http://scholastictutors.webs.com
Solution to the Example Question
(with correct initial weights and bias)

Click here to see the video http://youtu.be/S3iQgcoQVbc

This space is left for


sponsors/advertisements
from
US$ 999 per advert
(Multi-book & Multi-page adverts with
web links to divert traffic to your web
sites/videos are also available)

20
http://scholastictutors.webs.com
Solution to the Example
(with correct initial weights and bias)

w1 (0)  30, w2 (0)  300, 


With correct initial
 given
weights and bias
b(0)  50,   0.01 

Fixed Input
Activation
50
Function
x0 = +1
x1 -30 Output

300
 sig (.)
y(n)
x2
1, if x0
sgn( x )  
1, if x0
21

http://scholastictutors.webs.com
Solution to the Example
(with correct initial weights and bias) (cont…)

w1 (0)  30, w2 (0)  300, 


 given
b(0)  50,   0.01  x2
Therefore the Initial Decision Class C1
20 (200,19.83)
Boundary for this example is: (121,16.8)

w1x1  w2 x2  b  0 16 (114,15.2)

12
30 x1  300 x2  50  0 (100,9.83) (210,9.4)
8 (195,8.1)

30  100  50 4 Class C2
x1  100, x2   9.83
300
50 100 150 200 250 x1
30  200  50
x1  200, x2   19.83
300
Initial hyper-plane does separate the two classes. 22

http://scholastictutors.webs.com
Classification of the Unknown Fruit
http://scholastictutors.webs.com

Fixed Input
Activation
50
x0 = +1 Function

x1 = 140 -30 +1220 Output

x2 = 17.9
300
 sig (.)
y(n)=+1
Class Unknown
For Class C1,
Now use the above model to classify the unknown fruit. Output = +1
x( unknown )   1, 140, 17.9
T

w(3)  50,  30, 300


T

 
y( unknown )  sgn w T (3)x( unknown )  sgn  50  1  30  140  300  17.9 
 sgn(1220)  1
 this
this unknown
unkown fruit
fruit belonge to the
belongs to the class
class C1. 23
Solution to the Example Question
(with unknown initial weights and bias)

Click here to see the video http://www.youtube.com/watch?feature=player_profilepage&v=S3iQgcoQVbc#t=1220s

This space is left for


sponsors/advertisements
from
US$ 999 per advert
(Multi-book & Multi-page adverts with
web links to divert traffic to your web
sites/videos are also available)

24
http://scholastictutors.webs.com
Solution to the Example
(with unknown initial weights and bias)

w1 (0)  30, w2 (0)  300, 


With unknown initial  given
weights and bias b(0)  1230,   0.01 

Therefore the Decision Boundary for this


x2 (200,24.1)

case: 20
30 x1  300 x2  1230  0 (121,16.8)
16
(100,14.1) (114,15.2)

30  100  1230 12
x1  100, x2   14.1 (210,9.4)
300 8 (195,8.1)
30  200  1230
x1  200, x2   24.1 4
300

Initial hyperplane does not separate the two classes.


50 100 150 200 250 x1
Therefore we need to Train the Neural Network
25

http://scholastictutors.webs.com
Training with known Fruit
(121,16.8)
Fixed Input
Activation
-1230
x0 = +1 Function

x1 = 121 -30 Output



+180
sig (.) y(n)=+1
x2 = 16.8
300
Class C1
x( n )  x(0)   1, 121, 16.8
T
and d (0)  1 For Class C1,
w( n)  w( 0)   1230,  30, 300 Output = +1
T


y( n )  y(0)  sgn w T ( 0)x( 0) 
 sgn  1230  1  30  121  300  16.8 
 sgn (180)  1  d (0)
Hence no need to recalculate the weights.
 w( n  1)  w(1)   1230,  30, 300
T
26

http://scholastictutors.webs.com
Training with known Fruit
(114,15.2)
Fixed Input
Activation
-1230
x0 = +1 Function

x1 = 114 -30 Output


-90 y(n)=-1
sig (.)
x2 = 15.2
300
Class C1
For Class C1, the

x(1)   1, 114, 15.2


T output should be +1,
and d (1)  1 but what we get is -1.
Hence we have to
w(1)   1230,  30, 300
T
recalculate the weights.

 
y(1)  sgn w T (1)x(1)  sgn  1230  1  30  114  300  15.2 
 sgn( 90)  1  d (1)
Hence we have to recalculate the weights.
http://scholastictutors.webs.com
Adaptation of Weight Vector

Here we use Adaptation of Weight Vector (Step 4) to update the weight


vector of the perceptron.

w( n  1)  w( n)    d ( n)  y( n) x( n)
w(1)   1230,  30, 300
T

x(1)   1, 114, 15.2


T

d (1)  1, y(1)  1,  0.01


w(1  1)  w( 2)   1230,  30, 300  0.01  1   1   1, 114, 15.2
T T

  1230,  30, 300   0.02, 2.28, 0.304


T T

 w( 2)   1229.08,  27.72, 300.304


T

28

http://scholastictutors.webs.com
Training with known Fruit
(210,9.4)
Fixed Input
-1229.08 Activation
x0 = +1 Function

x1 = 210 -27.72
Output

x2 = 9.4  -4227.4224
sig (.)
y(n)=-1
300.304
Class C2

w( 2)   1229.08,  27.72, 300.304


T For Class C2,
Output = -1
x( 2)   1, 210, 9.4
T
and d ( 2)  1
 
y( 2)  sgn w T ( 2)x( 2)  sgn  1229.08  1  27.72  210  300.304  9.4 
 sgn ( 4227.4224)  1  d ( 2)
Hence no need to recalculate the weights.
 w( n  1)  w(3)   1229.08,  27.72, 300.304
T
29

http://scholastictutors.webs.com
Training with known Fruit
(195,8.1)
Fixed Input
-1229.08 Activation
x0 = +1 Function

x1 = 195 -27.72
Output

x2 = 8.1  -4202.0176
sig (.)
y(n)=-1
300.304
Class C2

w(3)   1229.08,  27.72, 300.304


T For Class C2,
Output = -1
x(3)   1, 195, 8.1
T
and d (3)  1
 
y(3)  sgn w T (3)x(3)  sgn  1229.08  1  27.72  195  300.304  8.1
 sgn ( 4202.0176)  1  d (3)
Hence no need to recalculate the weights.
 w( n  1)  w( 4)   1229.08,  27.72, 300.304
T
30

http://scholastictutors.webs.com
Training with known Fruit
(121,16.8)
Fixed Input
-1229.08 Activation
x0 = +1 Function

x1 = 121 -27.72
Output

x2 = 16.8  461.91
sig (.)
y(n)=+1
300.304
Class C1

w( 4)   1229.08,  27.72, 300.304


T For Class C1,
Output = +1
x( 4)   1, 121, 16.8
T
and d ( 4)  1
 
y( 4)  sgn w T ( 4)x( 4)  sgn  1229.08  1  27.72  121  300.304  16.8 
 sgn ( 461.91)  1  d ( 4)
Hence no need to recalculate the weights.
 w( n  1)  w(5)   1229.08,  27.72, 300.304
T
31

http://scholastictutors.webs.com
Training with known Fruit
(114,15.2)
Fixed Input
-1229.08 Activation
x0 = +1 Function

x1 = 114 -27.72
Output

x2 = 15.2  175.46
sig (.)
y(n)=+1
300.304
Class C1

w(5)   1229.08,  27.72, 300.304


T
For Class C1,
x(5)   1, 114, 15.2
T Output = +1
and d (5)  1
 
y(5)  sgn w T (5)x(5)  sgn  1229.08  1  27.72  114  300.304  15.2 
 sgn (175.46)  1  d (5)
Hence no need to recalculate the weights.
 w( n  1)  w(6)   1229.08,  27.72, 300.304
T

32

http://scholastictutors.webs.com
Decision Boundary After Training

Therefore the decision boundary obtained


after Neural Network training is:

27.72 x1  300.304 x2  1229.08  0


x2
27.72  100  1229.08
Class C1 (200,22.55)
x1  100, x2   13.32 20
300.30
(121,16.8)
27.72  200  1229.08 16 (114,15.2)
x1  200, x2   22.55
300.30 (100,13.32)
12
(210,9.4)
8 (195,8.1)
The new decision boundary
can now be used to classify 4 Class C2
any unknown item.
50 100 150 200 250 x1
33

http://scholastictutors.webs.com
Classification of the Unknown Fruit
using the New Decision Boundary
Fixed Input
-1229.08 Activation
x0 = +1 Function

x1 = 140 -27.72
Output

x2 = 17.9  175.46
sig (.)
y(n)=+1
300.304
Class Unknown

For Class C1,


Now use the above model to classify the unknown fruit. Output = +1
𝐱 unknown = +1,140,17.9 𝑇
𝐰 5 = −1229.08, −27.72,300.304 𝑇
y unkown = sgn 𝐰 𝑇 (5)𝐱(unknown)
= sgn −1229.08 × 1 − 27.72 × 140 + 300.304 × 17.9
= sgn 265.56 = +1

∴ this unknown fruit belongs to the class 𝐶1 35

http://scholastictutors.webs.com

Das könnte Ihnen auch gefallen