понедельник, 27 февраля 2017 г.

Simple Narx Example

1.
% Simple First Narx Net Example

load magdata
y = con2seq(y);
u = con2seq(u);

% y = Feedback Signal and Taget signal

sizey = size(y);
sizeu = size(u);

d1 = [1:2];
d2 = [1:2];

narx_net = narxnet(d1,d2,10);

narx_net.divideFcn = '';
narx_net.trainParam.min_grad = 1e-10;

[p,Pi,Ai,t] = preparets(narx_net, u, {}, y);

narx_net.view;

narx_net = train(narx_net,p,t,Pi);

% Simulation
yp = sim(narx_net, p, Pi);
e = cell2mat(yp)-cell2mat(t);
plot(e);

% closed loop

narx_net_closed = closeloop(narx_net);

view(narx_net_closed)

y1 = y(1700:2600);
u1 = u(1700:2600);
[p1,Pi1,Ai1,t1] = preparets(narx_net_closed,u1,{},y1);

yp1 = narx_net_closed(p1,Pi1,Ai1);
TS = size(t1,2);
plot(1:TS,cell2mat(t1),'b',1:TS,cell2mat(yp1),'r')


2. 
% Multiple External Variables in X cell two paramers

[X, T] = ph_dataset;

net = narxnet(10);

[x, xi,ai,t] = preparets(net,X,{},T);

net.view

net = train(net,x,t,xi,ai);

y=net(x,xi,ai);
e = gsubtract(t,y);

sz = size(t);

%plot(cell2mat(e));

plot(1:1991,cell2mat(t),'b',1:1991,cell2mat(y),'r');

Комментариев нет:

Отправить комментарий