genetic algorithm for feature selection

1 visualización (últimos 30 días)
HASAN AL-KAF
HASAN AL-KAF el 23 de Mzo. de 2017
Editada: Walter Roberson el 20 de Mayo de 2018
Hi
I used the code in MathWorks and I edited but I couldn't get the result I find these error after i run the code
Not enough input arguments.
Error in lastga>fitnessfunction (line 47)
fitnessRMSE = sqrt(sum(bsxfun(@minus,X,Y').^2,2)/20);
Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11)
fcn_handle = @(x) fcn(x,FcnArgs{:});
Error in makeState (line 47)
firstMemberScore = FitnessFcn(state.Population(initScoreProvided+1,:));
Error in gaunc (line 40)
state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ga (line 356)
[x,fval,exitFlag,output,population,scores] = gaunc(FitnessFcn,nvars, ...
Error in lastga (line 23)
[chromosome,~,~,~,~,~] = ga(FitnessFcn,nVars,options);
Caused by:
Failure in initial user-supplied fitness function evaluation. GA cannot continue.
>>
I Use 2015b version . I used the code for genetic algorithm for feature selection for near infrared data
Clear all
Data = load('data.mat')
% This is available in Mathworks
GenomeLength =401; % This is the number of features in the dataset
options = gaoptimset('CreationFcn', {@PopFunction},...
'PopulationSize',50,...
'Generations',100,...
'PopulationType', 'bitstring',...
'SelectionFcn',{@selectionroulette},...
'MutationFcn',{@mutationuniform, 0.1},...
'CrossoverFcn', {@crossoverarithmetic,0.8},...
'EliteCount',2,...
'StallGenLimit',100,...
'PlotFcns',{@gaplotbestf},...
'Display', 'iter');
rand('seed',1)
nVars = 20; %
FitnessFcn = @fitnessfunction ;
[chromosome,~,~,~,~,~] = ga(FitnessFcn,nVars,options);
Best_chromosome = chromosome; % Best Chromosome
Feat_Index = find(Best_chromosome==1); % Index of Chromosome
end
%%%POPULATION FUNCTION
function [pop] = PopFunction(GenomeLength,~,options)
RD = rand;
pop = (rand(options.PopulationSize, GenomeLength)> RD); % Initial Population
end
%%%FITNESS FUNCTION You may design your own fitness function here
function [fitnessRMSE] = fitnessfunction(X ,Y)
X= data.x ;
Y=data.y ;
fitnessRMSE = sqrt(sum(bsxfun(@minus,X,Y').^2,2)/nvar);
end
  2 comentarios
Walter Roberson
Walter Roberson el 23 de Mzo. de 2017
Please post the complete error message, everything in red.
(We do not have your data.mat file so we cannot just run the code ourselves to test.)
Dheeb Albashish
Dheeb Albashish el 20 de Mayo de 2018
Editada: Walter Roberson el 20 de Mayo de 2018
nVars = 20; %
should be 401 as number of features.
function [fitnessRMSE] = fitnessfunction(pop)

Iniciar sesión para comentar.

Respuestas (0)

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