ADALINE time series prediction
[p1,p2] = meshgrid(-10:.25:10);
z = feval(func, [p1(:) p2(:)]*w'+b );
z = reshape(z,length(p1),length(p2));
plot3(p1,p2,z)
grid on
xlabel('Input 1')
ylabel('Input 2')
zlabel('Neuron output')
Warning: MATLAB has disabled some advanced graphics rendering features by switching to
software OpenGL. For more information, click here.
>> K = 30;
% define classes
q = .6; % offset of classes
>> A = [rand(1,K)-q; rand(1,K)+q];
B = [rand(1,K)+q; rand(1,K)+q];
C = [rand(1,K)+q; rand(1,K)-q];
D = [rand(1,K)-q; rand(1,K)-q];
>> plot(A(1,:),A(2,:),'bs')
>> hold on
grid on
plot(B(1,:),B(2,:),'r+')
plot(C(1,:),C(2,:),'go')
plot(D(1,:),D(2,:),'m*')
>> text(.5-q,.5+2*q,'Class A')
text(.5+q,.5+2*q,'Class B')
text(.5+q,.5-2*q,'Class C')
text(.5-q,.5-2*q,'Class D')
>> a = [0 1]';
b = [1 1]';
c = [1 0]';
d = [0 0]';
>> % a = [0 1]';
% b = [1 1]';
% d = [1 0]';
% c = [0 1]';
>> P = [A B C D];
>> T = [repmat(a,1,length(A)) repmat(b,1,length(B)) ...
repmat(c,1,length(C)) repmat(d,1,length(D)) ];
%plotpv(P,T);
>> net = perceptron;
>> E = 1;
net.adaptParam.passes = 1;
linehandle = plotpc(net.IW{1},net.b{1});
n = 0;
>> while (sse(E) & n<1000)
n = n+1;
[net,Y,E] = adapt(net,P,T);
linehandle = plotpc(net.IW{1},net.b{1},linehandle);
drawnow;
end
>> view(net);
>> p = [0.7; 1.2]
y = net(p)
p =
0.7000
1.2000
y =
1
1
>> dt = 0.01; % time step [seconds]
t1 = 0 : dt : 3; % first time vector [seconds]
t2 = 3+dt : dt : 6; % second time vector [seconds]
t = [t1 t2];
>> y = [sin(4.1*pi*t1) .8*sin(8.3*pi*t2)];
>> plot(t,y,'.-')
>> xlabel('Time [sec]');
>> ylabel('Target Signal');
>> grid on
ylim([-1.2 1.2])
>> p = con2seq(y);
>> inputDelays = 1:5; % delayed inputs to be used
learning_rate = 0.2;
>> net = linearlayer(inputDelays,learning_rate);
>> [net,Y,E] = adapt(net,p,p);
>> view(net)
>> disp('Weights and bias of the ADALINE after adaptation')
net.IW{1}
net.b{1}
Weights and bias of the ADALINE after adaptation
ans =
0.7179 0.4229 0.1552 -0.1203 -0.4
>> Y = seq2con(Y); Y = Y{1};
E = seq2con(E); E = E{1};
>> subplot(211)
plot(t,y,'b', t,Y,'r--');
legend('Original','Prediction')
grid on
>> xlabel('Time [sec]');
ylabel('Target Signal');
ylim([-1.2 1.2])
>> subplot(212)
plot(t,E,'g');
grid on
>> legend('Prediction error')
xlabel('Time [sec]');
ylabel('Error');
ylim([-1.2 1.2])
[p1,p2] = meshgrid(-10:.25:10);
z = feval(func, [p1(:) p2(:)]*w'+b );
z = reshape(z,length(p1),length(p2));
plot3(p1,p2,z)
grid on
xlabel('Input 1')
ylabel('Input 2')
zlabel('Neuron output')
Warning: MATLAB has disabled some advanced graphics rendering features by switching to
software OpenGL. For more information, click here.
>> K = 30;
% define classes
q = .6; % offset of classes
>> A = [rand(1,K)-q; rand(1,K)+q];
B = [rand(1,K)+q; rand(1,K)+q];
C = [rand(1,K)+q; rand(1,K)-q];
D = [rand(1,K)-q; rand(1,K)-q];
>> plot(A(1,:),A(2,:),'bs')
>> hold on
grid on
plot(B(1,:),B(2,:),'r+')
plot(C(1,:),C(2,:),'go')
plot(D(1,:),D(2,:),'m*')
>> text(.5-q,.5+2*q,'Class A')
text(.5+q,.5+2*q,'Class B')
text(.5+q,.5-2*q,'Class C')
text(.5-q,.5-2*q,'Class D')
>> a = [0 1]';
b = [1 1]';
c = [1 0]';
d = [0 0]';
>> % a = [0 1]';
% b = [1 1]';
% d = [1 0]';
% c = [0 1]';
>> P = [A B C D];
>> T = [repmat(a,1,length(A)) repmat(b,1,length(B)) ...
repmat(c,1,length(C)) repmat(d,1,length(D)) ];
%plotpv(P,T);
>> net = perceptron;
>> E = 1;
net.adaptParam.passes = 1;
linehandle = plotpc(net.IW{1},net.b{1});
n = 0;
>> while (sse(E) & n<1000)
n = n+1;
[net,Y,E] = adapt(net,P,T);
linehandle = plotpc(net.IW{1},net.b{1},linehandle);
drawnow;
end
>> view(net);
>> p = [0.7; 1.2]
y = net(p)
p =
0.7000
1.2000
y =
1
1
>> dt = 0.01; % time step [seconds]
t1 = 0 : dt : 3; % first time vector [seconds]
t2 = 3+dt : dt : 6; % second time vector [seconds]
t = [t1 t2];
>> y = [sin(4.1*pi*t1) .8*sin(8.3*pi*t2)];
>> plot(t,y,'.-')
>> xlabel('Time [sec]');
>> ylabel('Target Signal');
>> grid on
ylim([-1.2 1.2])
>> p = con2seq(y);
>> inputDelays = 1:5; % delayed inputs to be used
learning_rate = 0.2;
>> net = linearlayer(inputDelays,learning_rate);
>> [net,Y,E] = adapt(net,p,p);
>> view(net)
>> disp('Weights and bias of the ADALINE after adaptation')
net.IW{1}
net.b{1}
Weights and bias of the ADALINE after adaptation
ans =
0.7179 0.4229 0.1552 -0.1203 -0.4
>> Y = seq2con(Y); Y = Y{1};
E = seq2con(E); E = E{1};
>> subplot(211)
plot(t,y,'b', t,Y,'r--');
legend('Original','Prediction')
grid on
>> xlabel('Time [sec]');
ylabel('Target Signal');
ylim([-1.2 1.2])
>> subplot(212)
plot(t,E,'g');
grid on
>> legend('Prediction error')
xlabel('Time [sec]');
ylabel('Error');
ylim([-1.2 1.2])
0 Comments