how do i optimize weights of neural network using GA in MATLAB(need codes to achieve that), again how do i call this function that optimzes the neural network weights in GA GUI so i can work with it from the interface
4 views (last 30 days)
Show older comments
i need to train a neural network(a feedforward network and also a narx network) using genetic algorithm.and i need to do this by using GA to search for weights that will make the network learn very well.
2 Comments
Alisina Gharjestani
on 6 Dec 2017
Hi,have you developed a code for optimizing a narx network by using genetic algorithm?
Greg Heath
on 7 Dec 2017
What have you found when you searched the NEWSGROUP and ANSWERS using
genetic narx
and
genetic narxnet
?
Accepted Answer
Greg Heath
on 20 May 2015
When
[ I N ] = size(input)
[ O N ] = size(target)
MSE00 = mean(var(target',1))% Reference MSE
The number of available training equations is
Ntrneq = N*O
For an I-H-O node topology the number of unknown weights is
Nw = (I+1)*H+(H+1)*O = (I+O+1)*H+1
Obviously,
1. The "3" in the GA input is replaced by I+O+1
2. The normalized mse calculation is
NMSE = mean((target(:)-output(:)).^2)/MSE00
Of course there will be more complications if the performance measure has to be decomposed into class and trn/val/tst subsets.
Hope this helps.
Greg
2 Comments
Greg Heath
on 24 May 2015
The first two equations yield the sizes of the input and target matrices. I and O are the dimensions of the input and target vectors, respectively. N is the total number of examples.
More Answers (3)
Gurvinder Singh
on 6 May 2016
this code is valid for only one input. if i provide more than one input the code gives an error;
Index exceeds matrix dimensions.
Error in separatewb (line 34) iw{i,j} = reshape(wb(hints.iwInd{i,j}),...
Error in setwb (line 23) [b,IW,LW] = separatewb(net,wb,hints);
Error in mse_test (line 9) net = setwb(net, x);
Error in Untitled2>@(x)mse_test(x,net,inputs,targets)
Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11) fcn_handle = @(x) fcn(x,FcnArgs{:});
Error in makeState (line 47) firstMemberScore = FitnessFcn(state.Population(initScoreProvided+1,:));
Error in gaunc (line 40) state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ga (line 371) [x,fval,exitFlag,output,population,scores] = gaunc(FitnessFcn,nvars, ...
Error in Untitled2 (line 24) [x_ga_opt, err_ga] = ga(h, 3*n+1, ga_opts);
Caused by: Failure in initial user-supplied fitness function evaluation. GA cannot continue.
how to run it for more than one input???
0 Comments
Greg Heath
on 6 May 2016
I have posted a new MIMO GA code in the NEWSGROUP.
Hope this helps.
Thank you for formally accepting my answer
Greg
4 Comments
Harshith Bhat
on 28 Feb 2017
These are the errors Error in @(x)mse_test(x,net,inputs,targets)
Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11) fcn_handle = @(x) fcn(x,FcnArgs{:});
Error in makeState (line 47) firstMemberScore = FitnessFcn(state.Population(initScoreProvided+1,:));
Error in gaunc (line 40) state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ga (line 356) [x,fval,exitFlag,output,population,scores] = gaunc(FitnessFcn,nvars, ...
Error in experiment (line 30) [x_ga_opt, err_ga] = ga(h, 3*n+1, ga_opts);
Caused by: Failure in initial user-supplied fitness function evaluation. GA cannot continue.
>>
Terry Chen
on 10 Nov 2020
Dear Greg,
where can get this link : http://www.mathworks.com/matlabcentral/newsreader/view_thread/344888#944621
It seems disappear.
Terry
Greg Heath
on 19 May 2015
Unfortunately, I lost my own NN GA code to a computer crash many years ago. I have not attempted to replace it. However, I have searched the NEWSGROUP and ANSWERS for examples combining the NN and OPTIMIZATION Toolboxes.
There is a post by the MATLAB SUPPORT TEAM that outlines the procedure for a SISO problem. However, I have not been successful in using it.
There is a more recent post by a user that successfully yields an answer called the Pareto Front. I haven't learned enough to go beyond that.
Try searching the NEWSGROUP and ANSWERS using
mathworks support team neural genetic
and
mathworks support team neural GA
Then
neural genetic pareto
and
neural GA pareto
and finally, just
neural genetic
and
neural GA
If you are successful, please bless us with your knowledge.
Hope this helps.
Thank you if you think this answer is worth a formal acceptance
Greg
2 Comments
Greg Heath
on 16 Mar 2016
inputs =1:10;
targets = cos(inputs.^2)
is a RIDICULOUS example:
plot(inputs,targets)
targets = cos(inputs).^2
is no better.
The problem is in the inputs spacing. 16 points per period should do the trick.
Hope this helps.
Greg
See Also
Categories
Find more on Sequence and Numeric Feature Data Workflows in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!