在Hammerstein非线性模型中,基于PSO的参数辨识系统
Hammerstein非線性模型的基于PSO的參數(shù)辨識系統(tǒng)的本質(zhì)就是將參數(shù)的辨識問題轉(zhuǎn)換為參數(shù)空間優(yōu)化問題,對整個參數(shù)域進(jìn)行搜索并最終獲得最優(yōu)的參數(shù)估計。我們需要的參數(shù)辨識模型具體描述如下所示:
? ? ? ? 將Hammerstein非線性模型進(jìn)行分離,得到8個不同的模型,逐個對其參數(shù)進(jìn)行識辨。下面從較為簡單的NL8開始說明直到NL1,NL這九個結(jié)果。最后對整個Hammerstein非線性模型進(jìn)行識辨仿真。
NL
原非線性模型的坐標(biāo)圖。
PSO最佳適應(yīng)曲線。
V(t)中七個參數(shù)的辨識過程。
Y(t)的三個參數(shù)的辨識過程如下所示:
部分核心代碼如下:
?
clc;
close all;
clear;
%對a1,b1,b2進(jìn)行參數(shù)辨識
Len = ?1000;
%開始粒子群優(yōu)化
%開始粒子群優(yōu)化
%粒子群參數(shù)設(shè)置
ys ? ? ? ? = zeros(1,Len);
y0 ? ? ? ? = zeros(1,Len);
var ? ? ? ?= 0.001; ? ? ? ? % 噪聲方差
err ? ? ? ?= 0.01;
iter_max ? = 200; ? ? ? ? ?% 最大迭代次數(shù)
N ? ? ? ? ?= 50; ? ? ? ? ? % 種群規(guī)模
C1 ? ? ? ? = 2; ? ? ? ? ? ?% 加速度常數(shù)
C2 ? ? ? ? = 2;
Xmin ? ? ? = -1; ? ? ? ? ? % 解取值范圍[Xmin,Xmax]
Xmax ? ? ? = 1;
p ? ? ? ? ?= 3; ? ? ? ? ? % 粒子維數(shù)
w ? ? ? ? ?= linspace(0.9,0.4,iter_max); ? % 慣性權(quán)重
X ? ? ? ? ?= Xmin+(Xmax-Xmin)*rand(p,N); ? % 粒子位置
Xpbest ? ? = X; ? ? ? ? ? ? ? ? ? ? ? ? ? ?% 個體最佳位置
Xgbest ? ? = Xmin+(Xmax-Xmin)*rand(p,1); ? % 種群最佳位置
fpbest ? ? = 0*rand(1,N); ? ? ? ? ? ? ? ? ?% 個體最佳適應(yīng)度值
fgbest ? ? = 0; ? ? ? ? ? ? ? ? ? ? ? ? ? ?% 種群最佳適應(yīng)度值
fgbest_fig = zeros(1,iter_max);?
Xgbest_fig = zeros(p,iter_max);
Vmax ? ? ? = 1;
V ? ? ? ? ?= Vmax*(2*rand(p,N)-1);
e ? ? ? ? ?= idinput(Len,'rgs',[0 1],[-var var]); ?% 高斯白噪聲,均值為0,方差為var
%定義輸入輸出
load ? data1.mat
clear ?u alpha v f1 f2 f3 h1 h2 h1pr h2pr
load ? result.mat
clear ?Xgbest_fig p_best pa_best pb_best Z1_best Z2_best e1_best e2_best Xgbest_fig
for t=1:Len
? ? y0(t) = y(t) + e(t);
end
iter=0;
while iter<iter_max
? ? iter=iter+1;%進(jìn)行迭代
? ? iter
? ? for i=1:N
? ? ? ? for t = 3:Len
? ? ? ? ? ? a1 ? ? ? ? = ? X(1,i);
? ? ? ? ? ? a2 ? ? ? ? = ? X(2,i);
? ? ? ? ? ? b1 ? ? ? ? = ? X(3,i); ? ? ? ? ??
? ? ? ? ? ? %y(t)
? ? ? ? ? ? ys(t) ? ? ?= ? -a1*ys(t-1) - a2*ys(t-2) + vs(t-1) + b1*vs(t-2); ? ? ? ? ? ?
? ? ? ? end
? ? ? ? J=1/(1+(ys-y0)*(ys-y0)');
? ? ? ? if J>fpbest(i)
? ? ? ? ? ? fpbest(i) ? = J;
? ? ? ? ? ? Xpbest(:,i) = X(:,i);
? ? ? ? end?
? ? end
? ? [fitnessmax,index]=max(fpbest);
? ? if fitnessmax>fgbest
? ? ? ? fgbest=fitnessmax;
? ? ? ? Xgbest=X(:,index);
? ? end
? ? for i=1:N
? ? ? ? r1 ? = rand;?
? ? ? ? r2 ? = rand;
? ? ? ? fai1 = C1*r1;
? ? ? ? fai2 = C2*r2; ?
? ? ? ? % 速度更新
? ? ? ? V(:,i) = w(iter) * V(:,i) +fai1 *( Xpbest(:,i) - X(:,i) ) + fai2 * ( Xgbest(:,1) - X(:,i) );
? ? ? ? % 若速度超過限定值,則讓其等于邊界值
? ? ? ? index ?= find(abs(V(:,i))>Vmax);
? ? ? ? if(any(index))
? ? ? ? ? ? V(index,i)=V(index,i)./abs(V(index,i)).*Vmax;
? ? ? ? end
? ? ? ? %位置更新
? ? ? ? X(:,i)=X(:,i)+V(:,i);
? ? end
? ? fgbest_fig(iter) ? = fgbest;%種群最佳適應(yīng)度值
? ? Xgbest_fig(:,iter) = Xgbest;%種群最佳位置
end
figure;
plot(1:iter_max,fgbest_fig,'r-*');
%參數(shù)優(yōu)化過程曲線
figure
plot(1:iter_max,Xgbest_fig(1,:),'r-.','LineWidth',2);
hold on?
plot(1:iter_max,Xgbest_fig(2,:),'b-.','LineWidth',2);
hold on?
plot(1:iter_max,Xgbest_fig(3,:),'m-.','LineWidth',2);
hold on?
legend('a1 PSO','a2 PSO','b1 PSO');
plot(1:iter_max,a1,'k');
hold on
plot(1:iter_max,a2,'k');
hold on
plot(1:iter_max,b1,'k');
hold off
disp(Xgbest)
a1_best ? = ? Xgbest(1);
a2_best ? = ? Xgbest(2);
b1_best ? = ? Xgbest(3); ??
figure;
subplot(5,2,8);
plot(1:iter_max,Xgbest_fig(1,:),'r-.','LineWidth',2);
hold on?
plot(1:iter_max,a1,'k');
hold off
xlabel('迭代次數(shù)');
ylabel('a1')
subplot(5,2,9);
plot(1:iter_max,Xgbest_fig(2,:),'r-.','LineWidth',2);
hold on?
plot(1:iter_max,a2,'k');
hold off
xlabel('迭代次數(shù)');
ylabel('a2')
subplot(5,2,10);
plot(1:iter_max,Xgbest_fig(3,:),'r-.','LineWidth',2);
hold on?
plot(1:iter_max,b1,'k');
hold off
xlabel('迭代次數(shù)');
ylabel('b1')
load ? result.mat
subplot(5,2,1);
plot(1:iter_max,Xgbest_fig(1,:),'r-.','LineWidth',2);
hold on?
p ? = ?2;
plot(1:iter_max,p,'k');
hold off
xlabel('迭代次數(shù)');
ylabel('p');
subplot(5,2,2);
plot(1:iter_max,Xgbest_fig(2,:),'r-.','LineWidth',2);
hold on?
pa ?= ?0.5;
plot(1:iter_max,pa,'k');
hold off
xlabel('迭代次數(shù)');
ylabel('pa')
subplot(5,2,3);
plot(1:iter_max,Xgbest_fig(3,:),'r-.','LineWidth',2);
hold on?
pb ?= ?1;
plot(1:iter_max,pb,'k');
hold off
xlabel('迭代次數(shù)');
ylabel('pb')
subplot(5,2,4);
plot(1:iter_max,Xgbest_fig(4,:),'r-.','LineWidth',2);
hold on?
Z1 ?= ?1.2;
plot(1:iter_max,Z1,'k');
hold off
xlabel('迭代次數(shù)');
ylabel('Z1')
subplot(5,2,5);
plot(1:iter_max,Xgbest_fig(5,:),'r-.','LineWidth',2);
hold on?
Z2 ?= -1;
plot(1:iter_max,Z2,'k');
hold off
xlabel('迭代次數(shù)');
ylabel('Z2')
subplot(5,2,6);
plot(1:iter_max,Xgbest_fig(6,:),'r-.','LineWidth',2);
hold on?
e1 ?= ?1.5;
plot(1:iter_max,e1,'k');
hold off
xlabel('迭代次數(shù)');
ylabel('e1')
subplot(5,2,7);
plot(1:iter_max,Xgbest_fig(7,:),'r-.','LineWidth',2);
hold on?
e2 ?= -1.2;
plot(1:iter_max,e2,'k');
hold off
xlabel('迭代次數(shù)');
ylabel('e2')
A27-01
總結(jié)
以上是生活随笔為你收集整理的在Hammerstein非线性模型中,基于PSO的参数辨识系统的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 通过MATLAB读取mnist数据库
- 下一篇: 基于EM参数估计的SAGE算法的MATL