Time series in Artificial neural network (ANN) example pollution Mortality
Mostra commenti meno recenti
[X,T] = pollution_dataset
net = timedelaynet(1:2,10);
[Xs,Xi,Ai,Ts] = preparets(net,X,T);
net = train(net,Xs,Ts,Xi,Ai);
I used this very simple example code to get a feel; how a time series network predict a future value. So, what I did instead of using 508 dataset for inputs and outputs. I reduced it to 502 dataset and then tried to get 503rd target by using 503rd input vector.
My simple code was
>> d={[80.3800000000000;57.3100000000000;4.34000000000000;1.57000000000000;9.73000000000000;40.0100000000000;6.99000000000000;47.2200000000000]};
>> a=net(d);
This gave me the following results
281.7230
29.0219
157.1554
While actual output should be
149.220000000000
7.88000000000000
73.4600000000000
Why this is giving so deviated values?....Any Explanation Please!
Risposta accettata
Più risposte (2)
Greg Heath
il 28 Lug 2013
Modificato: Greg Heath
il 29 Lug 2013
0 voti
1. You should not use the default divide function DIVIDERAND in a timeseries. Although I recommend DIVIDEBLOCK, DIVIDEIND or DIVIDEINT could also be used.
2. Normalize the target series to have zero mean and unit variance (help zscore)
3. Initialize the RNG before creating the net
4. [ net tr Y Xf Af ] = train(net,Xs,Ts,Xi,Ai);
5. Make sure the design is good
tr = tr
6. If not make multiple designs until you find a good one
7. Make sure the delay buffer is loaded when you run the new data.
Hope this helps.
Thank you for formally accepting my answer
Greg
P.S. Search timedelaynet greg
4 Commenti
sandeep
il 29 Lug 2013
Greg Heath
il 29 Lug 2013
If you use the command line approach, use that command after the train command which determines tr.
sandeep
il 31 Lug 2013
sandeep
il 31 Lug 2013
Greg Heath
il 31 Lug 2013
rng(0)
[net,tr] = train(net,inputs,targets,inputStates,layerStates);
tr = tr % No semicolon
12 Commenti
sandeep
il 1 Ago 2013
Greg Heath
il 12 Ago 2013
1. net = net will show you all of the net properties
2. tr = tr will show you the training record
3. tr.divideint, tr.trainInd ,etc indicate that you do not have uniform spacing between your points. Why didn't you follow my recommendation?
4. Why don't you use dividetrain first and concentrate on minimizing the number of hidden neurons you need to get a good design.
5. goal = 1e-20 is unreasonable. Try 0.01*mean(var(target',1)) to get a normalized MSE of 0.01
6. Try 10 different random weight initializations for each value of hidden nodes that you try.
7. If you search on rng(0) timedelaynet you will probably find some helpful code
8. Also search on h = Hmin
HTH
Greg
sandeep
il 14 Ago 2013
Greg Heath
il 16 Ago 2013
Time series in Artificial neural network (ANN) example pollution Mortality Asked by sandeep on 27 Jul 2013 at 6:33 Comment by Greg Heath on 12 Aug 2013 at 15:00 % 1. net = net will show you all of the net properties % 2. tr = tr will show you the training record % 3. tr.divideint, tr.trainInd ,etc indicate that you do not have % uniform spacing between your points. Why didn't you follow my % recommendation? % 4. Why don't you use dividetrain first and concentrate on mini- % mizing the No. of hidden neurons you need to get a good design. % 5. goal = 1e-20 is unreasonable. Try 0.01*mean(var(target',1)) to % get a normalized MSE of 0.01 % 6. Try 10 different random weight initializations for each value of % hidden nodes that you try. % 7. If you search on rng(0) timedelaynet you will probably find some % helpful code % 8. Also search on h = Hmin
Response by sandeep on 14 Jul 2013 ~9:30 % Which recommendation I did not follows? for divideblock? I used % that one but it did not give good results.
Divideblock is not the reason for the failure. However, If you try
another option, you MUST maintain the same uniform time spacing
for trn/val and tst.
% Please explain your point no. 6. " Try 10 different random weight % initializations for each value of hidden nodes that you try."
Assumes prob(successful random weight initialization) >= 10%
I have many posts as examples. Search on i = 1:Ntrials
% Suppose I get good results after 8 time training. But again when % I want to reproduce the results I could not get the same results. % If I use rng(0) then I get constant results after second training. % How could I reproduce my results which is best? rng(0) % reproduce the results but it is worse than other results.
1. You can record the initial state of the RNG before each
weight initialization,
help rng
rng(1492)
Ntrials= 5
for i = 1:Ntrials
state(i) = rng
output(i) = rand
end
% To recalculate output(3)
rng( state(3))
y = rand
error = output(3)-y %0
2. Or, within a loop, store the net that has the current best
performance on the validation data.
% Here is my code % %A 4 dimensional input, having data of 351 days % filename = 'Inputs_2013_new.xlsx'; % u= xlsread(filename); % % A 1 dimensional output, having datas of 351 days. % filename = 'Outputs_2013_new.xlsx';
I'm confused: For pollution_dataset
size(input) = [8 508]
size(output) = [ 3 508]
Which ones are you using?
% y= xlsread(filename); % x = tonndata(u,true,false); % t = tonndata(y,true,false); % inputSeries = x(1:320); %320 days for training % xnh=x(321:end); %31 days for prediction of outputs % targetSeries = t(1:320); % toPredict = t(321 : end);
BASIC ERROR: Input is 4-D but you are using a 1-D notation!
% inputDelays = 1:21; % feedbackDelays = 1:21;
Why??
% hiddenLayerSize = [25 15];
Why TWO hidden??? Why these values?
% net = narxnet(inputDelays,feedbackDelays,hiddenLayerSize); % net.layers{1}.transferFcn='logsig'; % net.layers{2}.transferFcn='logsig';
Innappropriate for mapminmax
% net.layers{1}.initFcn='initnw'; % net.layers{2}.initFcn='initnw'; % net.inputs{1}.processFcns = {'removeconstantrows','mapminmax'}; % net.inputs{2}.processFcns = {'removeconstantrows','mapminmax'};
DELETE previous 4. They are defaults
% [inputs,inputStates,layerStates,targets] = preparets(net,inputSeries,{},targetSeries); % net.divideFcn = 'dividetrain'; %I tried with dividerand, divideblock, divideint, % no one is giving correct results
Dividetrain useful for determining delays and hidden nodes. Then
retrain with divideblock to get unbiased performance estimates from
nontraining test set
%net.divideParam.trainRatio = 70/100; %net.divideParam.valRatio = 15/100; %net.divideParam.testRatio = 15/100;
DELETE. Incompatible with dividetrain
% net.trainFcn = 'trainlm'; %I tried diffrent training algorithm, But could % not get better predition. % net.performFcn = 'mse'; % net.trainParam.epochs=1000; % net=init(net);
DELETE. They are defaults.
% Train the Network % rng(0) % [net,tr] = train(net,inputs,targets,inputStates,layerStates); % tr=tr;
Remove semicolon to see the detailed training record
% Test the Network % outputs = net(inputs,inputStates,layerStates); % errors = gsubtract(outputs, targets); % errors2=cell2mat(errors); % errors3=(abs(errors2)./y(1:2,22:320))*100; %Change here when you change Time Delay % performance = perform(net,targets,outputs)
DELETE. Obtain performance from tr.
%Now close the loop
Worry about that later.
Hope this helps.
Greg
sandeep
il 27 Ago 2013
sandeep
il 30 Ago 2013
Greg Heath
il 31 Ago 2013
sandeep on 27 Aug 2013 at 5:37 Thank you sir for giving your valuable time.
1."BASIC ERROR: Input is 4-D but you are using a 1-D notation!"
what will be the notation of 4-D
% Instead of x(a:b) valid for 1-D, For 4-D all of the following have different meanings.
x(i,a:b), i=1,2,3 or 4
x([1,3], a:b)
x(:,a:b)
Try them out.
3. "Innappropriate for mapminmax"
What should I use?
mapminmax yields inputs and targets over [-1,1]. logsig has a range of (0,1) and therefore, is not appropriate.
What activation function has a range of (-1,1)?
sandeep
il 31 Ago 2013
Greg Heath
il 1 Set 2013
Sir,
1.Suppose I wrote my 4-D inputs as the following cell array
g={[1;2;3;4] [4;5;6;7] [8;9;3;4] [1;3;5;8] [2;4;5;6] [4;6;7;9] [1;3;5;6]}
in that case g(2,1:3) or g([1,3],1:3) gives 'Index exceeds matrix dimensions.'
my earlier code is working without any difficulty. Are you still suggests there is a problem?
% Sorry, my comments were for matrices, not cells.
3. What would be if I manually normalized all of my data by their corresponding maximums. so that my inputs and outputs excel files contain data of range [0,1]? Is it OK?
% Only consider MAPMIMAX or MAPSTD for inputs and use TANSIG in all hidden
layers
% Also, only consider MAPMIMAX or MAPSTD for real-valued regression and
curve-fitting outputs (, e.g., FITNET) and use PURELIN or TANSIG in the
output layer
% However, for c-class/category classification and pattern recognition outputs
( e.g., PATTERNNET), consider binary unit column vectors from eye(c). Since
the outputs sum to unity, it is only necessary to use c-1 of the outputs.
Typically, however, this only done for c==2.
4. Sir, What should be the criterion of deciding which network is good for me. whether it should be Validation performance or test performance of training performance of overall performance or training R, test R, Validation R or overall R? What should be my criterion?......It seems that there are so many variable based on that we can decide.
% For huge data sets where the number of training equations is much larger
than the number of unknown weights (Ntrneq >> Nw), I tend to use
'dividetrain' and the degree-of-freedom adjusted MSE, NMSE or R2 (R^2 )
which I denote by MSEa, NMSEa and R2a.
% For smaller data sets I rely more on validation set performance using
'dividerand' for static nets and 'divideblock' for dynamic nets.
% To mitigate unfortunate designations of random initial weights, I tend to
always generate 10 designs for each set of input parameters.
% Test sets are only to be used for the estimation of nondesign set (AKA
generalization ) performance.
% You can search my NEWSGROUP and ANSWERS posts using the above notation. (e.g., greg MSEa or greg R2a)
5. You can record the initial state of the RNG before each weight
initialization,
help rng
rng(1492)
Ntrials= 5
for i = 1:Ntrials
state(i) = rng
output(i) = rand
end
% To recalculate output(3)
rng( state(3))
y = rand
error = output(3)-y %0
This code is working very well, But when I restart the computer I am not able to reproduce the results anymore. It reproduce the results till that I am on my workspace.Thanks again for your suggestion and giving time.
% Strange ... I have never encountered that.
sandeep
il 2 Set 2013
Greg Heath
il 3 Set 2013
You are giving your interpretation of what you did and comparisons. It is too confusing without seeing your code. Please stay with the MATLAB dataset.
Shashank Prasanna
il 3 Set 2013
sandeep, if you have a new or related question please create/ask a new question. This will (1) give your question more visibility and (2) allow you to give credit to who ever answers your question.
Categorie
Scopri di più su Deep Learning Toolbox in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!