Problem training Neural network
Show older comments
Hi,
I am trying to train a simple multilayer feed forward neural network using a genetic algorithm. I have been trying to train the network to learn a sine wave from 0:6pi. However, the search stops abruptly without finding the global optimal solution. I usually get a MSE of 1e-2 or greater. I tried with 4 neurons to 20 neurons in the hidden layer, but the search still ends with non-optimal solutions. I also tried to train a ANN using the the neural network toolbox's GUI nftool, which gives very good results, even with 4 neurons in the hidden layer. Isn't genetic search supposed to better than BP based training? Or is something wrong with my code?
The function I am using for optimization is as defined below:
function [err]=ANN(weights)
global len; %len is the number of neurons in the hidden layer
w=weights(1:len); %weights from input layer to hidden layer
u=weights(len+1:2*len); %bias at hidden layer
v=weights(2*len+1:3*len); %weights from hidden layer to output layer
b=weights(3*len+1); %bias at the output layer
outh=sigmtf(w,u,input);%Sigmoid transfer function
outpma=outh.*repmat(v',[1 length(input)]);
outp=ones(1,length(w))*outpma+b; %final output of the network
err=mean(((outp-target)).^2); error to be minimized
%Function used to train the error is from the GA toolbox.
ga(@ANN,len*3+1)
Answers (0)
Categories
Find more on Deep Learning Toolbox 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!