Invalid value for OPTIONS parameter InitialPopulationMatrix.

4 次查看(过去 30 天)
following is my code.while executing it is generating the following error:
Error using validate (line 286)
Invalid value for OPTIONS parameter InitialPopulationMatrix.
Error in gacommon (line 65)
[options,nvars,FitnessFcn,NonconFcn] = validate(options,type,nvars,fun,nonlcon,user_options);
Error in ga (line 336)
NonconFcn,options,Iterate,type] = gacommon(nvars,fun,Aineq,bineq,Aeq,beq,lb,ub, ...
Error in template (line 29)
[chromosome,~,~,~,~,~]=ga(fitnessfcn,nVars,options) ;
i would really appreciate if anyone can guide me through it following is the implementation code:
import java.security.*;
import java.math.*;
import java.lang.*;
md = MessageDigest.getInstance('SHA-256');
hash = md.digest(uint8(all));
si=reshape( (dec2bin(typecast(hash, 'uint8'),8) - '0').', 1, []);
%selection of best feature using genetic algorithm
tournamentSize=2;
options = gaoptimset('InitialPopulation',si,...
'PopulationSize',200,...
'Generations',100,...
'PopulationType', 'bitstring',...
'SelectionFcn',{@selectiontournament,tournamentSize},...
'MutationFcn',{@mutationuniform, 0.01},...
'CrossoverFcn', {@crossoverarithmetic,0.8},...
'EliteCount',0.05*1,...
'StallGenLimit',100,...
'PlotFcns',{@gaplotbestf},...
'Display', 'iter');
rng('Shuffle','v5normal')
fitnessfcn = @FitFunc;
nVars = 1;
[chromosome,~,~,~,~,~]=ga(fitnessfcn,nVars,options) ;
Best_chromosome = chromosome; % Best Chromosome
Feat_Index = find(Best_chromosome==1); % Index of Chromosome
end
function [FitVal] = FitFunc(Population)
FitVal = mean(Population == 1) * 0.01;
end

采纳的回答

Stephan
Stephan 2018-4-16
编辑:Stephan 2018-4-16
To look if your code is working you could set si = 25 and see if it works.
Are there any zeros or negative values in your si variable? Also a value of one would not really make sense.
If using a vector for population size matlab works with subpopulations. Perhaps you can start using a double variable with one number instead.

更多回答(5 个)

Walter Roberson
Walter Roberson 2018-4-16

https://www.mathworks.com/help/gads/gaoptimset.html

"InitialPopulationMatrix: Initial population used to seed the genetic algorithm. Has up to PopulationSize rows and N columns, where N is the number of variables."

Your 1 x 256 matrix would therefore be appropriate if you had 256 variables, but you only have 1 variable.

You need to use the transpose of your population matrix, to give 256 rows with 1 column.

  3 个评论
roja chigiti
roja chigiti 2018-4-16
after resolving these errors i am not able to get the best fit value

请先登录,再进行评论。


Stephan
Stephan 2018-4-16

Hi,

so far i found three problems with your code:

1. replace your ki-variable by populationsize

options = gaoptimset('InitialPopulation',populationsize,...

instead of

options = gaoptimset('InitialPopulation',ki,...

2. Too many input arguments for your Crossover Function

'CrossoverFcn', {@crossoverscattered},...

instead of

'CrossoverFcn', {@crossoverscattered,0.8},...

3. The result of your option for 'EliteCount' is not an integer but it has to be. So ether you delete this option (i guess your choosen value is the standard value) or use the worlds best number for example:

'EliteCount',42,...

instead of

'EliteCount',0.05*1,...

After changing the code this way your code worked for me.

That helped?.

  1 个评论
roja chigiti
roja chigiti 2018-4-16
编辑:roja chigiti 2018-4-16
thank you sir,..it solves most of the error sir but population size is number i want to send ki' as my initial population as i want to select best fit value from ki ,. by following so i am not getting best fit value sir

请先登录,再进行评论。


Stephan
Stephan 2018-4-16

Hi,

what is the result when you type

whos si

seems like Matlab doesnt accept this parameter.


Stephan
Stephan 2018-4-16

Hi,

try:

options = gaoptimset('InitialPopulation',ki',...

instead of

options = gaoptimset('InitialPopulation',ki,...
  1 个评论
roja chigiti
roja chigiti 2018-4-16
编辑:roja chigiti 2018-4-16
i tried it sir and its working fine.. thank you so much for your help.. i need to change my fitness function

请先登录,再进行评论。


Stephan
Stephan 2018-4-16
编辑:Stephan 2018-4-16
it was a pleasure to me ;-)

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by