How to calculate correctly Ntrneq, Nw, Hub, Hmax, MSEgoal for MULTIPLE SEQUENCES in neural networks?
4 views (last 30 days)
Show older comments
I am trying to find the minimum number of nodes in hidden layer that satisfies my MSEgoal.
I have my input and output cell arrays of {1x491} with [2x33] values. Technically, I have 33 time series of length 491 with padded NaNs with 2-inputs and 2-outputs.
If I do:
x = cell2mat(X);
t = cell2mat(T);
[ I N ] = size(x); % [ 2 16203] % Including the NaN values
[ O N ] = size(t);
N = the total number of point that will be use for training, including the NaNs.
However, I assume the I do not want to count the NaNs to calculate Ntrneq so I removed them:
[ I N ] = size(x(:,any(~isnan(x)))); % [ 2 12116] % Removed NaN values from the count
[ O N ] = size(t(:,any(~isnan(t))));
However, Ntreq is huge = 24202, with a HUB of 967 and Hmax of 96. Which is also huge compared to h=10 that have been using in a pilot test where error are in the order of 1/10000.
But if I do:
[ I N ] = size(X); % [ 1 491]
[ O N ] = size(T);
Am I only calculating Ntrneq, Nw, Hub, Hmax as if I only had 1 time series but still I&O =2?
This is my complete code:
x = cell2mat(X);
t = cell2mat(T);
%[ I N ] = size(x); % [ 2 16203] % Including the NaN values
% [ O N ] = size(t);
[ I N ] = size(x(:,any(~isnan(x)))); % [ 2 12116] % Removed NaN values from the count
[ O N ] = size(t(:,any(~isnan(t))));
% [ I N ] = size(X); % [ 1 491] % Removed NaN values from the count
% [ O N ] = size(T);
Ntrn = N % 12116 use all data set only for finding h
rng('default')
FD = 10:15; % Determine with pilot chracterization. It will be updated with auto-correlation of targets
ID = 10:15; % Determine with pilot chracterization. It will be updated with cross-correlation of targets and inputs
steps=15; % Lag same es MXFD or MXID = max(FD) or max(ID)
NFD = length(FD); NID = length(ID);
Ntrneq = (Ntrn-steps)*O %24202, I deleted the lags
Hub = -1+ceil( (Ntrneq-O) / ((NID*I)+(NFD*O)+1)) % 967
Hmax = floor(Hub/10) % 96
Hmin = 0; dH = 1; Ntrials = 10; j=0;
rng(0)
for h = Hmin:dH:Hmax
j = j+1;
if h == 0
net = narxnet( ID, FD, [] );
Nw = ( NID*I + NFD*O + 1)*O;
else
net = narxnet( ID, FD, h );
Nw = ( NID*I + NFD*O + 1)*h + ( h + 1)*O;
end
Ndof = Ntrn-Nw;
[ Xs Xi Ai Ts ] = preparets(net,X,{},T);
ts = cell2mat(Ts);
xs = cell2mat(Xs);
MSE00s = mean(nanvar(ts',1)); %I omitted the NaNs
MSE00as = mean(nanvar(ts',0));
MSEgoal = 0.01*Ndof*MSE00as/Ntrneq;
MinGrad = MSEgoal/10; % or MSEgoal/100;
net.trainParam.goal = MSEgoal;
net.trainParam.min_grad = MinGrad;
net.divideFcn = 'dividetrain';
net.performParam.normalization = 'standard'; % Does this affect the performance because my MSEgoal is in the normal range.
for i = 1:Ntrials
net = configure(net,Xs,Ts);
[ net tr Ys ] = train(net,Xs,Ts,Xi,Ai);
ys = cell2mat(Ys);
stopcrit{i,j} = tr.stop;
bestepoch(i,j) = tr.best_epoch;
MSE = mse(ts-ys);
MSEa = Ntrneq*MSE/Ndof;
R2(i,j) = 1-MSE/MSE00s; %? different ranges?
R2a(i,j) = 1-MSEa/MSE00as; %? different ranges?
end
stopcrit = stopcrit
bestepoch = bestepoch
R2 = R2
R2a = R2a
%Totaltime = toc
Lastly, in my code I am not normalizing my inputs and outputs but I used:
net.performParam.normalization = 'standard';
becasue my outputs have different ranges. Does that mean that my
net.trainParam.goal = MSEgoal;
net.trainParam.min_grad = MinGrad;
are on different ranges (data vs training). so my R2, too?
I have posted this question about using zscore on my data set:
because I couldn't make it work.
I have attached my X and T.
Thank you,
0 Comments
Answers (0)
See Also
Categories
Find more on Function Approximation and Nonlinear Regression in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!