Invalid value for OPTIONS parameter InitialPopulationMatrix.

조회 수: 3 (최근 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.


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에서 Genetic Algorithm에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by