# GA optimization

6 visualizzazioni (ultimi 30 giorni)
Malathy il 28 Feb 2012
I have developed an neural network with 4 input nodes, 4 hidden nodes and one output node using feed forward back propagation network. Now I need to use GA to optimize and determine the maximum output. How to define the ANN model as the fitness function.
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Seth DeLand il 28 Feb 2012
You can create a function handle to the network and then pass that function handle into GA. Note that GA will pass in a row vector, so if your NN accepts a column vector as input it will need to be transposed. Also, GA minimizes the objective function so we add the negative sign to flip it from a maximization problem to a minimization problem. For example:
objFcn = @(x) -sim(net,x'); % Function that simulates NN and returns output
[xOpt,fVal] = ga(objFcn, 4); % Find the minimum of objFcn with 4 inputs
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Abul Fujail il 4 Apr 2012
Thank you very much...
I am also solving the same problem, Neural network with 4 input and want to optimize the weights to get the best result. My codes ase shown below in='input_train.tra';
p=transpose(p);
tic;
net=feedforward([.1 .9;.1 .9;.1 .9;.1 .9],[7,1], {'logsig','logsig'},'trainlm');
net=init(net);
tr='target_train.tra';
x=transpose(x);
net.trainParam.epochs=600;
net.trainParam.show=10;
net.trainParam.lr=0.3;
net.trainParam.mc=0.6;
net.trainParam.goal=0;
[net,tr]=train(net,p,x);
%y=sim(net,p);
objFcn = @(x) -sim(net,x') % Function that simulates NN and returns output
[xOpt,fVal] = ga(objFcn, 4) % Find the minimum of objFcn with 4 inputs
The target vector consists of a vector with 80 values, and input consists of 4 vectors with 80 values in each vector... Now i want that the result should also consists of 80 values, one result for each input pattern... what changes should be done in the program... please suggest me... thank you.. Fujail

Accedi per commentare.

### Categorie

Scopri di più su Function Approximation and Clustering in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by