genetic algorithm for feature selection

8 views (last 30 days)
HASAN AL-KAF on 23 Mar 2017
Edited: Walter Roberson on 20 May 2018
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},...
'PopulationType', 'bitstring',...
'MutationFcn',{@mutationuniform, 0.1},...
'CrossoverFcn', {@crossoverarithmetic,0.8},...
'Display', 'iter');
nVars = 20; %
FitnessFcn = @fitnessfunction ;
[chromosome,~,~,~,~,~] = ga(FitnessFcn,nVars,options);
Best_chromosome = chromosome; % Best Chromosome
Feat_Index = find(Best_chromosome==1); % Index of Chromosome
function [pop] = PopFunction(GenomeLength,~,options)
RD = rand;
pop = (rand(options.PopulationSize, GenomeLength)> RD); % Initial Population
%%%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);
Dheeb Albashish
Dheeb Albashish on 20 May 2018
nVars = 20; %
should be 401 as number of features.
function [fitnessRMSE] = fitnessfunction(pop)

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!