Lecture 6

advertisement
Artificial Neural Networks
.
.
.
.
.
Shreekanth Mandayam
Robi Polikar
….
…

netk
..

..
……

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Function Approximation
 Constructing complicated functions from simple building blocks
 Lego systems
 Fourier / wavelet transforms
 VLSI systems
 RBF networks
Function Approximation
.
.
.
.
.
*
*
*
*
*
*
?
*
*
*
*
Function Approx. Vs.
Classification
.
.
.
.
.
 Classification can be thought of as a special case of function
approximation:
 For a three class problem:
x1
….
x
Class 1: [1 0 0]
Classifier
Class 2: [0 1 0]
Class 3: [0 0 1]
xd
x1
….
x
Classifier
xd
d-dimensional input
x
y=f(x)
1: Class 1
2: Class 2
3: Class 3
1 or 3, c-dimensional input
y
Radial Basis Function
Neural Networks
.
.
.
.
.
………..
 The RBF networks, just like MLP networks, can therefore be used
classification and/or function approximation problems.
 The RBFs, which have a similar architecture to that of MLPs,
however, achieve this goal using a different strategy:
Input layer
Nonlinear
transformation layer
Linear output
layer
(generates local receptive fields)
.
.
.
.
.
Nonlinear Receptive Fields
 The hallmark of RBF networks is their use of nonlinear receptive
fields
 RBFs are universal approximators !
 The receptive fields nonlinearly transforms (maps) the input
feature space, where the input patterns are not linearly separable, to
the hidden unit space, where the mapped inputs may be linearly
separable.
 The hidden unit space often needs to be of a higher dimensionality
 Cover’s Theorem (1965) on the separability of patterns: A complex
pattern classification problem that is nonlinearly separable in a low
dimensional space, is more likely to be linearly separable in a high
dimensional space.
The (you guessed it right) XOR Problem
.
.
.
.
.
x2
Consider the nonlinear functions to map the input vector x to the 1- 2 space
1
x=[x1 x2]
1 (x )  e
 2 (x)  e
0
0
t1  [1 1]T
 xt2 2
t 2  [0 0]T
x1
1
Input x
1(x)
2(x)
1.0
(1,1)
1
0.1353
0.8
(0,1)
0.3678
0.3678
(1,0)
0.3678
0.3678
(0,0)
 x  t1 2
0.1353
1

0.6
0.4
0.2
0
_ (1,1)
_
_
_
_
_
0
(0,1)
(1,0)
(0,0)
|
0.2
|
|
0.4 0.6
|
|
0.8 1.0
|
1.2
The nonlinear  function transformed a nonlinearly separable problem into a linearly separable one !!!
.
.
.
.
.
Initial Assessment
 Using nonlinear functions, we can convert a nonlinearly separable
problem into a linearly separable one.
 From a function approximation perspective, this is equivalent to
implementing a complex function (corresponding to the nonlinearly
separable decision boundary) using simple functions (corresponding
to the linearly separable decision boundary)
 Implementing this procedure using a network architecture, yields the
RBF networks, if the nonlinear mapping functions are radial basis
functions.
 Radial Basis Functions:
 Radial: Symmetric around its center
 Basis Functions: A set of functions whose linear combination can
generate an arbitrary function in a given function space.
RBF Networks
.
.
.
.
.
d input
nodes
H hidden layer RBFs
(receptive fields)
x1
Uji
Wkj
H
 H

zk  f netk   f  wkj y j    wkj y j


 j 1
 j 1
Linear act. function
netk
j y
j
zc
…
x(d-1)
H
xd
z1
..
……....
x2
c output
nodes
..
……...
1
x1
 netJ  x  uJ
uJi

U  XT
xd

2
 x uJ 

 


e 
: spread constant
Principle of Operation
.
.
.
.
.
Euclidean Norm
x1
 netJ  x  uJ
UJi

xd

 x uJ
 

e 



2
: spread constant
y1
wKj

yJ

H
 H

zk  f netk   f  wkj y j    wkj y j


 j 1
 j 1
yH
Unknowns: uji, wkj, 
.
.
.
.
.
Principle of Operation
 What do these parameters represent?
 Physical meanings:
