Slide 1 - Alpha Control Lab

Modelleerimine ja Juhtimine
Tehisnärvivõrgudega
Identification and Control with
artificial neural networks
Eduard Petlenkov,
(2nd
part)
Automaatikainstituut
Eduard Petlenkov, Automaatikainstituut, 2015
Supervised learning
Supervised learning is a training algorithm based on known input-output
data.
Y p  NN ( X )  Y p  Y  0
X is an input vector;
Yp is a vector of reference outputs corresponding to input vector X
Y is a vector of NN’s outputs corresponding to input vector X
NN is a mathematica function of the network
(Y=NN(X))
Eduard Petlenkov, Automaatikainstituut, 2015
Õpetamine (2)
Network training procedure consists of the following 3 steps:
1.
2.
3.
Computation of NN’s outputs corresponding to the
current NN’s paraneters;
Computation of NN’s error;
Updating NN’s parameters by using selected training
algorithm in order to minimize the error.
Eduard Petlenkov, Automaatikainstituut, 2015
Gradient descent error backpropagation (1)
J (W , )   (Y p  Y pd ) 2
Error function:
k
Yp
- NN’s output
Y p  NN ( X p , W , )
X p - inputs used for training;
NN - NN’s function;
Ypd
- etalons (references) for outputs=desired outputs.
function to be minimized:
min J (W , )
Eduard Petlenkov, Automaatikainstituut, 2015
Gradient descent error backpropagation (2)
F ( x1 , xn )
J (W , )
Eduard Petlenkov, Automaatikainstituut, 2015
 F F 

F ( x1 , xn )  

 x1 x2 
 F
F 


 F ( x1 , xn )   

x2 
 x1
 J
 J (W , )   
 W

J 

 
Global minimum problem
Eduard Petlenkov, Automaatikainstituut, 2015
Training of a double-layer perceptron using Gradient descent error
backpropagation (1)
yh j (t )  F1 (Wh ji (t ) x i (t )  Bh j (t ))
i
y k (t )  F2 (Wo kj (t ) yhi (t )  Bo k (t ))
i
i - number of input;
j – number of neuron in the hidden layer;
t
k – number of output neuron;
;
x i (t ) NN’s input at time instance
t;
Wh ji (t ) - Values oh the hidden layer weighting coefficients at time instance t;
Bh j (t ) - Values oh the hidden layer biases at time instance t;
F1
- Activation function of the hidden layer neurons
yh j (t ) - Outputs of the output layer neurons at time instance t;
Wo kj (t ) - Values oh the output layer weighting coefficients at time instance t;
Bo k (t ) - Values oh the output layer biases at time instance t;
F2
- Activation function of the output layer neurons;
y k (t ) - Outputs of the network at time instance t;
Eduard Petlenkov, Automaatikainstituut, 2015
Training of a double-layer perceptron using Gradient descent error
backpropagation (2)
error:
gradients:
e(t )  y(t )  yetalon (t )
J
  j (t ) xi (t )
Wij
J
  k (t ) yh j (t )
Wkj
Signals distributing information about error from output layer to
 j (t ),  k (t )
previous layers (that is why the method is called error
backpropagation):
 k (t )  ( y k (t )  y kd (t ))  F2
 j (t )  F1    k (t )  Wokj (t )
k
F1, F2 Are derivatives of the corresponding layers activation functions.
Eduard Petlenkov, Automaatikainstituut, 2015
Training of a double-layer perceptron using Gradient descent error
backpropagation (3)
Updated weighting coefficients:
Wokj (t  1)  Wokj (t )   
Wh ji (t  1)  Wh ji (t )  
J
 Wokj (t )   k (t ) yh j (t )
Wokj
J
 Wh ji (t )  j (t ) xi (t )
Wh ji
 learning rate
1
e x
f ( x) 
 f ' ( x) 
x
1 e
1  e x

Eduard Petlenkov, Automaatikainstituut, 2015

2
1
1


x
1 e
1  e x


2
 f ( x)  f 2 ( x)
Gradient Descent (GD) method vs Levenberg-Marquardt (LM) method
Z n  ut , yt , t  1,, N 
1
J  , Z N  
2N
J  , Z N  1
G   


N
N
 yt   yˆ t 
2
t 1
1

2N
N
 et , 
2
t 1
et , 
et ,  



t 1
N
- Gradient
 2 J  , Z N  1 N et ,   et , 
1
H   



  
 T
N


N
 

t 1


T
 2 et , 
et , 

T




t 1
N
- Hessian
R  
GD:
 k 1   k   G 
Eduard Petlenkov, Automaatikainstituut, 2015
LM:
 k 1   k    k 
R k   I  k   G k 
  k 
Näide MATLABis (1)
P1=(rand(1,100)-0.5)*20
P2=(rand(1,100)-0.5)*20
P=[P1;P2]
% Juhuslikud sisendid. 100 väärtust vahemikus [-10 +10]
% Närvivõrgu sisendite moodustamine
T=0.3*P1+0.9*P2 % Vastavate väljundite arvutamine
net=newff([-10 10;-10 10],[5 1],{'purelin' 'purelin'},'traingd')
esimene sisend
[min max]
teinesisend
[min max]
neuronite arvud
igas kihis
Viimase kihi
neuronite arv =
väljundite arv
Teise kihi neuronite
aktiveerimisfunktsioon
Esimese kihi neuronite
aktiveerimisfunktsioon
net.trainParam.show=1;
net.trainParam.epochs=100;
% Närvivõrgu genereerimine
Treenimise parameetrid
õppimisalgoritm
Näide MATLABis (2)
net=train(net,P,T)
% Närvivõrgu treenimine
out=sim(net,[3 -2])
% Närvivõrgu simuleerimine
Teise sisendi
väärtus
Esimese sisendi
väärtus
W1=net.IW{1,1} % esimese kihi kaalukoefitsientide maatriks
W2=net.LW{2,1} % teise kihi kaalukoefitsientide maatriks
B1=net.b{1} % esimese kihi neuronite nihete vektor
B2=net.b{2} % teise kihi neuronite nihete vektor
Eduard Petlenkov, Automaatikainstituut, 2015