Future Prediction using NARNET ntstool
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi all,
I am attempting to using the NARNET function to create a net that analyzes my inputs and then predicts a number of new values. I am using time-series stock data as my input, and the non-linear autoagressive method in ntstool. I am using 3 hidden neurons, 10 delays, and the LM training method. When I plot the response, I receive the following;

This correctly models the inputs I have fed into the net. However, I would now like the net to predict the next 10 or so points (i.e. I have data for x number of days and would like to know the 10 following days). I then click "code-generation" and the following code is placed in my scripts. How can I go about predicting the next 10 data points (I am familiar with coding/matlab on an intermediate level so dumbed down responses would be appreciated haha).
function [y1,xf1] = myNeuralNetworkFunction(x1,xi1)
%MYNEURALNETWORKFUNCTION neural network simulation function.
if true
% code
end
% [y1,xf1] = myNeuralNetworkFunction(x1,xi1) takes these arguments:
% x1 = 1xTS matrix, input #1
% xi1 = 1x10 matrix, initial 10 delay states for input #1.
% and returns:
% y1 = 1xTS matrix, output #1
% xf1 = 1x10 matrix, final 10 delay states for input #1.
% where TS is the number of timesteps.
% ===== NEURAL NETWORK CONSTANTS =====
% Input 1
x1_step1_xoffset = 19.280001;
x1_step1_gain = 0.0504159314343332;
x1_step1_ymin = -1;
% Layer 1
b1 = [1.9782172138961608976;-0.25095202107890846044;1.6269071248628457216];
IW1_1 = [-0.1900195394857509823 -0.32574920145646352188 -0.28162662484854183997 0.53209956709792194385 0.71708074435955770909 0.49528714462702727594 0.0082645500608133706799 -0.015589115420090327718 0.010326746159929170096 -0.9377170752087964356;0.59690882897694941267 0.015900138812292664847 -0.035920420125361667008 0.014361212783342496707 -0.03824228939616346884 0.0021501348364735784965 -0.00098403189602899862262 0.003752900476250610115 -0.0098996264715030622 0.032779441538841075365;0.86683938892310274937 -0.29939312366363907136 0.77577942573184877073 0.18339827852509529849 0.43212792809259392701 0.36033363671446927423 -0.73143991150168119475 -0.26527945315928219694 0.39836854251047409958 0.31891757682577714927];
% Layer 2
b2 = -0.34595983079818815042;
LW2_1 = [0.61803591474585495291 1.7087207002573796544 0.18709077654147429626];
% Output 1
y1_step1_ymin = -1;
y1_step1_gain = 0.0504159314343332;
y1_step1_xoffset = 19.280001;
% ===== SIMULATION ========
% Dimensions
TS = size(x1,2); % timesteps
% Input 1 Delay States
xd1 = mapminmax_apply(xi1,x1_step1_gain,x1_step1_xoffset,x1_step1_ymin);
xd1 = [xd1 zeros(1,1)];
% Allocate Outputs
y1 = zeros(1,TS);
% Time loop
for ts=1:TS
% Rotating delay state position
xdts = mod(ts+9,11)+1;
% Input 1
xd1(:,xdts) = mapminmax_apply(x1(:,ts),x1_step1_gain,x1_step1_xoffset,x1_step1_ymin);
% Layer 1
tapdelay1 = reshape(xd1(:,mod(xdts-[1 2 3 4 5 6 7 8 9 10]-1,11)+1),10,1);
a1 = tansig_apply(b1 + IW1_1*tapdelay1);
% Layer 2
a2 = b2 + LW2_1*a1;
% Output 1
y1(:,ts) = mapminmax_reverse(a2,y1_step1_gain,y1_step1_xoffset,y1_step1_ymin);
end
% Final delay states
finalxts = TS+(1: 10);
xits = finalxts(finalxts<=10);
xts = finalxts(finalxts>10)-10;
xf1 = [xi1(:,xits) x1(:,xts)];
end
% ===== MODULE FUNCTIONS ========
% Map Minimum and Maximum Input Processing Function
function y = mapminmax_apply(x,settings_gain,settings_xoffset,settings_ymin)
y = bsxfun(@minus,x,settings_xoffset);
y = bsxfun(@times,y,settings_gain);
y = bsxfun(@plus,y,settings_ymin);
end
% Sigmoid Symmetric Transfer Function
function a = tansig_apply(n)
a = 2 ./ (1 + exp(-2*n)) - 1;
end
% Map Minimum and Maximum Output Reverse-Processing Function
function x = mapminmax_reverse(y,settings_gain,settings_xoffset,settings_ymin)
x = bsxfun(@minus,y,settings_ymin);
x = bsxfun(@rdivide,x,settings_gain);
x = bsxfun(@plus,x,settings_xoffset);
end
Thank you!
0 Commenti
Risposte (0)
Vedere anche
Categorie
Scopri di più su Deep Learning Toolbox in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!