• : The radial basis function for the hidden layer. This is a simple nonlinear
mapping function (typically Gaussian) that transforms the d- dimensional
input patterns to a (typically higher) H-dimensional space. The complex
decision boundary will be constructed from linear combinations (weighted
sums) of these simple building blocks.
• uji: The weights joining the first to hidden layer. These weights constitute the
center points of the radial basis functions.
• : The spread constant(s). These values determine the spread (extend) of
each radial basis function.
• Wjk: The weights joining hidden and output layers. These are the weights
which are used in obtaining the linear combination of the radial basis
functions. They determine the relative amplitudes of the RBFs when they are
combined to form the complex function.
RBFN
Principle of Operation
.
.
.
.
.
wJ:Relative weight
of Jth RBF
J: Jth RBF function
J
*
uJ Center of Jth RBF
.
.
.
.
.
How to Train?
 There are various approaches for training RBF networks.
 Approach 1: Exact RBF – Guarantees correct classification of all training
data instances. Requires N hidden layer nodes, one for each training
instance. No iterative training is involved. RBF centers (u) are fixed as
training data points, spread as variance of the data, and w are obtained by
solving a set of linear equations
 Approach 2: Fixed centers selected at random. Uses H<N hidden layer
nodes. No iterative training is involved. Spread is based on Euclidean
metrics, w are obtained by solving a set of linear equations.
 Approach 3: Centers are obtained from unsupervised learning
(clustering). Spreads are obtained as variances of clusters, w are obtained
through LMS algorithm. Clustering (k-means) and LMS are iterative. This
is the most commonly used procedure. Typically provides good results.
 Approach 4: All unknowns are obtained from supervised learning.
Approach 1
.
.
.
.
.
 Exact RBF
 The first layer weights u are set to the training data; U=XT. That is the
gaussians are centered at the training data instances.
d max


 The spread is chosen as
2 N , where dmax is the maximum Euclidean
distance between any two centers, and N is the number of training data
points. Note that H=N, for this case.
 The output of the kth RBF output neuron is then
N
N
zk  (w
wjkj)   x  u j
j 1
Multiple
outputs
z   w j  x  u j
Single output
j 1
 During training, we want the outputs to be equal to our desired targets.
Without loss of any generality, assume that we are approximating a single
dimensional function, and let the unknown true function be f(x). The
desired output for each input is then di=f(xi), i=1, 2, …, N.
(Not to be confused with input dimensionality d)
Approach 1
.
.
.
.
.
(Cont.)
 We then have a set of linear equations, which can be represented in
the matrix form:
N
z   w j  x  u j
j 1
y
 11 12  1N   w1   d1 

 w  d 



22
2N   2   2 
 21


 


       

    




N
1
N
2
NN

  wN   d N 
 ij   xi  x j , (i, j )  1,2,..., N
Define:
d  [d1, d 2 ,d N ]T
w  d
w  [ w1, w2 , wN ]T
w   1d

   ij | (i, j )  1,2,..., N

Is this matrix always invertible?
Approach 1
.
.
.
.
.
(Cont.)
 Michelli’s Theorem (1986)
 If {xi}iN=1 are a distinct set of points in the d-dimensional space, then the
N by N interpolation matrix  with elements obtained from radial basis
functions  ij   xi  x j is nonsingular, and hence can be inverted!
 Note that the theorem is valid regardless the value of N, the choice of
the RBF (as long as it is an RBF), or what the data points may be, as long
as they are distinct!
 A large number of RBFs can be used:
• Multiquadrics:
• Inverse multiquadrics:
• Gaussian functions:

 ( r )  r 2  c2
 (r) 
1/ 2
for some c  0, r  
1
r 2  c2 1/ 2

r2
 (r)  e
2 2
r  xxj

for some   0, r  
Approach1
.
.
.
.
.
(Cont.)
 The Gaussian is the most commonly used RBF (why…?).
 Note that
as r  ,  ( r )  0
 Gaussian RBFs are localized functions ! unlike the sigmoids used by MLPs
Using Gaussian radial basis functions
Using sigmoidal radial basis functions
.
.
.
.
.
Exact RBF Properties
 Using localized functions typically makes RBF networks more suitable for
