Can somebody explain me how to use "divideind"??
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Mehrukh Kamal
il 10 Nov 2013
Risposto: Greg Heath
il 28 Gen 2014
I am using Neural Network tool box for pattern recognition. The tool box uses random values of the input matrix for training test validation of defined percentage which results in different performance graph every time i train it.
I read that if i generate the advanced script and use divideind i can fix the matrix of validation,testing and training. But i'm not sure how to use it and what amendments should be made in the advance script. Kindly Help.
P.S dont tell me to read help and doc its use less (atleast for me)
0 Commenti
Risposta accettata
Greg Heath
il 17 Nov 2013
Modificato: Greg Heath
il 17 Nov 2013
The first time use as many defaults as possible. Defaults and basic code examples are listed in
help patternnet and
doc patternnet
Also, if you remove the semicolon, all the defaults will be revealed via
net = patternnet(hiddenLayerSize)
Once you are error free, start to make changes.
Even the correct code may not work because of an unfortunate set of initial weights. Therefore, with the correct number of hidden nodes I usually design 10 nets in a loop. The best is chosen by the lowest validation set error. The prediction of performance on unseen data (generalization) is obtained from the corresponding test set error.
Often the default number of hidden nodes(10) is nonoptimal. My solution is a double loop design with the outer loop over ~ 10 candidate values.
Details are in my posts obtained from searching
greg patternnet Ntrials
Hope this helps.
Thank you for formally accepting my answer
Greg
P.S. More later.
0 Commenti
Più risposte (5)
Greg Heath
il 17 Nov 2013
[ inputs, targets ] = simpleclass_dataset;
[ I N ] = size(inputs) % [ 2 1000 ]
[ O N ] = size(targets) % [ 4 1000 ]
hiddenLayerSize = 10;
net = patternnet(hiddenLayerSize);
view(net)
net.divideFcn = 'divideind';
net.divideParam.trainInd = 151:850;
net.divideParam.valInd = 1:150;
net.divideParam.testInd = 851:1000;
[net,tr] = train(net,inputs,targets);
view(net)
outputs = net(inputs);
errors = gsubtract(targets,outputs);
performance = perform(net,targets,outputs)
trainTargets = targets .* tr.trainMask{1};
valTargets = targets .* tr.valMask{1};
testTargets = targets .* tr.testMask{1};
trainPerformance = perform(net,trainTargets,outputs)
valPerformance = perform(net,valTargets,outputs)
testPerformance = perform(net,testTargets,outputs)
3 Commenti
Greg Heath
il 21 Nov 2013
1. It depends upon the application. For classification or pattern-recognition, VEC2IND is the most common.
2. NaNs are ignored.
Greg Heath
il 28 Gen 2014
I forgot to apply the mask to the outputs when calculating trn/val/tst performance!
Greg Heath
il 28 Gen 2014
Your original problem of nonrepeatibility is easily solved by initializing the RNG before it is used to divide data or initialize weights. If you search using
greg Ntrials
you will see the command
rng(0)
However, you can use any positive integer, e.g., rng(4151941). This tends to be preferable because random division eliminates any bias in the way the data was collected.
However, I will find one of my examples that uses divideind and post the URL.
Greg
0 Commenti
Greg Heath
il 28 Gen 2014
{close all, clear all, clc
[ x, t ] = simpleclass_dataset;
[ I N ] = size(x) % [ 2 1000]
[ O N ] = size(t) % [ 4 1000]
trueclassind = vec2ind(t);
ind1 = find(trueclassind == 1);
ind2 = find(trueclassind == 2);
ind3 = find(trueclassind == 3);
ind4 = find(trueclassind == 4);
N1 = length(ind1) % 243
N2 = length(ind2) % 247
N3 = length(ind3) %233
N4 = length(ind4) %277
minmax1 = minmax(ind1) % [ 5 993 ]
minmax2 = minmax(ind2) % [ 1 1000 ]
minmax3 = minmax(ind3) % [ 4 996 ]
minmax4 = minmax(ind4) % [ 6 985 ]
mean(diff(trueclassind)) % 0 Classes completely mixed up
trnind = 1:700;
valind = 701:850;
tstind = 851:1000;
Ntrn = 700
Nval = 150
Ntst = 150
Ntrneq = Ntrn*O
MSEtrn00 = mean(var(t(trnind)',1)) % 0.1875
MSEtrn00a = mean(var(t(trnind)',0)) % 0.1878
MSEval00 = mean(var(t(valind)',1)) % 0.1892
MSEtst00 = mean(var(t(tstind)',1)) % 0.1858
% Create a Pattern Recognition Network
H = 10;
net = patternnet(H);
Nw = (I+1)*H+(H+1)*O % 74
Ndof = Ntrneq-Nw % 2726
net.divideFcn = 'divideind';
net.divideParam.trainInd = trnind;
net.divideParam.valInd = valind;
net.divideParam.testInd = tstind;
[net tr y e ] = train(net,x,t); % e = t-y
% Test the Network
MSEtrn = mse(e(trnind)) % 1.5629e-7
MSEtrna = Ntrneq*MSEtrn/Ndof % 1.6053e-7
R2trn = 1-MSEtrn/MSEtrn00 % 1}
R2trna = 1-MSEtrna/MSEtrn00a % 1
R2val = 1-mse(e(valind))/MSEval00 % 1
R2tst = 1-mse(e(tstind))/MSEtst00 % 1}
0 Commenti
Mehrukh Kamal
il 17 Nov 2013
4 Commenti
Greg Heath
il 28 Gen 2014
1. Please remove all statements that are covered by defaults
2. Test on one of MATLAB's example data sets for classification/pattern-recognition
help nndatasets
doc nndatasets
Their example for patternnet is the iris_dataset. However, that is a multidimensional input set. Try one of the single dimensional sets.
Greg Heath
il 28 Gen 2014
Sorry there are no single dimensional input examples. Just use
simpleclass_dataset
Vedere anche
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!