www.pudn.com > kicILC-control.rar > svm_feedback_x2_final.asv, change:2013-04-18,size:4214b


%global uk duk 
%%产生输入数据 
clear; 
pr=idinput(21,'prbs',[0 1],[0 2]); 
for j=1:60 
t1=(0:0.05:1)'; 
ut=[]; 
ut=[ut,i]; 
for i=1:length(t1) 
ut(i,1)=t1(i,1); 
if i<=12, 
ut(i,2)=0.97; 
else 
    ut(i,2)=0.92; 
end 
us(j,i)=ut(i,2)+0.043*(-1+2*rand(1,1)); 
 
%us(j,i)=ut(i,2)+0.043*(-1+pr(i)); 
%us(j,i)=ut(i,2)+0.058*rand(1,1); 
%uk(i,1)=ut(i,2); 
uk1(i,1)=us(1,i); 
uk2(i,1)=us(1,i); 
duk1(i,1)=0; 
duk2(i,1)=0; 
ut(i,2)=us(j,i); 
end 
%us(j,:)=ut(:,2)+normrnd(0,0.3,21,1); 
%ut(:,2)=us(j,:); 
u=us(:,1:21); 
 
%%将输入数据输入系统,产生训练数据60组,30组训练,30组测试 
opts=simset('OutputVariables','xy'); 
[t,x,y]=sim('nonlinear1',[0:0.05:1],opts,ut); 
x1(j,1)=x(21,1); 
x2(j,1)=x(21,2); 
end 
X=u(1:30,:);%训练集 
Y1=x1(1:30); 
 
%%支持向量机训练、测试 
gam = 1547; 
p=1; 
d=0.00010; 
type = 'function estimation'; 
%[gam1,p1] = tunelssvm({X,Y1,'f',10,[1,1],'poly_kernel'},[1 0.1;100 10],'gridsearch',{},'leaveoneout_lssvm'); 
%[alpha1,b1] = trainlssvm({X,Y1,type,gam1,p1,'poly_kernel','preprocess'}); 
 
Xt=u(31:60,:);%测试集 
%Yt1 = simlssvm({X,Y1,type,gam1,p1,'poly_kernel','preprocess'},{alpha1,b1},Xt); 
Y2=x2(1:30); 
%[Y,I]=min(Y2); 
%uk1=u(I,:)'; 
%uk2=uk1; 
%[gam2,p2] = tunelssvm({X,Y2,'f',10,[1,1],'poly_kernel'},[0.1 0.01;100 1],'gridsearch',{},'leaveoneout_lssvm'); 
[alpha2,b2] = trainlssvm({X,Y2,type,gam,[d,p],'poly_kernel','original'}); 
Yt2 = simlssvm({X,Y2,type,gam,[d,p],'poly_kernel','original'},{alpha2,b2},Xt); 
figure(1) 
%subplot(2,1,1) 
%plot(1:30,x1(31:60),'*',1:30,Yt1(1:30),'--'); 
%xlabel(' SVM training samples','FontSize',11); 
%ylabel('X1(tf)','FontSize',11); 
%legend('True Outputs','Estimated Outputs'); 
%subplot(2,1,2) 
plot(1:30,x2(31:60),'*',1:30,Yt2(1:30),'--'); 
xlabel(' SVM training samples','FontSize',11); 
ylabel('X2(tf)','FontSize',11); 
legend('True Outputs','Estimated Outputs'); 
 
%%迭代学习控制仿真 
G1=zeros(21,1); 
G2=zeros(21,1); 
v=0.01*ones(21,1); 
R=diag(v,0); 
Q=[1000]; 
%Yk=[1 0.922415]';%0.76 0.7875 
Yd=[0.606]'; 
%Ek=[0 0 0]'; 
%Ye(:,1)=Yk+Ek; 
%Index(1)=(Yd-Yk-Ek)'*Q*(Yd-Yk-Ek); 
for i=1:241 
    Yd1(i)=Yd; 
    uk1=uk1+duk1; 
    uk2=uk2+duk2; 
    uin1=[t1,uk1]; 
    uin2=[t1,uk2]; 
    if i<150, 
    [t_1,x_1,y_1]=sim('nonlinear1',[0:0.05:1],opts,uin1); 
    [t_2,x_2,y_2]=sim('nonlinear1',[0:0.05:1],opts,uin2); 
    else 
        [t_1,x_1,y_1]=sim('nonlinear2',[0:0.05:1],opts,uin1); 
        [t_2,x_2,y_2]=sim('nonlinear2',[0:0.05:1],opts,uin2); 
    end 
    Ye1(1,i)=x_1(21,2)'; 
    Ye2(1,i)=x_2(21,2)'; 
    Ek1(1,i)=Yd-x_1(21,2)';%+0.05*randn(2,1); 
    Ek2(1,i)=Yd-x_2(21,2)'; 
    Index1(i)=norm(Ek1(1,i),2);%Ek(:,i)'*Q*Ek(:,i); 
    Index2(i)=norm(Ek2(1,i),2); 
    for j=1:30 
    %G(:,1)=G(:,1)+(p1(1,1)*alpha1(i)*u(j,:))'*(u(j,:)*uk+1)^(p1(1,1)-1); 
    G1(:,1)=G1(:,1)+(d*alpha2(j)*u(j,:))'*(u(j,:)*uk1+1)^(d-1); 
    G2(:,1)=G2(:,1)+(d*alpha2(j)*u(j,:))'*(u(j,:)*uk2+1)^(d-1); 
    end 
    duk1=(inv(G1*Q*G1'+R))*G1*Q*(Yd-Ye1(1,i)); 
    if i>1, 
    duk2=(inv(G2*Q*G2'+R))*G2*Q*(Yd-Yk(1,i-1)-0.2*ek(i-1));%3e-6 
    Yk(1,i)=Yk(1,i-1)+G2'*duk2; 
    ek(i)=(sum(Ye2(1:i))-sum(Yk(1:i)))/i; 
    else 
        Yk(1,1)=Ye2(1,1); 
        ek(1)=Yd-Yk(1,1); 
        duk2=(inv(G2*Q*G2'+R))*G2*Q*(Yd-Yk(1,1)); 
    end 
end 
figure(2) 
plot(1:10:241,Index1(1:10:241),'o'); 
hold on; 
plot(1:10:241,Index1(1:10:241),'-'); 
hold on; 
plot(1:10:241,Index2(1:10:241),'s'); 
hold on; 
plot(1:10:241,Index2(1:10:241),'-.'); 
xlabel(' Iteration Number','FontSize',11); 
ylabel('Sum of Squared Control Errors','FontSize',11); 
hold off; 
figure(3) 
%subplot(2,1,1) 
%plot(1:241,Ye(1,:),'o'); 
%hold on; 
%plot(1:241,Ye(1,:),'-'); 
%plot(1:11,Yd(1,1),'--'); 
%xlabel(' Iteration Number','FontSize',11); 
%ylabel('X1(tf)','FontSize',11); 
%hold off; 
%subplot(2,1,2) 
plot(1:10:241,Ye1(1:10:241),'o'); 
hold on; 
plot(1:10:241,Ye1(1:10:241),'-'); 
hold on; 
plot(1:10:241,Yd1(1:10:241),'--'); 
xlabel(' Iteration Number','FontSize',11); 
ylabel('X2(tf)','FontSize',11); 
hold off; 
figure(4) 
plot(1:10:241,Ye2(1:10:241),'s'); 
hold on; 
plot(1:10:241,Ye2(1:10:241),'-.'); 
hold on; 
plot(1:10:241,Yd1(1:10:241),'--'); 
xlabel(' Iteration Number','FontSize',11); 
ylabel('X2(tf)','FontSize',11); 
%figure(4) 
%plot(t1,uk1); 
hold off;