フィルターのクリア

Invalid value for OPTIONS parameter InitialPopulationMatrix.

12 ビュー (過去 30 日間)
roja chigiti
roja chigiti 2018 年 4 月 13 日
編集済み: Stephan 2018 年 4 月 16 日
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.
  2 件のコメント
roja chigiti
roja chigiti 2018 年 4 月 16 日
sir attached code is what i am trying to do.
roja chigiti
roja chigiti 2018 年 4 月 16 日
can you enlighten me sir?

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

その他の回答 (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
roja chigiti
roja chigiti 2018 年 4 月 16 日
Thank you so much sir ,.. its working fine

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


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.

  1 件のコメント
roja chigiti
roja chigiti 2018 年 4 月 16 日
Name Size Bytes Class Attributes
si 1x256 2048 double

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


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 Center および File ExchangeSolver 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