Artificial Neural Networks - Scholastic Home Video Tutor€¦ · 3/2/2013  · •Artificial Neural...

36
Scholastic Video Book Series Artificial Neural Networks Part 1 http://scholastictutors.webs.com (http://scholastictutors.webs.com/Scholastic-Book-NeuralNetworks-Part01-2013-02-03.pdf) 1 ScholasticTutors@Copyright (Feb, 2013) ISVT 911-0-20-130203-1

Transcript of Artificial Neural Networks - Scholastic Home Video Tutor€¦ · 3/2/2013  · •Artificial Neural...

Page 2: Artificial Neural Networks - Scholastic Home Video Tutor€¦ · 3/2/2013  · •Artificial Neural Networks (ANN) are computers whose architecture is modeled after the brain. •They

International Baccalaureate (IB)

2

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

http://scholastictutors.webs.com

(ANN-001)

Page 3: Artificial Neural Networks - Scholastic Home Video Tutor€¦ · 3/2/2013  · •Artificial Neural Networks (ANN) are computers whose architecture is modeled after the brain. •They

3

Classification Example

• The following table shows sample data obtained from two different fruits.

• 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.

Weight (grams) Length (cm)

Fruit 1 (Class

C1)

121 16.8

114 15.2

Fruit 2 (Class

C2)

210 9.4

195 8.1

http://scholastictutors.webs.com

Page 4: Artificial Neural Networks - Scholastic Home Video Tutor€¦ · 3/2/2013  · •Artificial Neural Networks (ANN) are computers whose architecture is modeled after the brain. •They

Artificial Neural Networks Theory

4

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)

http://scholastictutors.webs.com

Page 5: Artificial Neural Networks - Scholastic Home Video Tutor€¦ · 3/2/2013  · •Artificial Neural Networks (ANN) are computers whose architecture is modeled after the brain. •They

5

• 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.

Artificial Neural Networks Theory

http://scholastictutors.webs.com

Page 6: Artificial Neural Networks - Scholastic Home Video Tutor€¦ · 3/2/2013  · •Artificial Neural Networks (ANN) are computers whose architecture is modeled after the brain. •They

6

• 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.

