genetic algorithm for feature selection

3 次查看(过去 30 天)
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 个评论
Walter Roberson
Walter Roberson 2017-3-23
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 2018-5-20
编辑:Walter Roberson 2018-5-20
nVars = 20; %
should be 401 as number of features.
function [fitnessRMSE] = fitnessfunction(pop)

请先登录,再进行评论。

回答(0 个)

类别

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