genetic algorithm for feature selection

1 回表示 (過去 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 Center および File ExchangeGenetic Algorithm についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by