-
Notifications
You must be signed in to change notification settings - Fork 1
/
FuzzyC1.m
160 lines (115 loc) · 3.92 KB
/
FuzzyC1.m
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
% Fuzzy C1 stands for FuzzyIWO_MUX 2:1
clc;
clear;
close all;
%% Problem Definition
VarMin=0.2; % Lower Bound of Decision Variables
VarMax=2; % Upper Bound of Decision Variables
%nVar=4; % Number of Decision Variables
nVar=4;
VarSize=[1 nVar]; % Decision Variables Matrix
VarRange=[VarMin VarMax]; % Range of Decision Variables
%% IWO Parameter
MaxIt=10; % Maximum Number of Iterations
% Nweed== No
Nweed= 2; % ( Number of initial population )
%50
Pmax=4; % Maximum number of weed population
%100
Smin=1; % Minimum Number of Seeds
Smax=10; % Maximum Number of Seeds
n=3; % Nonlinear modulation index
%Initialsigma=0.3; % In Fuzzy it is not defined, the value of 0.3 is set to sigma % Initial value of standard deviation
%Finalsigma=0.001; % Final value of standard deviation
% Predfined Sigma
Sigma = 0.3;
%% Initialization
NFE=0;
individual.Position=[];
individual.Cost=[];
pop=repmat(individual,Nweed,1);
for i=1:Nweed
pop(i).Position=unifrnd(VarMin,VarMax,VarSize);
pop(i).Cost=C2(pop(i).Position);
end
% Sort Population
Costs=[pop.Cost];
[Costs SortOrder]=sort(Costs);
pop=pop(SortOrder);
BestSol=[];
WorstCost=zeros(MaxIt+1,1);
BestCost=zeros(MaxIt+1,1);
MeanCost=zeros(MaxIt+1,1);
WorstCost(1)=Costs(end);
BestCost(1)=Costs(1);
nfe=zeros(MaxIt,1);
%% IWO Main Loop
for it=1:MaxIt
%Number Of seeds for each weed
Costs=[pop.Cost];
S=min(Smax,round(Smax-(Smax-Smin)*(Costs-BestCost(it))/(WorstCost(it)-BestCost(it))));
%Iteration Sigma
%Sigma(it)=((((MaxIt-it)^n)/((MaxIt-1)^n))*(Initialsigma-Finalsigma))+Finalsigma;
%Reproduction
Ns=sum(S);
pop2=repmat(individual,Ns,1);
Positions=[pop.Position];
Solution=zeros(1,nVar);
number=1;
for b=1:Nweed
for c=1:S(b)
for d=1:nVar
Seed=normrnd(pop(b).Position(d),(Sigma)^2);
while (Seed>VarMax) || (Seed<VarMin)
if Seed>VarMax
Seed=Seed-(Seed-VarMax);
end
if Seed<VarMin
Seed=Seed+(VarMin-Seed);
end
end
Solution(d)=Seed;
end
pop2(number).Position=Solution;
pop2(number).Cost=C2(pop2(number).Position);
number=number+1;
end
end
% Merge Populations
pop=[pop
pop2]; %#ok
% Sort Population
Costs=[pop.Cost];
[Costs SortOrder]=sort(Costs);
pop=pop(SortOrder);
% Delete Extra Individuals
pop=pop(1:Pmax);
Costs=Costs(1:Pmax);
% Save Results
BestSol=pop(1);
BestCost(it+1)=Costs(1);
WorstCost(it+1)=Costs(end);
MeanCost(it)=mean(Costs);
nfe(it)=NFE;
% Show Information
disp(['Iteration ' num2str(it) ': ' ...
'Best Cost = ' num2str(BestCost(it)) ' , ' ...
'Mean Cost = ' num2str(MeanCost(it))]);
%% 1. Normalization of FIS Inputs
itnormalized = it / MaxIt;
% bests(1) is worst ball
%Bestnormalized = ( bests(1) - bests(it) ) / bests(1)
BestCostnormalized = ( WorstCost(it) - BestCost(it) ) / WorstCost(it)
%% 2. Read FIS file
FISMAT = readfis('Fuzzy_IWO_FIS.fis');
%% 3. Define Input Arguments for FIS Before Firing Rules
U = [itnormalized , BestCostnormalized];
%% 4. Fire Rules or Run Evalfis Command
Y = evalfis(U,FISMAT);
end
%% Results
figure;
plot(BestCost,'g','LineWidth',2);
% semilogy(BestCost,'LineWidth',2);
xlabel('Iteration');
ylabel('Best Fitness = Best Average Power');