Professional Documents
Culture Documents
Bodgan M. Wilamowski
Relatively complex
nonlinear
li mapping
i
Question:
What is given?
(a) Mathematical function
No need for design – just use microcomputer for
calculations
(b) Experimental data
- Find an analytical functions describing the process ???
- Use a data to train neural networks
w i c x
where c is the learning constant
Hebb rule w i c o x
6
Supervised learning rules for single neuron
w i c x
correlation rule (supervised): d
perceptron fixed rule: d o
perceptron adjustable rule - as above but the learning constant is modified to:
x wT net
T 2
*
xx x
LMS (Widrow-Hoff) rule: d net
delta rule: d o f '
w x T x x T d
1
pseudoinverse
d i rule
l (the
(th same as LMS):
LMS)
7
Training Neurons
w i x i
Perceptron learning rule:
d o
w i x i d sign ( net )
A
Assuming
i bibipolar
l neurons
output = ±1 w i x i 2
8
Simple example of training one neuron
neuron
3 y
x
1
((1,2)
, ) => -1
3
2 y
-3
(2 1) =>
(2,1) > +1
+1
1
initial setting with wrong answers
both paterns belongd to -1 category
x
1 2 3
9
3.6
(2 1) => +1
(2,1) 1 x0 9
0.4
1
3.6
y0 2
x 1.8
1 2 3
12
Simple example of training one neuron
Applying the second pattern first time
weights: w [0.4
[0 4 1.8
18 - 3.6]
3 6]
pattern 2: x [2 1 1]
n
net = w i xi w xd o
i=1
net 2 0.4 1 1.8 1 3.6 1 1
w 0.3 x 1 1 0.6 x
w [1.2 0.6 0.6]
w [1.6 2.4 - 3.0] 13
(2 1) =>
(2,1) > +1 3
x0 1.87
1 1.6
3
y0 1.25
x 2.4
1 2 3
14
Simple example of training one neuron
Applying the first pattern second time
weights: w [1.6
[1 6 2.4
2 4 - 3]
pattern 1: x [1 2 1]
n
net = w i xi w xd o
i=1
net 1 1.6 2 2.4 1 3 3.4 1
w 0.3 x 1 1 0.6 x
w [-0.6 - 1.2 - 0.6]
w [1 1.2 - 3.6]
15
2 -3.6
+1
3.6
x0 3.6
1 1
3.6
x y0 3
1 2 3 1.2
16
Simple example of training one neuron
Applying the second pattern second time
weights: w [1 1.2
1 2 - 3.6]
3 6]
pattern 2: x [2 1 1]
n
net = w i xi w xd o
i=1
net 2 1 1 1.2 1 3.6 0.4 1
w 0.3 x 1 1 0.6 x
w [1.2 0.6 0.6]
w [2.2 1.8 - 3.0]
17
2 -3
+1
3
x0 1.36
2.2
1
3
y0 1.67
1.8
x
1 2 3
18
Simple example of training one neuron
Applying the first pattern third time
weights: w [2.2
[2 2 1.8
1 8 - 3.0]
3 0]
pattern 1: x [1 2 1]
n
net = w i xi w xd o
i=1
net 1 2.2 2 1.8 1 3 2.8 1
w 0.3 x 1 1 0.6 x
w [-0.6 - 1.2 - 0.6]
w [1.6 0.6 - 3.6]
19
2 -3.6
+1
3.6
x0 2.25
1
1.6
3.6
y0 6
x 0.6
1 2 3
20
Simple example of training one neuron
Applying the second pattern third time
weights: w [1.6
[1 6 0.6
0 6 - 3.6]
3 6]
pattern 2: x [2 1 1]
n
net = w i xi w xd o
i=1
net 2 1.6 1 0.6 1 3.6 0.2 1
w 0.3 x 1 1 0 x 0
w [0 0 0]
w [1.6
[1 6 0.6 0 6 - 3.6]
3 6]
21
2 -3.6
+1
3.6
x0 2.25
1
1.6
3.6
y0 6
x 0.6
1 2 3
22
Simple example of training one neuron
Applying the first pattern 4-th time
weights: w [1.6
[1 6 00.66 - 3.6]
3 6]
pattern 1: x [1 2 1]
n
net = w i xi w xd o
i=1
net 1 1.6 2 0.6 1 3.6 0.8 1
w 0.3 x 1 1 0 x 0
w [0 0 0]
w [1.6
[1 6 0.6 0 6 - 3.6]
3 6]
23
xx x
LMS (Widrow-Hoff) rule: d net
delta rule: d o f '
w x T x x T d
1
pseudoinverse
d i rule
l (the
(th same as LMS):
LMS)
24
Training one neuron using the perceptron rule
Desired output
Pattern 1: 1 2 +1 -1
Pattern 2: 2 1 +1 +1
Initial weights: 1 3 -3
learning constant α 0.3
w i x i d sign ( net )
w i x i 2
25
2 -3.6
+1
3.6
x0 2.25
1
1.6
3.6
y0 6
x 0.6
1 2 3
26
Soft activation functions
1 if net 0 1 if net 0
sign (net ) 1
o f ( net ) 0.5 if net 0 o f ( net ) sgn( net ) 0 if net 0
2 0 if net 0 1 if net 0
1 2
o = f(net) = o = f(net) = tanh 0.5net = -1
1 + exp- net 1 + exp- net
f ' = 1 o o
f ' = 1 o2
27
29
31
plot(ip(1,1),ip(1,2),'ro'); plot(ip(2,1),ip(2,2),'bx');
2.5
[np ni]=size(ip); ip(:,ni+1)=ones(np,1)
[np,ni]=size(ip); ip(: ni+1)=ones(np 1) %agumenting input
a=axis ; a=[0 4 0 4]; axis(a); j=0;
Y input
for ite=1:20,
1.5
for p=1:np,
jj=j+1;
j if jj>1, plot(x,y,'g');
( y g ) end; 1
net(p)=ip(p,:)*ww' ;
0.5
op(p)=tanh(k*0.5*net(p)); %hiperbolic function
er(p)=dp(p)-op(p); ww=ww+c*er(p)*ip(p,:); 0
0 0.5 1 1.5 2 2.5 3 3.5 4
x(2)=4; y(2)=-(ww(1)
y(2)=-(ww(1)*x(2)+ww(3))
x(2)+ww(3))./ww(2);
/ww(2);
plot(x,y,'r');
% pause;
end
ter=sqrt(er*er'), tter(ite)=ter;
0
end;
error
32
0 2 4 6 8 10 12 14 16 18 20
iterations
Program in MATLAB (perceptron -soft)
4
plot(ip(1,1),ip(1,2),'ro'); plot(ip(2,1),ip(2,2),'bx');
nput
[np ni]=size(ip); ip(:,ni+1)=ones(np,1)
[np,ni]=size(ip); ip(: ni+1)=ones(np 1) %agumenting input 2
Y in
a=axis ; a=[0 4 0 4]; axis(a); j=0; 1.5
for ite=1:20,
for p=1:np, 1
jj=j+1;
j if jj>1, plot(x,y,'g');
( y g ) end; 05
0.5
net(p)=ip(p,:)*ww' ;
op(p)=tanh(k*0.5*net(p)); %hiperbolic function 0
0 0.5 1 1.5 2 2.5 3 3.5 4
X input
er(p)=dp(p)-op(p); ww=ww+c*er(p)*ip(p,:);
x(1)=-1; y(1)=-(ww(1)*x(1)+ww(3))./ww(2); 1
10
x(2)=4; y(2)=-(ww(1)
y(2)=-(ww(1)*x(2)+ww(3))
x(2)+ww(3))./ww(2);
/ww(2);
plot(x,y,'r');
% pause;
end
0
ter=sqrt(er*er'), tter(ite)=ter; 10
error
end;
hold off; ite
figure(2); clf; -1
10
semilogy(tter); xlabel(
xlabel('iterations');
iterations ); ylabel(
ylabel('error');
error );
-2
10
33
0 2 4 6 8 10 12 14 16 18 20
iterations
d TE
np
2 d p o p xip
dwi p 1
Therefore:
2
np
TE d p net p
p 1 34
Program in MATLAB (LMS)
4
%single neuron LMS training with soft activation function
f
format t compact; t clear
l all;
ll 3.5
ut
[
[np,ni]=size(ip);
i] i (i ) iip(:,ni+1)=ones(np,1)
( i+1) ( 1) % %augmentingti
Y inpu
2
input 1.5
f p=1:np,
for 1 0.5
error
ter=sqrt(er*er'), tter(ite)=ter;
if ter <0.0001, break; end; 0
10
end;
hold off; ite
figure(2); clf; 35
0 10 20 30 40 50 60 70 80 90 100
semilogy(tter); xlabel('iterations'); ylabel('error'); iterations
Err2 d 2 o2
2
Errnp d np onp
2
np
TE d p o p
p 1
36
DELTA learning rule 1
2
np
TE d p o p
p 1
o p f w1 x1 w2 x2 wni xni
The gradient of TE along wi:
d TE
do p
np
2 d p o p
dwi p 1 dwi
d p
do d p dnet
do d tp
f ' xi
dwi dnet p dwi
37
np
wi 2 d p o p f ' xip
p 1
38
Program in MATLAB (Delta)
4
3.5
nput
plot(ip(1 1) ip(1 2) 'ro');
plot(ip(1,1),ip(1,2), ro ); plot(ip(2,1),ip(2,2),
plot(ip(2 1) ip(2 2) 'bx');
bx ); 2
Y in
[np,ni]=size(ip); ip(:,ni+1)=ones(np,1) %augmenting input
1.5
a=axis ; a=[0 4 0 4]; axis(a);j=0;
for ite=1:250, 1
for p=1:np,
05
0.5
j j 1 if jj>1,
j=j+1; 1 plot(x,y,'g');
l t( ' ') end; d
net(p)=ip(p,:)*ww' ; 0
0 0.5 1 1.5 2 2.5 3 3.5 4
op(p)=tanh(0.5*k*net(p)); %hyperbolic function X input
fp(p)=k*(1-op(p)*op(p));
er(p)=dp(p)-op(p);
(p) p(p) p(p); ww=ww+c*fp(p)*er(p)*ip(p,:);
p(p) (p) p(p, );
1
10
x(1)=-1; y(1)=-(ww(1)*x(1)+ww(3))./ww(2);
x(2)=4; y(2)=-(ww(1)*x(2)+ww(3))./ww(2);
plot(x,y,'r');
% pause; 0
10
end
ter=sqrt(er*er'), tter(ite)=ter;
error
if ter <0.001, break; end;
end; -1
10
% BATCH training 3
fp=k.*(1-op.*op); er=dp-op; 1
10
dw=(c*er.*fp)'*ip; ww=ww+dw;
x(1)=-1; y(1)=-(ww(1)*x(1)+ww(3))./ww(2);
x(2)=4; y(2)=-(ww(1)*x(2)+ww(3))./ww(2); 0
10
plot(x,y,'r');
% pause;
error
-1
10
ter=er'*er, tter(ite)=ter;
if ter <0.001, break; end;
end; -2
10
[
[np,ni]=size(ip);
i] i (i ) ip(:,ni+1)=ones(np,1)
i ( i+1) ( 1) % %augmentingti iinputt
dp=[-1, 1,-1, 1, -1, 1, -1, 1, -1, 1]', ww=[-1 3 -3], c=1.8; k=1;
Y input
1
for ite=1:10000,
if ite>1, plot(x,y,'g'); end; -1
net=ip*ww'; op=tanh(0.5.*k.*net);
fp=k.*(1-op.*op); er=dp-op; -2
-2 -1 0 1 2 3 4
dw=(c*er.*fp)'*ip; ww=ww+dw; 2
X input
10
x(1)= 1; y(1)=-(ww(1)
x(1)=-1; y(1)= (ww(1)*x(1)+ww(3))
x(1)+ww(3))./ww(2);
/ww(2);
x(2)=4; y(2)=-(ww(1)*x(2)+ww(3))./ww(2);
plot(x,y,'r'); 1
10
% pause;
ter=er'*er, tter(ite)=ter;
if ter <0.01, break; end;
error
0
end; 10
figure(2); clf;
semilogy(tter); xlabel('iterations'); ylabel('error');
. 10
-2 41
0 100 200 300 400 500 600
iterations