-
Notifications
You must be signed in to change notification settings - Fork 1
/
IIPO.m
210 lines (172 loc) · 7.1 KB
/
IIPO.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
%% Iteration-baed IPO (IIPO) algorithm for IIR filter design
clc ;
clear all ;
% close all ;
% format shortg
prompt = {'Please enter the number of run:'} ;
title = 'IIPO Algorithm' ;
dims = [1 45] ;
nline = 1 ;
definput = {'1','a'} ;
answer = inputdlg(prompt,title,dims,definput) ;
Run_Num = answer(1,:) ;
Run_Num = str2num(Run_Num{:}) ;
prompt = {'maxt','npop' ,'F','Beta','c','m_Ratio'} ;
title = 'IIPO parameters' ;
nline = 1 ;
dims = [1 45] ;
definput = {'200','50' '1','2','1.75','0','a'} ; %Exp. 1_1&2:1,1.75,1.75,0; Exp. 2_1&2:1,2,1.75,0; %Exp. 3_1&2:1,2,1.75,0;
answer = inputdlg(prompt,title,dims,definput) ;
maxt = answer(1,:); maxt = str2num(maxt{:}) ;
npop = answer(2,:); npop = str2num(npop{:}) ;
F = answer(3,:); F = str2num(F{:}) ;
Beta = answer(4,:); Beta = str2num(Beta{:}) ;
c = answer(5,:); c = str2num(c{:}) ;
m_Ratio = answer(6,:); m_Ratio = str2num(m_Ratio{:}) ;
n = 0 ;
Bests = zeros(1 , Run_Num ) ;
BestsPop = zeros(Run_Num , 9 ) ; %varaible number
BestsCnvg = zeros(Run_Num , 200 ) ; % numofruns
RunTime = zeros(1 , Run_Num ) ;
NoU_index = zeros(Run_Num , 1 ) ;
Stable = 0 ;
NoU = 0 ; % Number of Unstable filters
for n = 1:Run_Num
tic
n
%% IIR Filter Fitness
[Hfilt Wfilt] = IIR_main();
%%
% Function_name = 'F8'
% [lb,ub,dim,fobj] = Get_Functions_details(Function_name);
% costfunction = fobj;
nvar = 9 ; % Exp. 1_1:2, Exp. 1_2:4; Exp. 2_1:4, Exp. 2_2:6; Exp. 3_1:9; Exp. 3_2=11;
varsize = [1 nvar] ;
varmin = -1.2 ;
varmax = +1.2 ;
%%
N = rand(size(Hfilt,1),1);
% N=rand(size(Hfilt,1),1)-0.5; % Between [-0.5 0.5]
% N=rand(size(Hfilt,1),1); % Between [0 1]
% N=rand(size(Hfilt,1),1)*2-1; % Between [-1 1]
%%
%% IIPO parameters
% npop = 50;
% maxt = 200;
%%
empty_ball.position =[];
empty_ball.cost =[];
empty_ball.velocity =[];
empty_ball.acceleration =[];
ball = repmat(empty_ball,npop,1);
globalbest.cost = inf;
for i = 1:npop
ball(i).position = unifrnd(varmin,varmax,varsize);
ball(i).velocity = zeros(varsize);
ball(i).Acceleration = zeros(varsize);
ball(i).sbetter = zeros(varsize);
ball(i).mean = zeros(varsize);
ball(i).cost = Fitness(ball(i).position,Hfilt,Wfilt,N);
if ball(i).cost < globalbest.cost
globalbest.position = ball(i).position;
globalbest.cost = ball(i).cost;
end
end
bests = zeros(maxt,1);
T = m_Ratio.*maxt;
%%
for t = 1:maxt
sumcost = 0;
s = 1;
for i= 1:npop
ball(i).sbetter = ball(i).position;
for j= 1:npop
df = ball(j).cost - ball(i).cost;
if df < 0
ball(i).sbetter = ball(i).sbetter + ball(j).position;
s = s+1;
end
end
ball(i).mean = ((ball(i).sbetter) ./ s);
P_MEAN = F.*(maxt./t);
k1 = (1./t)^(Beta) ;
k2 = c ./ (1 + exp( - (t-T)));
ball(i).velocity = globalbest.position-ball(i).position;
ball(i).Acceleration = P_MEAN .* ball(i).mean - ball(i).position;
ball(i).position = ball(i).position + ...
k1 .* (ball(i).Acceleration) .* rand(varsize)+...
k2 .* ball(i).velocity .* rand(varsize);
ball(i).position = min(max(ball(i).position,varmin),varmax);
ball(i).cost = Fitness(ball(i).position,Hfilt,Wfilt,N);
if ball(i).cost < globalbest.cost
globalbest.position = ball(i).position;
globalbest.cost = ball(i).cost;
end
bests(t) = globalbest.cost;
sumcost = sumcost+ball(i).cost;
end
disp(['Iteration' num2str(t) ':bestcost=' num2str(bests(t))]);
meanfits(t) = sumcost/npop;
end
BestsCnvg(n,:) = bests ;
Bests(n) = bests(t-1) ;
BestsPop(n,:) = globalbest.position ;
RunTime(n) = toc ;
[Bsoa Asoa Z_f P_f] = Matching(globalbest.position) ;
Stable = abs(P_f) ;
if any(Stable > 1)
NoU = NoU + 1 ;
NoU_index(n) = n ;
end
end
% disp([' ']);
disp([' ']);
disp([' IIPO ']);
disp(['-----------------------------------------------']);
disp(['Number of run = ' num2str(Run_Num)]);
disp([' ']);
disp([' ']);
disp(['**************** Statistical indexes : Time ****************']);
disp(['------------------------------------------------']);
disp(['Per run = ' num2str(RunTime)]);
disp(['Average = ' num2str(mean(RunTime))]);
disp(['Standard deviation = ' num2str(std(RunTime))]);
disp(['Maximum = ' num2str(max(RunTime))]);
disp(['Minimum = ' num2str(min(RunTime))]);
% disp([' ']);
disp([' ']);
disp(['***************** Statistical indexes : Fitness ****************']);
disp(['-----------------------------------------------']);
disp(['Number of run = ' num2str(Run_Num)]);
disp(['Best cost per run = ' num2str(Bests)]);
disp(['Average = ' num2str(mean(Bests))]);
disp(['Standard deviation = ' num2str(std(Bests))]);
disp(['Maximum = ' num2str(max(Bests))]);
disp(['Minimum = ' num2str(min(Bests))]);
% disp([' ']);
disp([' ']);
disp(['***************** Instability ****************']);
disp(['-----------------------------------------------']);
disp(['Nomber of Unstable Filters = ' num2str(NoU)]);
disp([' ']);
%% Implementation of IIR IIPO *******************************
[minimum index] = min(Bests);
disp([ ' Best Solution = ' num2str(BestsPop(index,:))])
[Bsoa Asoa Z_f P_f] = Matching(BestsPop(index,:))
IIR_main();
%
figure(1);
plot(BestsCnvg(index,:),'.b','LineWidth',1);
legend('Bests')
xlabel('Iteration')
ylabel('Fitness')
figure(2);
zplane(Z_f,P_f); %%% Displays the poles and zeros of discrete-time systems.
legend('Zero','Pole');
xlabel('Real Part');
ylabel('Imaginary Plot');
% title('Pole-Zero Plot in IIPO');
figure(3);
H = abs(Hfilt);
Hdb=20*log10(H);
plot(Wfilt/512,Hdb);grid