Attempt to reference field of non-structure array error message while running genetic algorithm code

While running my genetic algorithm code i'm getting the following errors
Attempt to reference field of non-structure array.
Error in setwb (line 23)
inputLearn = net.hint.inputLearn;
Error in rmse_test (line 17)
net = setwb(net,x');
Error in @(x)rmse_test(x,{net,inputs,targets})
Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11)
fcn_handle = @(x) fcn(x,FcnArgs{:});
Error in fcnvectorizer (line 14)
y(i,:) = feval(fun,(pop(i,:)));
Error in makeState (line 47)
Score = fcnvectorizer(state.Population(initScoreProvided+1:end,:),FitnessFcn,1,options.SerialUserFcn);
Error in gaunc (line 41)
state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ga (line 351)
[x,fval,exitFlag,output,population,scores] = gaunc(FitnessFcn,nvars, ...
Error in genetic_algorithm (line 55)
[x_ga_opt, err_ga] = ga(h, 3, ga_opts);
Caused by:
Failure in user-supplied fitness function evaluation. GA cannot continue.
Can someone help me how to solve this error and make this code run properly...??
I have attached my code and data here

 採用された回答

You coded
h = @(x) rmse_test(x, {net, inputs, targets});
but rmse_test expects (x, net, inputs, targets) as separate variables.

8 件のコメント

@walter so how should i code that to give as separate variables?
h = @(x) rmse_test(x, net, inputs, targets);
Priya Dharshini
Priya Dharshini 2016 年 5 月 9 日
編集済み: Walter Roberson 2016 年 5 月 9 日
but @walter sir, I even tried using that statement already. I got error like this
Index exceeds matrix dimensions.
Error in setwb (line 32)
net.IW{i,j}(:) = x(inputWeightInd{i,j});
Error in rmse_test (line 17)
net = setwb(net,x');
Error in @(x)rmse_test(x,net,inputs,targets)
Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11)
fcn_handle = @(x) fcn(x,FcnArgs{:});
Error in fcnvectorizer (line 14)
y(i,:) = feval(fun,(pop(i,:)));
Error in makeState (line 47)
Score = fcnvectorizer(state.Population(initScoreProvided+1:end,:),FitnessFcn,1,options.SerialUserFcn);
Error in gaunc (line 41)
state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ga (line 351)
[x,fval,exitFlag,output,population,scores] = gaunc(FitnessFcn,nvars, ...
Error in genetic_algorithm (line 55)
[x_ga_opt, err_ga] = ga(h, 3, ga_opts);
Caused by:
Failure in user-supplied fitness function evaluation. GA cannot continue.
so how should i give the function handler which will make it run properly...?? And may i know what and where the problem is..??
You have a 43 x 3 input matrix, so you need 43 x 3 input weights, but your code is trying to get by with only 3. In your ga call you need to change the 3 to numel(inputs)
Priya Dharshini
Priya Dharshini 2016 年 5 月 11 日
編集済み: Walter Roberson 2016 年 5 月 11 日
@walter sir, when i change ga call with n=3 to n=numel(inputs) the value of n is taken as 129 <1X1 double> and gives the same error. How should i rectify this error?
You had to transpose your inputs, and a different number of variables was called for. See attached.
Note: takes a while to run...
Thank you sir. It works fine :) Was so helpful
Please Accept the answer if it works for you.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by