genetic algorithm for feature selection

조회 수: 3 (최근 30일)
HASAN AL-KAF
HASAN AL-KAF 2017년 3월 23일
편집: Walter Roberson 2018년 5월 20일
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