introduction to artificial neural network

81

Upload: qingkai-kong

Post on 09-Jan-2017

215 views

Category:

Data & Analytics


4 download

TRANSCRIPT

Page 1: Introduction to Artificial Neural Network
Page 2: Introduction to Artificial Neural Network

Artificial Neural Network basics

Qingkai Kong 2016-12-02

h"p://seismo.berkeley.edu/qingkaikong/  

Page 3: Introduction to Artificial Neural Network
Page 4: Introduction to Artificial Neural Network

Workshop time

Lear

ning

cur

ve

Gentle introduction

Step by step ANN

Real world example

h"ps://github.com/qingkaikong/20161202_ANN_basics  

Page 5: Introduction to Artificial Neural Network

Workshop time

Lear

ning

cur

ve

Gentle introduction •  What’s ML •  ANN history •  ANN overview

Step by step ANN

Real world example

h"ps://github.com/qingkaikong/20161202_ANN_basics  

Page 6: Introduction to Artificial Neural Network

What is machine learning?

h"ps://github.com/qingkaikong/20161202_ANN_basics  

Page 7: Introduction to Artificial Neural Network

Self-driving car Voice recognition …

h"ps://github.com/qingkaikong/20161202_ANN_basics  

Page 8: Introduction to Artificial Neural Network

Not always working

Page 9: Introduction to Artificial Neural Network
Page 10: Introduction to Artificial Neural Network

1940s Birth

1970s Winter

1980s Rebirth

2006 Deep

Page 11: Introduction to Artificial Neural Network
Page 12: Introduction to Artificial Neural Network
Page 13: Introduction to Artificial Neural Network

ANN in simple view

Page 14: Introduction to Artificial Neural Network

ANN jargons

Page 15: Introduction to Artificial Neural Network

What’re the weights

Page 16: Introduction to Artificial Neural Network
Page 17: Introduction to Artificial Neural Network

.  

.  

.  

w1  

w2  

wn  

F(eye×w1+nose×w2+…+mouth×wn)  

Sheldon  Cooper?  

Intuitive ���Artificial Neural Network

Output  

Input  

Page 18: Introduction to Artificial Neural Network

.  

.  

.  

w1  

w2  

wn  

F(eye×w1+nose×w2+…+mouth×wn)  

Sheldon  Cooper?  

Intuitive ���Artificial Neural Network

Output  

Input  

feedback  error  

Page 19: Introduction to Artificial Neural Network

.  

.  

.  

w1  

w2  

wn  

F(eye×w1+nose×w2+…+mouth×wn)  

Sheldon  Cooper?  

Intuitive ���Artificial Neural Network

Output  

Input  

feedback  error  

Page 20: Introduction to Artificial Neural Network

.  

.  

.  

w1  

w2  

wn  

F(eye×w1+nose×w2+…+mouth×wn)  

Intuitive ���Artificial Neural Network

Output  

Input  

Page 21: Introduction to Artificial Neural Network

Workshop time

Lear

ning

cur

ve

Gentle introduction •  What’s ML •  ANN history •  ANN overview

Step by step ANN •  Perceptron •  Backpropagation

Real world example

Page 22: Introduction to Artificial Neural Network
Page 23: Introduction to Artificial Neural Network

h"ps://arxiv.org/abs/1508.06576v1  h"ps://deepart.io/  

Application: Learn arts

Page 24: Introduction to Artificial Neural Network

h"p://junkhost.com/2016/03/man-­‐combines-­‐random-­‐peoples-­‐photos-­‐using-­‐neural-­‐networks-­‐and-­‐the-­‐results-­‐are-­‐amazing/  

Page 25: Introduction to Artificial Neural Network
Page 26: Introduction to Artificial Neural Network

X

Σ yf

InputOutput

feature2

feature3

ω0

ω2

ω3 X – input datay – output targetωi – weightsΣ – summationf – activation functionBlue circle – bias

feature1 ω1

1

Σ = ω0x0+ω1x1+ω2x2+ω3x3+…+ωnxn    f = f(ω0x0+ω1x1+ω2x2+ω3x3+…+ωnxn)  

Page 27: Introduction to Artificial Neural Network
Page 28: Introduction to Artificial Neural Network

z = ω0x0+ω1x1+ω2x2+ω3x3+…+ωnxn  

11+ e−z

More activation function

f (z) = 11+ e−z

df (z)dx

= f (z)(1− f (z))

Page 29: Introduction to Artificial Neural Network

X

Σ yf

InputOutput

feature2

feature3

ω0

ω2

ω3 X – input datay – output targetωi – weightsΣ – summationf – activation functionBlue circle – bias

feature1 ω1

1

Σ = ω0x0+ω1x1+ω2x2+ω3x3+…+ωnxn  f = f(ω0x0+ω1x1+ω2x2+ω3x3+…+ωnxn)y This is our estimation

Perceptron

Page 30: Introduction to Artificial Neural Network

X

Σ yf

InputOutput

feature2

feature3

ω0

ω2

ω3 X – input datay – output targetωi – weightsΣ – summationf – activation functionBlue circle – bias

feature1 ω1

1

Error  =  Target  -­‐  Es-ma-on  

Perceptron

Page 31: Introduction to Artificial Neural Network
Page 32: Introduction to Artificial Neural Network

Error  =  Target  -­‐  Es-ma-on  

How the ANN learns

Page 33: Introduction to Artificial Neural Network

Error  =  Target  -­‐  Es-ma-on  

How the ANN learns

Learning:  Update  weights  to  reduce  error  next  -me!    

Page 34: Introduction to Artificial Neural Network
Page 35: Introduction to Artificial Neural Network

Weights  Delta  =  Error  ×  slope  ×  input  

Weights update rules

How  much  we  will  update    the  weights  for  next  Xme  

Page 36: Introduction to Artificial Neural Network

Error  =  Target  -­‐  Es-ma-on  

Look at errors closer

0     1  Target  

Page 37: Introduction to Artificial Neural Network

Error  =  Target  -­‐  Es-ma-on  

Three  cases:  •  Error  <  0:  Target  is  0,  es-ma-on  is  not  0  •  Error  >  0:  Target  is  1,  es-ma-on  is  not  1  •  Error  =  0:  Es-ma-on  correct  

Look at errors closer

0     1  Target  

Page 38: Introduction to Artificial Neural Network

Cases  1:  •  Error  <  0:  Target  is  0,  es-ma-on  is  not  0  

Look at errors closer���(assume inputs are positive)

Page 39: Introduction to Artificial Neural Network

Cases  1:  •  Target  is  0  •  Es-ma-on  is  0.3  

Look at errors closer���(assume inputs are positive)

Error  =  0  –  0.3  =-­‐0.3  

Page 40: Introduction to Artificial Neural Network

Cases  1:  •  Target  is  0  •  Es-ma-on  is  0.3  

Look at errors closer���(assume inputs are positive)

11+ e−z

z  zupdate  

Error  =  0  –  0.3  =-­‐0.3  

Page 41: Introduction to Artificial Neural Network

Cases  1:  •  Target  is  0  •  Es-ma-on  is  0.3  

Look at errors closer���(assume inputs are positive)

Error  =  0  –  0.3  =-­‐0.3  

z = ω0x0+ω1x1+ω2x2+ω3x3  

We need reduce weights!  

Page 42: Introduction to Artificial Neural Network

Cases  1:  •  Target  is  0  •  Es-ma-on  is  0.3  

Look at errors closer���(assume inputs are positive)

Error  =  0  –  0.3  =-­‐0.3  

z = ω0x0+ω1x1+ω2x2+ω3x3  

We need reduce weights!If we add error to the weights, we will reduce it!  

Page 43: Introduction to Artificial Neural Network

Cases  1:  •  Target  is  0  •  Es-ma-on  is  0.3  

Look at errors closer���(assume inputs are positive)

Error  =  0  –  0.3  =-­‐0.3  

z = ω0x0+ω1x1+ω2x2+ω3x3  

We need reduce weights!But what if the inputs are negative  

Page 44: Introduction to Artificial Neural Network

Weights  Delta  =  Error  ×  input  

Weights update rules

Page 45: Introduction to Artificial Neural Network

z  

Page 46: Introduction to Artificial Neural Network

z  

flat  slope  

steep  slope  

Page 47: Introduction to Artificial Neural Network

Weights  Delta  =  Error  ×  slope  ×  input  

Weights update rules

Page 48: Introduction to Artificial Neural Network

Learn from example

Page 49: Introduction to Artificial Neural Network
Page 50: Introduction to Artificial Neural Network

Learn from Example

Sample   Feature  1   Feature  2   Feature  3   Target  Sample  1   0   0   1   0  Sample  2   1   1   1   1  Sample  3   1   0   1   1  Sample  4   0   1   1   0  Sample  5   1   0   0   1  

Page 51: Introduction to Artificial Neural Network

How to deal with errors

X

Σ yf

InputOutput

1

1

-0.166

-1.000

-0.395

1 0.441

1

Σ = (-0.166)×1 + 0.441×1 + (-1)×1 + (-0.395)×1 = -1.12

f(-1.12) = 1/(1+e-1.12) = 0.246

Error = 1 – 0.246 = 0.754

Sample   Feature  1   Feature  2   Feature  3   Target  

Sample  1   1   1   1   1  

Page 52: Introduction to Artificial Neural Network

11+ e−z

z   zupdate  

•  Target:  1  •  Es-ma-on:  0.246    

Error  0.754  

Page 53: Introduction to Artificial Neural Network

11+ e−z

z   zupdate  

•  Target:  1  •  Es-ma-on:  0.246    

Error  0.754  

We  want  to  increase  the  weights  next  -me  to  have  larger  z  

Page 54: Introduction to Artificial Neural Network