• To what extent can we ever expect to be able to create a machine which is `truly' intelligent?

Intelligent Machine

http://scholastictutors.webs.com

Page 7: Artificial Neural Networks - Scholastic Home Video Tutor€¦ · 3/2/2013  · •Artificial Neural Networks (ANN) are computers whose architecture is modeled after the brain. •They

7

• 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.

Input S

ignals

x1

x2

x3

x3

wk1

wk2

wk3

wk4

Synaptic Weights

Summing

Junction

Bias

bk

Activation

Function

(.)yk

Output vk

Model of a Neuron

http://scholastictutors.webs.com

Page 8: Artificial Neural Networks - Scholastic Home Video Tutor€¦ · 3/2/2013  · •Artificial Neural Networks (ANN) are computers whose architecture is modeled after the brain. •They

8

• In mathematical terms, a neuron k can be described by:

and

where uk is the linear combiner output due to input signals.

• Also .

1

m

k k j j

j

u w x

k k ky u b

k k kv u b

Some Mathematics

http://scholastictutors.webs.com

Page 9: Artificial Neural Networks - Scholastic Home Video Tutor€¦ · 3/2/2013  · •Artificial Neural Networks (ANN) are computers whose architecture is modeled after the brain. •They

9

• The bias is an external parameter of artificial neuron and can be included into the equations as follows:

• and

• Note the change of limits of j from 1 to 0.

0

m

k k j j

j

v w x

k ky v

Bias as an Input

http://scholastictutors.webs.com

Page 10: Artificial Neural Networks - Scholastic Home Video Tutor€¦ · 3/2/2013  · •Artificial Neural Networks (ANN) are computers whose architecture is modeled after the brain. •They

10

wk0=bk (bias)

x1

x2

x3

x3

wk1

wk2

wk3

wk4

Synaptic Weights

(including bias)

Summing

Junction

Activation

Function

(.)yk

Output vk

wk0

Fixed Input

x0 = +1

Modified Neuron Structure

http://scholastictutors.webs.com

Page 11: Artificial Neural Networks - Scholastic Home Video Tutor€¦ · 3/2/2013  · •Artificial Neural Networks (ANN) are computers whose architecture is modeled after the brain. •They

11

• Threshold Function or Heaviside Function:

1 if 0( )

0 if 0

vv

v

0

0.2

0.4

0.6

0.8

1.0

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

( )v

Types of Activation Functions

http://scholastictutors.webs.com

Page 12: Artificial Neural Networks - Scholastic Home Video Tutor€¦ · 3/2/2013  · •Artificial Neural Networks (ANN) are computers whose architecture is modeled after the brain. •They

12

• Piecewise-Linear Function: 1

1,2

1 1( ) ,

2 2

10,

2

v

v v v

v

0

0.2

0.4

0.6

0.8

1.0

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

( )v

Types of Activation Functions (cont…)

http://scholastictutors.webs.com

Page 13: Artificial Neural Networks - Scholastic Home Video Tutor€¦ · 3/2/2013  · •Artificial Neural Networks (ANN) are computers whose architecture is modeled after the brain. •They

13

• Sigmoid Function:

where a is the slope parameter of the sigmoid function.

1

( )1 exp

vav

0

0.2

0.4

0.6

0.8

1.0

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

( )v

Increasing a

Types of Activation Functions (cont…)

http://scholastictutors.webs.com

Page 14: Artificial Neural Networks - Scholastic Home Video Tutor€¦ · 3/2/2013  · •Artificial Neural Networks (ANN) are computers whose architecture is modeled after the brain. •They

• 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.

Single Layer Perceptron

14

http://scholastictutors.webs.com

Page 15: Artificial Neural Networks - Scholastic Home Video Tutor€¦ · 3/2/2013  · •Artificial Neural Networks (ANN) are computers whose architecture is modeled after the brain. •They

15

• Variables and Parameters

1 2

1 2

1 1 input vector

1

1 1 weight vector

bias

actual response

desired response

learning-rate parameter, a postive constant less

T

m

T

m

n m

x n x n x n

n m

b n w n w n w n

b n

y n

d n

x( ) ( )

, ( ), ( ), , ( )

w( ) ( )

( ), ( ), ( ), , ( )

( )

( )

( )

than unity

Perceptron Convergence (Learning) Algorithm

http://scholastictutors.webs.com

Page 16: Artificial Neural Networks - Scholastic Home Video Tutor€¦ · 3/2/2013  · •Artificial Neural Networks (ANN) are computers whose architecture is modeled after the brain. •They

16

1. Initialization. Set . Then perform the following computations for time step n = 1,2, …

2. Activation. At time step n, activate the perceptron by applying input vector and desired response .

3. Computation of Actual Response. Compute the actual response of the perceptron:

where is the signum function.

0 w( ) 0

nx( ) d n( )

sgn Ty n n n( ) [w ( )x( )]

sgn(.)

1 if 0sgn

1 if 0

,( )

,

xx

x

Perceptron Convergence (Learning) Algorithm (cont…)

http://scholastictutors.webs.com

Page 17: Artificial Neural Networks - Scholastic Home Video Tutor€¦ · 3/2/2013  · •Artificial Neural Networks (ANN) are computers whose architecture is modeled after the brain. •They

17

4. Adaptation of Weight Vector. Update the weight vector of the perceptron:

where

5. Continuation. Increment time step n by one and go back to step 2.

1n n d n y n n w( ) w( ) ( ) ( ) x( )

1

2

1 if belongs to class

1 if belongs to class

n Cd n

n C

x( )( )

x( )

Perceptron Convergence (Learning) Algorithm (cont…)

http://scholastictutors.webs.com

Page 18: Artificial Neural Networks - Scholastic Home Video Tutor€¦ · 3/2/2013  · •Artificial Neural Networks (ANN) are computers whose architecture is modeled after the brain. •They

18

• The hyper-plane

is the decision boundary for a two class classification problem.

1

1 1 2 2

0

or

0

m

i i

i

w x b

w x w x b

x2

x1 0

Class C2

Class C1

Decision Boundary

http://scholastictutors.webs.com

Page 19: Artificial Neural Networks - Scholastic Home Video Tutor€¦ · 3/2/2013  · •Artificial Neural Networks (ANN) are computers whose architecture is modeled after the brain. •They

Solution to the Example Question

(with correct initial weights and bias)

19

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)

http://scholastictutors.webs.com

Page 20: Artificial Neural Networks - Scholastic Home Video Tutor€¦ · 3/2/2013  · •Artificial Neural Networks (ANN) are computers whose architecture is modeled after the brain. •They

1 20 30 0 300

0 50 0 01

( ) , ( ) ,

( ) , .

w wgiven

b

x1

x2

50

-30

300

Activation

Function

(.)sigy(n)

Output

Fixed Input

x0 = +1

With correct initial

weights and bias

1 if 0sgn

1 if 0

,( )

,

xx

x

Solution to the Example (with correct initial weights and bias)

20

http://scholastictutors.webs.com

Page 21: Artificial Neural Networks - Scholastic Home Video Tutor€¦ · 3/2/2013  · •Artificial Neural Networks (ANN) are computers whose architecture is modeled after the brain. •They

Therefore the Initial Decision

Boundary for this example is:

1 230 300 50 0x x

4

8

12

16

20

50 100 150 200 250

(121,16.8)

(114,15.2)

(195,8.1)

(210,9.4) (100,9.83)

(200,19.83)

Class C1

Class C2

x1

x2

Initial hyper-plane does separate the two classes. 21

Solution to the Example (with correct initial weights and bias) (cont…)

1 2

30 100 50100 9 83

300, .x x

1 2

30 200 50200 19 83

300, .x x

1 1 2 20w x w x b

1 20 30 0 300

0 50 0 01

( ) , ( ) ,

( ) , .

w wgiven

b

http://scholastictutors.webs.com

Page 22: Artificial Neural Networks - Scholastic Home Video Tutor€¦ · 3/2/2013  · •Artificial Neural Networks (ANN) are computers whose architecture is modeled after the brain. •They

Class Unknown

x1 = 140

x2 = 17.9

x0 = +1

Now use the above model to classify the unknown fruit.

1

unknown 1 140 17 9

3 50 30 300

unknown sgn 3 unknown sgn 50 1 30 140 300 17 9

sgn 1220 1

this unkown fruit belonge to the class .

x( ) , , .

w( ) , ,

( ) w ( )x( ) .

( )

T

T

Ty

C

50

-30

300

Activation

Function

(.)sigy(n)=+1

Output

Fixed Input

+1220

For Class C1, Output = +1

Classification of the Unknown Fruit

22 this unknown fruit belongs to the class

http://scholastictutors.webs.com

Page 23: Artificial Neural Networks - Scholastic Home Video Tutor€¦ · 3/2/2013  · •Artificial Neural Networks (ANN) are computers whose architecture is modeled after the brain. •They

Solution to the Example Question

(with unknown initial weights and bias)

23

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)

http://scholastictutors.webs.com

Page 24: Artificial Neural Networks - Scholastic Home Video Tutor€¦ · 3/2/2013  · •Artificial Neural Networks (ANN) are computers whose architecture is modeled after the brain. •They

24

1 20 30 0 300

0 1230 0 01

( ) , ( ) ,

( ) , .

w wgiven

b

1 230 300 1230 0x x

1 2

30 100 1230100 14 1

300, .x x

1 2

30 200 1230200 24 1

300, .x x

Initial hyperplane does not separate the two classes.

Therefore we need to Train the Neural Network

4

8

12

16

20

50 100 150 200 250

(121,16.8)

(114,15.2)

(195,8.1)

(210,9.4)

(100,14.1)

(200,24.1)

x1

x2

With unknown initial

weights and bias

Solution to the Example (with unknown initial weights and bias)

Therefore the Decision Boundary for this

case:

http://scholastictutors.webs.com

Page 25: Artificial Neural Networks - Scholastic Home Video Tutor€¦ · 3/2/2013  · •Artificial Neural Networks (ANN) are computers whose architecture is modeled after the brain. •They

Class C1

x1 = 121

x2 = 16.8

x0 = +1

0 1 121 16 8 and 0 1

0 1230 30 300

0 sgn 0 0

sgn 1230 1 30 121 300 16 8

sgn 180 1 0

Hence no need to recalculate the weights.

1 1 1230 30 300

x( ) x( ) , , . ( )

w( ) w( ) , ,

( ) ( ) w ( )x( )

.

( ) ( )

w( ) w( ) , ,

T

T

T

T

n d

n

y n y

d

n

300

-30

-1230 Activation

Function

(.)sig y(n)=+1 Output

Fixed Input

+180

For Class C1, Output = +1

Training with known Fruit (121,16.8)

25

http://scholastictutors.webs.com

Page 26: Artificial Neural Networks - Scholastic Home Video Tutor€¦ · 3/2/2013  · •Artificial Neural Networks (ANN) are computers whose architecture is modeled after the brain. •They

Class C1

x1 = 114

x2 = 15.2

x0 = +1

1 1 114 15 2 and 1 1

1 1230 30 300

1 sgn 1 1 sgn 1230 1 30 114 300 15 2

sgn 90 1 1

Hence recalculate the weights.

x( ) , , . ( )

w( ) , ,

( ) w ( )x( ) .

( ) ( )

we have to

T

T

T

d

y

d

300

-30

-1230 Activation

Function

(.)sig y(n)=-1 Output

Fixed Input

-90

For Class C1, the output should be +1, but what we get is -1. Hence we have to recalculate the weights.

Training with known Fruit (114,15.2)

http://scholastictutors.webs.com

Page 27: Artificial Neural Networks - Scholastic Home Video Tutor€¦ · 3/2/2013  · •Artificial Neural Networks (ANN) are computers whose architecture is modeled after the brain. •They

27

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

1

1 1230 30 300

1 1 114 15 2

1 1 1 1 0 01

1 1 2 1230 30 300 0 01 1 1 1 114 15 2

1230 30 300 0 02 2 28 0 304

2 1229 08 27 72 300 304

w( ) w( ) ( ) ( ) x( )

w( ) , ,

x( ) , , .

( ) , ( ) , .

w( ) w( ) , , . , , .

, , . , . , .

w( ) . , . , .

T

T

T T

T T

T

n n d n y n n

d y

Adaptation of Weight Vector

http://scholastictutors.webs.com

Page 28: Artificial Neural Networks - Scholastic Home Video Tutor€¦ · 3/2/2013  · •Artificial Neural Networks (ANN) are computers whose architecture is modeled after the brain. •They

Class C2

x1 = 210

x2 = 9.4

x0 = +1

2 1229 08 27 72 300 304

2 1 210 9 4 and 2 1

2 sgn 2 2 sgn 1229 08 1 27 72 210 300 304 9 4

sgn 4227 4224 1 2

Hence no need to recalculate the weights.

1 3 1229 08 27 7

w( ) . , . , .

x( ) , , . ( )

y( ) w ( )x( ) . . . .

( . ) ( )

w( ) w( ) . , .

T

T

T

d

d

n

2 300 304, .T

300.304

-27.72

-1229.08 Activation

Function

(.)sigy(n)=-1

Output

Fixed Input

-4227.4224

For Class C2, Output = -1

Training with known Fruit (210,9.4)

28

http://scholastictutors.webs.com

Page 29: Artificial Neural Networks - Scholastic Home Video Tutor€¦ · 3/2/2013  · •Artificial Neural Networks (ANN) are computers whose architecture is modeled after the brain. •They

Class C2

3 1229 08 27 72 300 304

3 1 195 8 1 and 3 1

3 sgn 3 3 sgn 1229 08 1 27 72 195 300 304 8 1

sgn 4202 0176 1 3

Hence no need to recalculate the weights.

1 4 1229 08 27 7

w( ) . , . , .

x( ) , , . ( )

y( ) w ( )x( ) . . . .

( . ) ( )

w( ) w( ) . , .

T

T

T

d

d

n

2 300 304, .T

x1 = 195

x2 = 8.1 300.304

-27.72

-1229.08 Activation

Function

(.)sigy(n)=-1

Output

Fixed Input

x0 = +1

-4202.0176

For Class C2, Output = -1

Training with known Fruit (195,8.1)

29

http://scholastictutors.webs.com

Page 30: Artificial Neural Networks - Scholastic Home Video Tutor€¦ · 3/2/2013  · •Artificial Neural Networks (ANN) are computers whose architecture is modeled after the brain. •They

Class C1

4 1229 08 27 72 300 304

4 1 121 16 8 and 4 1

4 sgn 4 4 sgn 1229 08 1 27 72 121 300 304 16 8

sgn 461 91 1 4

Hence no need to recalculate the weights.

1 5 1229 08 27 72

w( ) . , . , .

x( ) , , . ( )

y( ) w ( )x( ) . . . .

( . ) ( )

w( ) w( ) . , . ,

T

T

T

d

d

n

300 304.T

x1 = 121

x2 = 16.8 300.304

-27.72

-1229.08 Activation

Function

(.)sigy(n)=+1

Output

Fixed Input

x0 = +1

461.91

For Class C1, Output = +1

30

Training with known Fruit (121,16.8)

http://scholastictutors.webs.com

Page 31: Artificial Neural Networks - Scholastic Home Video Tutor€¦ · 3/2/2013  · •Artificial Neural Networks (ANN) are computers whose architecture is modeled after the brain. •They

5 1229 08 27 72 300 304

5 1 114 15 2 and 5 1

5 sgn 5 5 sgn 1229 08 1 27 72 114 300 304 15 2

sgn 175 46 1 5

Hence no need to recalculate the weights.

1 6 1229 08 27 72

w( ) . , . , .

x( ) , , . ( )

y( ) w ( )x( ) . . . .

( . ) ( )

w( ) w( ) . , . ,

T

T

T

d

d

n

300 304.T

Class C1

x1 = 114

x2 = 15.2 300.304

-27.72

-1229.08 Activation

Function

(.)sigy(n)=+1

Output

Fixed Input

x0 = +1

175.46

For Class C1, Output = +1

31

Training with known Fruit (114,15.2)

http://scholastictutors.webs.com

Page 32: Artificial Neural Networks - Scholastic Home Video Tutor€¦ · 3/2/2013  · •Artificial Neural Networks (ANN) are computers whose architecture is modeled after the brain. •They

1 227 72 300 304 1229 08 0. . .x x

1 2

27 72 100 1229 08100 13 32

300 30

. ., .

.x x

Therefore the decision boundary obtained

after Neural Network training is:

1 2

27 72 200 1229 08200 22 55

300 30

. ., .

.x x

4

8

12

16

20

50 100 150 200 250

(121,16.8)

(114,15.2)

(195,8.1)

(210,9.4)

(100,13.32)

(200,22.55)

x1

x2 Class C1

Class C2

The new decision boundary

can now be used to classify

any unknown item.

Decision Boundary After Training

32

http://scholastictutors.webs.com

Page 33: Artificial Neural Networks - Scholastic Home Video Tutor€¦ · 3/2/2013  · •Artificial Neural Networks (ANN) are computers whose architecture is modeled after the brain. •They

Classification of the Unknown Fruit using the

New Decision Boundary

33

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)

http://scholastictutors.webs.com

Page 34: Artificial Neural Networks - Scholastic Home Video Tutor€¦ · 3/2/2013  · •Artificial Neural Networks (ANN) are computers whose architecture is modeled after the brain. •They

Class Unknown

x1 = 140

x2 = 17.9

x0 = +1

Now use the above model to classify the unknown fruit. For Class C1, Output = +1

Classification of the Unknown Fruit using the New Decision Boundary

34

300.304

-27.72

-1229.08 Activation

Function

(.)sigy(n)=+1

Output

Fixed Input

175.46

𝐱 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

http://scholastictutors.webs.com

Page 35: Artificial Neural Networks - Scholastic Home Video Tutor€¦ · 3/2/2013  · •Artificial Neural Networks (ANN) are computers whose architecture is modeled after the brain. •They

International Baccalaureate (IB)

35

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

http://scholastictutors.webs.com

(ANN-001)

END of the Book

If you like to see similar solutions to any Mathematics problems please contact us at: [email protected] with your request.