⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mysvregress.m

📁 本程序是基于船舶电力回归的SVM程序
💻 M
字号:
clc;clear ;
global p1 p2; 
p1=0.3,c=150,e=0.01
% 系统随机信号产生
u=20*rand(1,100)-10;
t=20*rand(1,100)-10;
for k=1:100
    u(k+100)=t(k);
end
%作输入信号图形和未知系统输出图形
h1=figure;
for n=1:200
    k=1:200;
    subplot(2,1,1);
    plot(k,u(k),'g');
    ylabel('u(k)');title('input rand data');
    hold on
    subplot(2,1,2);
    for t=2:199
    y(1)=0;y(2)=0;
    y(t+1)=y(t).*y(t-1).*(y(t)+1.5)./(y(t).^2+y(t-1).^2+1)+u(t);
end
    plot(k,y(k),'r');
    ylabel('y(k+1)'),title('output of the noknown sysytem')
end
%SVM的训练
v=zeros(3,100);v(2,1)=0; v(1,1)=0;%v(3,2)=0;v(1,2)=u(1);v(3,1)=0,v(2,2)=0;
%v(1,99)=u(99),v(1,100)=u(100);
for i=3:100;
    v(1,i-1)=u(i-1);
    v(2,i-1)=y(i-1);
    v(3,i-1)=y(i-2);
     s(i)=y(i)';
     s(1)=y(1);s(2)=y(2);
end
ker='rbf';X=v';Y=s'; %Y=v(3,:)';
clear n;clear t;
% c=150*ones(size(X,1),1);
[nsv,beta,bias]=svr(X,Y,ker,c,'einsensitive',e);
% SVM的测试
h2=figure;
for i=2:101
    r(1,i-1)=u(99+i);
    r(2,i-1)=y(i+99);
    r(3,i-1)=y(98+i);%r(1,100)=u(200),r(2,100)=0,r(3,100)=y(200);
end
tstX=r';trnX=v';
tstY=svroutput(trnX,tstX,ker,beta,bias);
for n=1:100
    t=1:100;
    subplot(2,1,1);
    %subplot(2,1,1);
    plot(t,y(t+100)','b',t,tstY(t),'r',t,tstY(t),'k+')
    ylabel('trnY and tstY')
    legend('the actual line','the prediction line','the prediction values')  
    title ('the actual and prediction values')
end
subplot(2,1,2);
%svrplot(X,Y,ker,beta,bias,0.01);
%输出误差函数图形
for n=1:100
    t=1:100 ;
    error(t)=y(t+100)'-tstY(t);
end
plot(t,error,'m');
ylabel('error');
title ('error=actul-prediction')
hold on
tf=find(abs(error)>0.2);
plot(tf,error(tf),'k*')
legend('abs(error)<0.2 ','the fault data',2);
num=length(tf);
fprintf('the fault data number: %d (%3.1f%%)\n',num,100*num/max(t));
%非线性系统辨识(训练数据的再输入)
h3=figure;
trnY=svroutput(trnX,trnX,ker,beta,bias);
for n=1:100
    t=1:100;
    subplot(2,1,1);
    plot(t,y(t)','b',t,trnY(t),'r',t,trnY(t),'k+')
    ylabel('y and trnY')
    legend('the actual line','the prediction line','the prediction values')  
    title ('the actual and prediction values')
end
%输出误差函数图形(真实训练数据和SVM辨识数据之间的误差)
subplot(2,1,2)
for n=1:95
    w=1:95 ;
    error2(w)=y(w)'-trnY(w);
end
plot(w,error2,'m');
ylabel('error2');
title ('error2=actul-estemt')

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -