Invalid value for OPTIONS parameter InitialPopulationMatrix.

3 visualizaciones (últimos 30 días)
roja chigiti
roja chigiti el 13 de Abr. de 2018
Editada: Stephan el 16 de Abr. de 2018
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

Respuesta aceptada

Stephan
Stephan el 16 de Abr. de 2018
Editada: Stephan el 16 de Abr. de 2018
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.

Más respuestas (5)

Walter Roberson
Walter Roberson el 16 de Abr. de 2018

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 comentarios
roja chigiti
roja chigiti el 16 de Abr. de 2018
after resolving these errors i am not able to get the best fit value
roja chigiti
roja chigiti el 16 de Abr. de 2018
Thank you so much sir ,.. its working fine

Iniciar sesión para comentar.


Stephan
Stephan el 16 de Abr. de 2018

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 comentario
roja chigiti
roja chigiti el 16 de Abr. de 2018
Editada: roja chigiti el 16 de Abr. de 2018
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

Iniciar sesión para comentar.


Stephan
Stephan el 16 de Abr. de 2018

Hi,

what is the result when you type

whos si

seems like Matlab doesnt accept this parameter.


Stephan
Stephan el 16 de Abr. de 2018

Hi,

try:

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

instead of

options = gaoptimset('InitialPopulation',ki,...
  1 comentario
roja chigiti
roja chigiti el 16 de Abr. de 2018
Editada: roja chigiti el 16 de Abr. de 2018
i tried it sir and its working fine.. thank you so much for your help.. i need to change my fitness function

Iniciar sesión para comentar.


Stephan
Stephan el 16 de Abr. de 2018
Editada: Stephan el 16 de Abr. de 2018
it was a pleasure to me ;-)

Categorías

Más información sobre Genetic Algorithm en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by