Prediction using narx Network

Technical Source
2 min readJun 17, 2021

%Neural network to create a Fibinocci series

u=[1 2 3 4 5 6 7 8 9 10]; %Input Series

y=[1 2 3 5 8 13 21 34 55 89]; % Target series

[u,us] = mapminmax(u);

[y,ys] = mapminmax(y);

y = con2seq(y);

u = con2seq(u); d1 = [1:2];

d2 = [1:2];

narx_net = narxnet(d1,d2,10);

narx_net.divideFcn = ‘’;

narx_net.trainParam.epochs = 1000;

narx_net.trainParam.min_grad = 1e-10;

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

% Train the Network-Open Loop

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

% Simulate the Network-Open Loop

yp = sim(narx_net,p,Pi);

y_again=mapminmax(‘reverse’,yp,ys)

%view(narx_net); %error_OL = cell2mat(yp)-cell2mat(y(3:end));

%Close narx net for future prediction

narx_net_closed = closeloop(narx_net);

[p1,Pi1,Ai1,t1] = preparets(narx_net_closed,u,{},y);

% Train the Network-Closed Loop

% narx_net_closed = train(narx_net_closed,p1,t1,Pi1);

% Simulate the Network-Closed Loop

yp1 = narx_net_closed(p1,Pi1,Ai1);

yp1_again=mapminmax(‘reverse’,yp1,ys)

Please answer the following questions:

1. How can I make one step prediction without closing loop?

2. How can I get the next 5 numbers in the series? please provide the code if possible. I went through all your posts but could not solve it.

3. When I close the narx net, I get the same results as of open loop without training.

4. If I train the close loop, the outputs deviate from the target. How can I reduce this error?

ANSWER

Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.

The Fibonacci series does not result from an input/output relationship. It is autoregressive

Either y(1:2) = [ 0 1 ] or y(1:2) = [ 1 1 ] and then

y(n+1) = y(n) + y(n-1)

Obviously this can be implemented with a NARNET WITH NO HIDDEN NODES.

--

--

Technical Source

Simple! That is me, a simple person. I am passionate about knowledge and reading. That’s why I have decided to write and share a bit of my life and thoughts to.