Subscripted Assignment Dimension Mismatch when using neural network output as fitness function for Genetic algorithm

Dear all I am trying to minimize following fitness function in global toolbox using Genetic algorithm using output from neural network (nftool) toolbox
Youtput = wo * (2 /1+exp (-2*wh * X + b1)) -1 +b2
wo = weight matrix of output layer (10× 2) matrix
wh = weight matrix of hidden layer (10× 2) matrix
X1 = input vector containing 2 variables
b1= Input bias (10×1) matrix
b2 = output bias (2× 1) matrix
I wrote following code which could be used as fitness function in global minimization toolbox.
function drug = drug_rel(X1)
reX1 = repmat(X1, 10, 1);
load ('weightinp');
wh = weightinp;
load ('weight1');
wo = weight1;
load ('bias');
b1 = bias;
load('bias2');
b2 = bias2;
drug = wo.*(2/1+exp(-2.*(wh.*reX1)+b1)-1)+b2;
When I fed this code as fitness function in genetic algorithm toolbox (optimtool(‘ga’)) I got an error message “Subscripted assignment dimension mismatch”. I tried a lot of techniques to correct it, but none worked. Now, I am out of ideas. Please help me to find the root cause of this problem and what needs to be done to correct this problem. Thank you

1 Comment

@shailendra shera: I've formatted your code such that it is readable now. Do you see the benefit of posting readable code if you want others to help you?
Please post the complete error message, such that the readers do not have to guess, which line is failing.
Do I see correctly: You have 3 load commands in a function, which is called frequently? This is very inefficient. See http://www.mathworks.com/matlabcentral/answers/1971 .

Sign in to comment.

Answers (0)

Asked:

on 14 May 2017

Commented:

Jan
on 14 May 2017

Community Treasure Hunt

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

Start Hunting!