-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPRDH.m
More file actions
84 lines (72 loc) · 2.7 KB
/
PRDH.m
File metadata and controls
84 lines (72 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
function [solution, time, off, ofit, site, paretoAVE, tempVar, bitImportance] = PRDH(train_F, train_L, cnti)
fprintf('PRDH\n');
tic
global maxFES
global sizep
FES = 1;
dim = size(train_F, 2);
ofit = zeros(sizep, 2); % Objective function values for the population
initThres = 1;
thres = 0.1; % Exponential decay constant
paretoAVE = zeros(1, 2); % To save final result of the Pareto front
%% Initialization
Problem.D = dim;
Problem.N = sizep;
Problem.lower = zeros(1, Problem.D);
Problem.upper = ones(1, Problem.D);
Problem.encoding = 4; % Binary encoding for all variables
Population = InitializePopulation(Problem);
[~, FrontNo, CrowdDis] = EnvironmentalSelection(Population, Problem.N);
%% Evaluate
for i = 1:Problem.N
[ofit(i, 1), ofit(i, 2)] = FSKNNfeixiang(Population(i).decs, train_F, train_L);
end
site = find(FrontNo == 1);
solution = ofit(site, :);
solution(:, 2) = solution(:, 2) / dim;
disp('Solution:');
disp(solution);
erBestParetoAVE = 1; % To save the history best
paretoAVE(1) = mean(solution(:, 1));
paretoAVE(2) = mean(solution(:, 2));
%% Optimization
while FES <= maxFES
MatingPool = TournamentSelection(2, Problem.N, FrontNo, -CrowdDis);
Offspring = OffspringReproduction(Population(MatingPool), Problem);
[Population, FrontNo, CrowdDis] = EnvironmentalSelection([Population, Offspring], Problem.N);
% Evaluate new population
for i = 1:length(Offspring)
[ofit(end+1, 1), ofit(end, 2)] = FSKNNfeixiang(Offspring(i).decs, train_F, train_L);
end
% Update solution and pareto front
site = find(FrontNo == 1);
solution = ofit(site, :);
paretoAVE(1) = mean(solution(:, 1));
paretoAVE(2) = mean(solution(:, 2));
FES = FES + 1;
end
%% Finalization
tempVar{1} = ofit; % All objective function values
tempVar{2} = FrontNo; % All front numbers
tempVar{3} = CrowdDis; % All crowding distances
tempVar{4} = []; % Other temporary variables if needed
clear tAveError;
clear tAveFea;
clear tErBest;
clear tThres;
toc
time = toc;
off = Population.decs; % Ensure off is assigned
end
function Population = InitializePopulation(Problem)
T = min(Problem.D, Problem.N * 3);
PopDec = zeros(Problem.N, Problem.D);
PopObj = zeros(Problem.N, 2);
PopCon = zeros(Problem.N, 1);
for i = 1 : Problem.N
k = randperm(T, 1);
j = randperm(Problem.D, k);
PopDec(i, j) = 1;
end
Population = SOLUTION(PopDec, PopObj, PopCon);
end