function approximation problems. Why?
 Since first layer weights are set to input patterns, second layer weights are
obtained from solving linear equations, and spread is computed from the
data, no iterative training is involved !!!
 Guaranteed to correctly classify all training data points!
 However, since we are using as many receptive fields as the number of
data, the solution is over determined, if the underlying physical process
does not have as many degrees of freedom  Overfitting!
 The importance of : Too small will
also cause overfitting. Too large will
fail to characterize rapid changes in
the signal.
Too many
Receptive Fields?
.
.
.
.
.
 In order to reduce the artificial complexity of the RBF, we need to
use fewer number of receptive fields.
 How about using a subset of training data, say M < N of them.
 These M data points will then constitute M receptive field centers.
 How to choose these M points…?
 At random  Approach 2.
 M

xi x j
 d2
2
 e max
y j   ij    xi  x j 


2


,
i  1,2,..., N
j  1,2,..., M

d max
2M
Output layer weights are determined as they were in Approach 1, through solving a
set of M linear equations!
 Unsupervised training: K-means  Approach 3
The centers are selected through self organization of clusters, where the
data is more densely populated. Determining M is usually heuristic.
K-Means - Unsupervised
Clustering - Algorithm
Approach 3
.
.
.
.
.
 Choose number of clusters, M
 Initialize M cluster centers to the first M training data points: tk=xk, k=1,2,…,M.
 Repeat
 At iteration n, group all patterns to the cluster whose center is closest
tk(n): center of kth RBF at
C (x)  arg min x(n)  t k (n) , k  1,2,..., M
nth iteration
k
 Compute the centers of all clusters after the regrouping
Mk
New cluster center
for kth RBF.
tk 
1
Mk
x j
j 1
Instances that are grouped
in the kth cluster
Number of instances
in the kth cluster
 Until there is no change in cluster centers from one iteration to the next.
An alternate k-means algorithm is given in Haykin (p. 301).
.
.
.
.
.
Determining the Output Weights:
LMS Algorithm
Approach 3
 The LMS algorithm is used to minimize the cost function
T
e(n) is the error at iteration n: e(n )  d (n)  y (n) w(n )
E ( w)
e(n)
 e(n)
w(n)
w
e(n)
  y(n)
w
1
E ( w )  e2 ( n )
2
E ( w)
  y (n)e(n)
w(n)
 Using the steepest (gradient) descent method: w( n  1)  w(n )  y (n )e(n )
Instance based LMS algorithm pseudocode (for single output):
Initialize weights, wj to some small random value, j=1,2,…,M
Repeat
Choose next training pair (x, d);
M
Compute network output at iteration n: z ( n )   w j   x  x j  wT  y
Compute error:
e( n )  d ( n )  z ( n )
Update weights: w( n  1)  w(n )  e(n ) y ( n )
Until weights converge to a steady set of values
j 1
where
.
.
.
.
.
Approach 4:
Supervised
RBF Training
 This is the most general form.
 All parameters, receptive field centers (first layer weights), output layer weights
and spread constants, are learned through iterative supervised training using LMS /
gradient descent algorithm.
1 N 2
E  e j
2 j 1
e j  d j   wk x j  t i


   x
j
M

i 1
G x j  ti
C
 ti

G’ represents the first derivative
of the function wrt its argument
.
.
.
.
.
RBF Matlab Demo
.
.
.
.
.
RBF Lab
Due: Friday , March 15
1. Implement the Exact RBF approach in MATLAB (writing your
own code) on a simple one-dimensional function approximation
problem, as well as a classification problem. Generate your own
function approx. example, and use the IRIS database for
classification (from UCI – ML database). Compare your results to
that of MATLAB’s built-in function
2. Implement Approach 2, using the code you generated for Q1.
3. Implement Approach 3. Write your own K-means and LMS codes.
Compare your results to that of MATLAB’s newrb() function, both
for function approximation and classification problems.
4. Apply your algorithms to the Dominant VOC gas sensing database
(available in \\galaxy\public1\polikar\PR_Clinic\Databases for PR
Class.
Download