资源简介
差分进化算法解决特征选择问题,差分进化算法解决特征选择问题,Differential evolution algorithm to solve the problem of feature selection,Differential evolution algorithm to solve the problem of feature selection,
代码片段和文件信息
function [ErrSubset] = DEFS(data_trdata_tsDNFPSIZELdclassifGEN)
%%
% Differential Evolution based Feature Selection
% Inputs
% ------
% data_tr: training dataset (with NP1 patterns x NF+1 features with last column being the training class label)
% data_ts: testing dataset (with NP1 patterns x NF+1 features with last column being the testing class label)
% NP: number of patterns (NP1 and NP2 used for example)
% NF: number of features
% DNF: desired number of features to be selected
% PSIZE:population size
% Ld: either load initial population (Ld=1) or simply initialize a new population (Ld=0)
% classif: takes text value as: ‘LDA‘ or ‘KNN‘ or ‘NB‘ or ‘RegTree‘
% GEN: number of generations or iterations
%
% OutPuts
% -------
% Err: Achieved error rate across the different itreations
% Subset: selected feature subset (feature indices)
%
% Example:
% -------
% load IRIS.txt
% [ErrSubset] = DEFS(iris(1:2:end1:end)iris(2:2:end:)3500‘KNN‘100)
% CONTROL PARAMETERS %
D = DNF; % dimension of problem
NP = PSIZE; % size of population
CR = 0.5; % crossover constant
L = 1; % low boundary constraint
H = size(data_tr2)-1; % high boundary constraint
NF = H;
NE = 5;
% Ld
if nargin < 5 || isempty(Ld)
Ld = 0;
end
if nargin < 6 || isempty(classif)
classif = 0;
end
if nargin < 7 || isempty(GEN)
GEN = 400; % number of generations=iterations
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This section can be used to replace the factor F in the paper
w_start = 0.95; %Initial inertia weight‘s value
w_end = 0.35; %Final inertia weight
w_varyfor = 1;
w_varyfor = floor(w_varyfor*GEN); %Weight change step. Defines total number of iterations for which weight is changed.
w_now = w_start;
inertdec = (.95-.35)/w_varyfor; %Inertia weight‘s change per iteration
w_start = 0.35; %Initial inertia weight‘s value
w_end = 0.95;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% *************************** %
% ** ALGORITHM VARIABLES ** %
% *************************** %
X = zeros(D1); % trial vector
Pop = zeros(DNP); % population
Fit = zeros(1NP); % fitness of the population
r = zeros(31); % randomly selected indices
% *********************** %
% ** CREATE POPULATION ** %
% *********************** %
% initialize random number generator
rand(‘state‘sum(100*clock));
if Ld
load TabK Pop
%Pop = Tab‘;
else
for j=1:NP
FF = randperm(H);
Pop(:j) = FF(1:D)‘; % within b.constraints
end
end
for j = 1:NP % initialize each individual
val =round(Pop(:j))‘;
switch classif
case ‘LDA‘
%LDA classifier
Ac1 = classify(data_ts(:val)data_tr(:val)data_tr(:
- 上一篇:捷联惯导的解算程序
- 下一篇:模糊PID设计+simuli
nk仿真
评论
共有 条评论