Documente Academic
Documente Profesional
Documente Cultură
p 1
w 1
p w
2 2
+
b
p n
w n
for n=2
w1 p1 + w 2 p 2 = b
n
a = g wi p i b = g ( w t p b ) a [ 0;1] p
i =1 2
g = step function
B
The euclidian space n is divided in two regions A and B
p
1
Laboratrio de Automao e Robtica - A. Bauchspiess Soft Computing - Neural Networks and Fuzzy Logic 51
The McCulloch Neuron
as patterns classifier
o x o
o o
o o o
o o
o x o x
x x o x
x x
x x x x x x
Laboratrio de Automao e Robtica - A. Bauchspiess Soft Computing - Neural Networks and Fuzzy Logic 52
Linear and Non-Linear Classifiers
There exist 2 =2
m 2n
possible logical functions connecting n inputs to one binary output.
A, A , 0, 1
A, B, A , B , 0, 1
A B, A B, A B, A B,
A B , A B , A B , A B , A B, A B
Laboratrio de Automao e Robtica - A. Bauchspiess Soft Computing - Neural Networks and Fuzzy Logic 53
Two Step Binary Perceptron
Laboratrio de Automao e Robtica - A. Bauchspiess Soft Computing - Neural Networks and Fuzzy Logic 54
Three Step Binary Perceptron
w
1 3
3 w 3 9
p 2
w 1
4 4 9
9 A
w 5 9
A B
p
1
5
a 1 1
10
p
2
p 1
6
1
B
a =A B
11 ^
7 10
Laboratrio de Automao e Robtica - A. Bauchspiess Soft Computing - Neural Networks and Fuzzy Logic 55
Neurons and Artificial Neural Networks
Micro-structure
characteristics of each neuron in the network
Meso-Structure
organization of the network
Macro-Structure
association of networks, eventually with some analytical processing
approach for complex problems
p
1
w 1
p w
2 2
+
b Bias input
p w
n n
Bias:
with p=0,
output 0 still possible !
Laboratrio de Automao e Robtica - A. Bauchspiess Soft Computing - Neural Networks and Fuzzy Logic 56
Typical activation functions
Linear f ( s) = s Hopfield purelin f(s)
BSB
s
-1
Laboratrio de Automao e Robtica - A. Bauchspiess Soft Computing - Neural Networks and Fuzzy Logic 57
Typical activation functions
Laboratrio de Automao e Robtica - A. Bauchspiess Soft Computing - Neural Networks and Fuzzy Logic 58
Meso-Structure Network Organization...
1- Multilayer Feedforward
Laboratrio de Automao e Robtica - A. Bauchspiess Soft Computing - Neural Networks and Fuzzy Logic 59
Meso-Structure Network Organization...
3 Bilayers Feedforward/Feedbackward
Laboratrio de Automao e Robtica - A. Bauchspiess Soft Computing - Neural Networks and Fuzzy Logic 60
Meso-Structure Network Organization
5 Hybrid Network
Sub- Sub-
Network
Rede 1 Network
Rede 2
1 2
Laboratrio de Automao e Robtica - A. Bauchspiess Soft Computing - Neural Networks and Fuzzy Logic 61
Neural Macro-Structure
Rede
NetW. 1
- # networks
- connection type
- size of networks
Rede 2a
NetW.2 Rede
NetW. 2b Rede
NetW. 2c
- degree of connectivity
Rede
NetW. 3
Laboratrio de Automao e Robtica - A. Bauchspiess Soft Computing - Neural Networks and Fuzzy Logic 62
Supervised Learning
d
-
x y
w w + x dy
Delta Rule Perceptron __
learning rate
Widrow-Hoff delta rule (LMS) ADALINE, MADALINE
j x ij
wij wij +
x k2
Laboratrio de Automao e Robtica - A. Bauchspiess Soft Computing - Neural Networks and Fuzzy Logic 63
Delta rule Perceptron
d
Perceptron Rosenblatt, 1957 -
x y
Dynamics: __
sj = w
i
ij pij + bj
1 bj
+ 1 se s j 0
y j = f (s j ) = p w
0 se s j < 0
1 j 1 j
p w sj
yj
2 j 2 j
+
pn j
w n j
j = dj yj
Laboratrio de Automao e Robtica - A. Bauchspiess Soft Computing - Neural Networks and Fuzzy Logic 64
ADALINE and MADALINE
Widrow & Hoff, 1960 (Mult.) Adaptive Linear Element
y j = wij pij + b j
i
Training:
j = d j sj = d j
wij pij + b j
j xij
wij wij +
x 2
k
Widrow-Hoff delta rule
LMS Least Mean Squared algorithm
0.1< <1 stability and convergency speed.
MatLab: NEWLIN, NEWLIND, ADAPT, LEARNWH
Laboratrio de Automao e Robtica - A. Bauchspiess Soft Computing - Neural Networks and Fuzzy Logic 65
LMS Algorithm
Objective: learn a function f : n from the samples (xk, dk)
Expected value
E[e2] = E[(d-y)2]
= E[(d-xwt)2]
= E[d2 ] 2E[dx]wt + wE [xtx] wt
Assuming w deterministic.
With
E [xtx] R autocorrelation input matrix
E [dx] P cross correlated vector Optimal analytic
w* = PR-1 solution of the
E[e2 ] = E[d2 ] 2Pwt + wRwt optimization
(solvelin.m)
0 = 2w*R 2P
Laboratrio de Automao e Robtica - A. Bauchspiess Soft Computing - Neural Networks and Fuzzy Logic 66
Iterative LMS Algorithm
Objective: adaptively learn a function f : n from the samples (xk, dk)
w E[e2 ] = 2wR 2P
Post-multiplyting by R-1
w* = w w E[e2 ] R-1 i
*
Laboratrio de Automao e Robtica - A. Bauchspiess Soft Computing - Neural Networks and Fuzzy Logic 67
Iterative LMS Algorithm...
assuming R = I estimated steppest decent algorithm:
wk+1 = wk ck w e2k
(d k yk ) 2 ( d k yk ) 2
= , L
i
w1 wn *
y y
= 2 (d k yk ) k , L 2(d k yk ) k
w1 wn j xij
wij wij +
y
= 2ek k , L
yk
x k2 Norma-
lization
1w wn
[ ]
Iterative (adaptive) solution
= 2ek x , L x = 2ek x k
1
k
n
k ( yk = x k w ) t
k
(The optimal solution is never reached!)
MADALINE i-input, j-neuron
LMS algorithm reduces to wk+1 = wk + 2ck ek xk
Laboratrio de Automao e Robtica - A. Bauchspiess Soft Computing - Neural Networks and Fuzzy Logic 68
The Multilayer Perceptron
- The Generalized Delta Rule
Rumelhart, Hinton e Williams, PDP/MIT, 1986
p1 = x1(0) x1(1)
x1(2) = y1
x2(1)
p2 = x2(0)
x2(2) = y2
p3 = x3(0)
x3(1)
Neuron Dynamics:
Laboratrio de Automao e Robtica - A. Bauchspiess Soft Computing - Neural Networks and Fuzzy Logic 69
The generalized delta rule
Training p1 = x1( 0) x1(1)
x1(2) = y1
m
=
2
j =1
(d j y j )2 - quadratic error p2 = x2(0)
x 2(1)
x2(2) = y2
Instantaneous gradient:
so (jk ) = ( k ) = ( k ) x (jk 1)
2 2
2 2 2 2 w j s j
(jk ) = = (k ) , , L
w j
(k )
w0 j w1 j
(k )
wmj
(k )
1 2
Defining the quadratic derivative error as (k )
j =
2 s (jk )
s j
(k )
2 2
(jk ) = =
w (jk ) s (jk ) w (jk ) (jk ) = 2 (j k ) x (jk 1) Gradient of the error with respect
to the weights as function of the
former layer signals!!
Laboratrio de Automao e Robtica - A. Bauchspiess Soft Computing - Neural Networks and Fuzzy Logic 70
The generalized delta rule...
p1 = x1( 0) x1(1)
For the output layer, the quadratic derivative error is: x1(2) = y1
x 2(1)
Nk Nk p2 = x2(0)
1
i =1
( d i yi ) 2
1
i =1
( d i f ( si( k ) )) 2 x2(2) = y2
(j k ) = = p3 = x3( 0)
2 s (jk ) 2 s (jk ) x3(1)
1 ( d j f ( s j )) ( k ) ( d j f ( s j ))
(k ) 2 (k )
(j k ) = = ( d j f ( s j )) = ( d j x (k )
j ) f ( s (k )
j )
2 s (jk ) s (jk )
(jk ) = d j x (jk ) = d j y j
Giving:
(j k ) = (jk ) . f ( s (jk ) )
Remember,
activation function, f, continuous differentiable
Laboratrio de Automao e Robtica - A. Bauchspiess Soft Computing - Neural Networks and Fuzzy Logic 71
The generalized delta rule...
p1 = x1( 0) x1(1)
For a hidden layer k, the quadratic derivative error x1(2) = y1
can be calculated using the linear outputs of layer k+1: x 2(1)
p2 = x2(0)
x2(2) = y2
considering
1 2 si( k +1) N k +1 ( k +1) si( k +1)
N k +1
= ( k ) = i s j
(k )
f( )
sl
(k )
= 0 if l j and that
s j
(k )
( )
f s (jk ) = f s (jk ) ( )
( k +1) (k )
i =1 2 si si i =1 si
Nk
We have: (k )
j ( )
N k +1 ( k +1) ( k +1)
= i w ji . f s (jk ) ( )
Taking into account that s (jk ) = w0( kj ) + wij( k ) xi( k 1) 1i =41
42443
i =1 (k )
j
N k +1
( )
( k +1) Nk
( k +1)
(j k ) = i si( k )
w
0i
+ wli( k +1) f sl( k )
Finally, the quadratic derivative errror for a hidden layer:
i =1 l =1
(j k ) = (jk ) . f ( s (jk ) )
( )
N k +1 Nk
(k )
j = ( k +1)
i wli( k +1)
si( k )
f sl( k )
i =1 l =1
Laboratrio de Automao e Robtica - A. Bauchspiess Soft Computing - Neural Networks and Fuzzy Logic 72
The Error Backpropagation algorithm
3. k last layer
4. for each element j in the layer k do:
Compute (kj ) using (jk ) = d j x (jk ) = d j y j if k is the last layer,
N k +1
(k )
j = i( k +1) w(jik +1) if it is a hidden layer;
i =1
Laboratrio de Automao e Robtica - A. Bauchspiess Soft Computing - Neural Networks and Fuzzy Logic 73
The Backpropagation Algorithm in practice
5 BP variants
- trainbpm (with momentum) Padro recuperado
Optimum
PadresMinima
Local armazenados
- trainbpx (adaptive learning rate)
- ....
wi,j
Estados
- trainlm (Levenberg-Marquard J, Jacobian)
e2(wi,j) - Illustrative quadratic error
W (j k ) = ( J T J + J ) 1 J T e as function of the weights
Laboratrio de Automao e Robtica - A. Bauchspiess Soft Computing - Neural Networks and Fuzzy Logic 74
Computational Tools
SNNS
MatLab
- Neural Network Toolbox
NeuralWorks
Java
C++
Laboratrio de Automao e Robtica - A. Bauchspiess Soft Computing - Neural Networks and Fuzzy Logic 75
SNNS - Stuttgarter Neural Network Simulator
Laboratrio de Automao e Robtica - A. Bauchspiess Soft Computing - Neural Networks and Fuzzy Logic 76
MatLab
- complete environment purelin
Model Reference Controller
Reference
model liq 4 order
-System Simulation logsig qi
Neural
Network Control qi h4
Controller Signal h4
-Training tansig
Plant Output
h4
-Control Scope
radbas
3 f(u)
1 y(n)=Cx(n)+Du(n)
y
Fcn1 z x(n+1)=Ax(n)+Bu(n) K*u
Unit Delay 1 Discrete State -Space 2 Matrix
Gain 4
-C-
Constant 3
Switch 1 f(u)
Fcn2
f(u) 1 y(n)=Cx(n)+Du(n)
2 K*u
u z x(n+1)=Ax(n)+Bu(n) + K*u
Fcn +
Unit Delay 5 Discrete State -Space 1 Matrix
tansig Matrix
Gain 3
-C- Gain 1 netsum 1 purelin -C-
netsum 1
Constant 2 Constant 4 uhat
Switch Switch 2 Saturation 1 Zero -Order
Hold
B2_c
Constant 7
1 f(u) y(n)=Cx(n)+Du(n)
r K*u
x(n+1)=Ax(n)+Bu(n)
Fcn3
Discrete State -Space 3 Matrix
Gain 2
-C-
Constant 5 B1_c
Switch 3
Constant 6
Laboratrio de Automao e Robtica - A. Bauchspiess Soft Computing - Neural Networks and Fuzzy Logic 77
Demonstration - Perceptron
% Perceptron
% Training an ANN to learn to classify a non-linear problem
% Input Pattern
P=[ 0 0 0 0 1 1 1 1
0 0 1 1 0 0 1 1 T= 1 0 1 1 1 0 1 0
0 1 0 1 0 1 0 1]
% Target Y= 1 0 1 1 1 0 1 0
%T=[1 0 1 1 1 0 1 0] % Linear separable
T=[1 0 0 1 1 0 1 0] % non separable
Y=sim(net,P)
Laboratrio de Automao e Robtica - A. Bauchspiess Soft Computing - Neural Networks and Fuzzy Logic 78
Demonstration - OCR
Training Vector
20 % Noise
ANN
Laboratrio de Automao e Robtica - A. Bauchspiess Soft Computing - Neural Networks and Fuzzy Logic 79
Demonstration OCR...
% of missclassifications Neural OCR Classifier
1 3
g1 (0 79.9 sec) = g 2 (80 150 sec) =
s 2 + 0.2 s + 1 s 2 + 2s + 1
-2
Laboratrio de Automao e Robtica - A. Bauchspiess Soft Computing - Neural Networks and Fuzzy Logic 81
Demo LMS, ADALINE, FIR...
% ADALINE - Adaptive dynamic system identification
% First sampled system - until 80 sec
g1=tf(1,[1 .2 1]), gd1=c2d(g1,.1)
% Sytem changes dramatically - after 80 sec
g2=tf(3,[1 2 1]),gd2=c2d(g2,.1)
% time vector
...
[y1,t1,x1]=lsim(gd1,u1,t1);
[y2,t2,x2]=lsim(gd2,u2,t2,x1);
net=newlin(t,y,[1 2 3 4 5 6 7 8 9 10],0.09)
[net,Y,E]=adapt(net,t,y)
Laboratrio de Automao e Robtica - A. Bauchspiess Soft Computing - Neural Networks and Fuzzy Logic 82
Demo LMS, ADALINE, FIR...
RMSE Set 1=6.5742 u=idinput(1500,'PRBS',[0 0.01])
4
2 n=10, lr=0.1
0
-2
-4
0 500 1000 1500
ADALINE
Error
Learns System AND 4
-2
-4
0 500 1000 1500
10
RMSE Set 2=22.7817 u=idinput(1200,'PRBS',[0 0.05])
-5
0 200 400 600 800 1000 1200
Laboratrio de Automao e Robtica - A. Bauchspiess Soft Computing - Neural Networks and Fuzzy Logic 83