Weights  delta  =  0.754 ×  slope  ×  input  

Page 55: Introduction to Artificial Neural Network

z  

df (z)dx

= f (z)(1− f (z))

z = -1.12 f(z) = 0.246 slope = 0.246 × (1 - 0.246) = 0.185

Page 56: Introduction to Artificial Neural Network

Change  item  =  0.754 ×  0.185  ×      1  1  1  1  

0.139  0.139  0.139  0.139  

=  

Page 57: Introduction to Artificial Neural Network

-­‐0.166    0.441  -­‐1.000  -­‐0.395  

0.139  0.139  0.139  0.139  

Updated  Weights  

+   =  

-­‐0.027    0.580  -­‐0.861  -­‐0.256  

=  

Changes of the error

Original  Weights  

updates  

Page 58: Introduction to Artificial Neural Network

-­‐0.166    0.441  -­‐1.000  -­‐0.395  

0.139  0.139  0.139  0.139  

Updated  Weights  

z = (-0.027)×1 + 0.580×1 + (-0.861)×1 + (-0.256) ×1 = -0.564

f(z) = 0.637

Error = 1 – 0.637 = 0.363  

+   =  

-­‐0.027    0.580  -­‐0.861  -­‐0.256  

=  

Changes of the error

Error of next iteration

Page 59: Introduction to Artificial Neural Network

Changes of the error

0.754  

0.363  

Page 60: Introduction to Artificial Neural Network

Iterate many times

Page 61: Introduction to Artificial Neural Network

Go to notebook 01  

Page 62: Introduction to Artificial Neural Network

Application: DeepDrumpf

h"ps://twi"er.com/DeepDrumpf  

Page 63: Introduction to Artificial Neural Network
Page 64: Introduction to Artificial Neural Network

Perceptron limitations

Page 65: Introduction to Artificial Neural Network

Winter of ANN

Page 66: Introduction to Artificial Neural Network

Multi-Layer Perceptron

Page 67: Introduction to Artificial Neural Network

X

Σ yf

Input

Output1

feature2

feature3

X – input datay – output targetΣ – summationf – activation functionblue circle - bias

feature1

Hidden1 Σ | f

Hidden3 Σ | f

Hidden4 Σ | f

Hidden2 Σ | f

1

Page 68: Introduction to Artificial Neural Network

X

Σ yf

Input

Output1

feature2

feature3

X – input datay – output targetΣ – summationf – activation functionblue circle - bias

feature1

Hidden1 Σ | f

Hidden3 Σ | f

1

Page 69: Introduction to Artificial Neural Network

X

Σ yf

Input

Output1

feature2

feature3

X – input datay – output targetΣ – summationf – activation functionblue circle - bias

feature1

Hidden1 Σ | f

Hidden3 Σ | f

Hidden4 Σ | f

Hidden2 Σ | f

1

Page 70: Introduction to Artificial Neural Network

X

Σ yf

Input

Output1

feature2

feature3

feature1

Hidden1 Σ | f

Hidden3 Σ | f

Hidden4 Σ | f

Hidden2 Σ | f

1

Page 71: Introduction to Artificial Neural Network

Go to notebook 02  

Page 72: Introduction to Artificial Neural Network

Workshop time

Lear

ning

cur

ve

Gentle introduction •  What’s ML •  ANN history •  ANN overview

Step by step ANN •  Perceptron •  Backpropagation

Real world example •  Sklearn example

Page 73: Introduction to Artificial Neural Network

h"p://richzhang.github.io/colorizaXon/  h"p://wha"ogive.com/videoColourizaXon/  

Application: Colourization

Page 74: Introduction to Artificial Neural Network
Page 75: Introduction to Artificial Neural Network
Page 76: Introduction to Artificial Neural Network

Go to notebook 03  

Page 77: Introduction to Artificial Neural Network
Page 78: Introduction to Artificial Neural Network
Page 79: Introduction to Artificial Neural Network

If you want to learn more …

h"p://dlab.berkeley.edu/training  

Page 80: Introduction to Artificial Neural Network

Some useful resources •  h"p://iamtrask.github.io/2015/07/12/basic-­‐python-­‐network/  •  h"ps://seat.massey.ac.nz/personal/s.r.marsland/MLBook.html  •  h"p://sebasXanraschka.com/ArXcles/2015_singlelayer_neurons.html  •  h"p://www.emergentmind.com/neural-­‐network  •  h"p://neuralnetworksanddeeplearning.com/  •  h"ps://www.coursera.org/learn/neural-­‐networks  

You  can  also  find  most  of  today’s  workshop  material  on  my  blog:  h"p://qingkaikong.blogspot.com/2016/10/machine-­‐learning-­‐1-­‐what-­‐is-­‐machine.html  

I  thank  all  the  authors  of  the  above  links,  as  well  as  a  lot  of  the  images  I  got  from  internet.    

Page 81: Introduction to Artificial Neural Network