Effacer les filtres
Effacer les filtres

How can i stop the neural network after just one iteration ?

7 vues (au cours des 30 derniers jours)
Mariem Harmassi
Mariem Harmassi le 30 Août 2012
Hi i am a master student and i am developping a matlab code for evolutionary neural network so the training algorithm is done with a genetic algoritm and i dont need to train my neural network with any training function available ,that's why i set the epochs to 1 . This is the code
net=NEWFF(minmax(trainInput'),[hn,1],{'tansig','purelin'},'traingd');
net.trainParam.show = NaN;
net.trainParam.lr = 0.05;
net.trainParam.mc = 0.1;
net.trainParam.epochs = 1;
net.trainParam.goal = 1e-2;
[net,tr]=train(net,trainInput',trainOutput');
I need a function which can stop the neural network after just one iteration that s mean i don t want the neural network to calculate a new weights and ierates .Dis This partial code realize this ?
closeloop is it useful ?
  1 commentaire
Joakim Lindblad
Joakim Lindblad le 9 Mar 2018
Guess I'm not the only one ending up on this ancient question...
To stop after one iteration, use an output function which returns true:
'OutputFcn',@(varargin) true
This can be useful to do, e.g., after resuming from a checkpoint.
If you know how to stop after zero iterations, plz post.

Connectez-vous pour commenter.

Réponse acceptée

Greg Heath
Greg Heath le 1 Sep 2012
Modifié(e) : Greg Heath le 1 Sep 2012
To design an I-H-O feedforward multilayer perceptron (with H hidden nodes) using Ntrn input/target training pairs with dimensions I and O, respectively,
1. Create the input and target matrices Xtrn and Ttrn with dimensions
[ I Ntrn ] = size(Xtrn)
[ O Ntrn [ = size(Ttrn)
2. Standardize ( help mapstd, help zscore) the columns to have zero mean and unit variance. The resulting matrices are xtrn and ttrn.
3. This data will generate
Neq = Ntrn*O
training equations which will be used to obtain
Nw = (I+1)*H+(H+1)*O
unknown weights (including H+O bias weights).
4. Although
H <= Hub = (Neq-O)/(I+O+1)
insures that
Neq >= Nw,
the stronger condition
H << Hub
is preferred in order to mitigate noise, measurement error and insufficient sampling variety.
5. The weights and biases are typically stored in matrices IW, b1, LW and b2 with sizes
[ H I ] = size(IW)
[ H 1 ] = size(b1)
[ O H ] = size(LW)
[ O 1 ] = size(b2).
6. For an arbitrary input x, the hidden node and output signals are given by
h = tanh( IW * x + b1 );
y = LW * h + b2;
7. When the input xtrn yields the output ytrn, the corresponding error is
etrn = ttrn-ytrn;
8. The corresponding degree-of-freedom adjusted mean-square error is
MSEtrna = sum( etrn(:).^2 ) / (Neq-Nw)
9. A reasonable design objective is to choose (H,IW,b1,LW,b2) to minimize MSEtrna.
10. I would use the genetic algorithm to find the weights given an integer value for H that satisfies H < Hub (or better yet, H << Hub).
11. Notice that no functions from the NN Toolbox are necessary.
Hope this helps.
Greg

Plus de réponses (2)

Greg Heath
Greg Heath le 31 Août 2012
Modifié(e) : Walter Roberson le 1 Sep 2012
>Hi i am a master student and i am developping a matlab code for evolutionary
>neural network so the training algorithm is done with a genetic algoritm and i
>dont need to train my neural network with any training function available ,that's
>why i set the epochs to 1.
Since you are not going to use any of the Toolbox training functions, do not use the function train and don't initialize any of it's parameters
This is your code
net=NEWFF(minmax(trainInput'),[hn,1], 'tansig','purelin'},'traingd');
Erroneously capitalized newff, omitted a left brace and initialized a training algorithm that won't be used.
If you are going to use a genetic algorithm you should not use TRAIN. Therefore, it makes no sense to initialize training parameters.
Once input and target matrices are normalized and edited, the only NNET TBX functions needed are net.IW, net.LW, net.b, sim and mse.
I recommend starting with a a general genetic algorithm outline. Then determine where the NN creation, weight updating and simulation commands should be placed.
It might be worthwhile to search online, including the archives of comp.ai.neural-nets and comp.soft-sys.matlab for sample code.
Hope this helps.
Greg

Mariem Harmassi
Mariem Harmassi le 1 Sep 2012
Hi firstly i want to think you for your help , i used a gentic algorithm as follow [x fval exitflag output population scores] = ga(@my_fun, nvars, options); and edit a matlab file my_fun.m where i declared the objective function of the genetic algorithm my_fun which will recieve as input the gneration of chromosomes : in this file a need to train my neural network just one time (one iteration) to have the mse and decide on the performance of the chromosome used.
  3 commentaires
Mariem Harmassi
Mariem Harmassi le 1 Sep 2012
Modifié(e) : Walter Roberson le 1 Sep 2012
  1. Ok for the capitals i am just new in Matlab but even i use sim the problem persists how can i control the number of iterations ?
  2. i tried to set the network weights baut it doesn t work this is the code :
ainInput=[1 0.4 0.2 0.7]
trainOutput=[0.8 ]
chrom=[0.5 0.6 0.8 0.6 0.7 0.9 0.8 0.4 0.5 0.9 0.9;
0.1 0.7 0.6 0.7 0.9 0.5 0.9 0.2 0.4 0.5 0.9]
X=chrom(1,:)
net=newff(minmax(trainInput'),trainOutput',[6,1]);
et.IW
ans =
[6x0 double]
[]
[]
>> net.LW
ans =
[] [] []
[1x6 double] [] []
[] [0x1 double] []
>> net.b
ans =
[6x1 double]
[ 0]
[0x1 double]
for the input layer it seems there is no connection between the four input trainInput and the hiiden layer ? what s wrong ?
Greg Heath
Greg Heath le 1 Sep 2012
You appear to be very confused. I suggest the following:
1. Try to duplicatethe results from demos and/or examples in the NN Toolbox. 2. Check out some of my posted code via the search words
heath newff close clear
Do not attempt a genetic solution until you understand these basics.
Hope this helps.
Greg

Connectez-vous pour commenter.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by