|
楼主 |
发表于 2007-5-13 15:26
|
显示全部楼层
回复 #2 xjzuo 的帖子
clear all
clc
load Q.txt
for i=1:50
p(i)=mean(Q(i,:));
end
%训练数据
for i=1:30
for j=1:30
P(j,:)=p(j:9+j);
T(j)=p(10+j);
end
end
P=P';
X=p(1,41:50);
%预测数据
for i=1:10
for j=1:10
A(j,:)=p(30+j:39+j);
end
end
%训练网络 {'tansig','logsig'},'trainscg','learngdm'
net=newff(minmax(P),[10,1],{'tansig','logsig'},'trainscg','learngdm'); %建立网络;10为隐层节点数,1为输出节点数,输入节点数不需设置。
net.trainParam.show=10; % 显示训练步长;
net.trainParam.goal=0.001; % 目标误差;
net.trainParam.epochs=2000; % 训练最大步数;
net.trainParam.lr=0.01; % 学习速率;
net=train(net,P,T);
%输出训练后的权值和阈值
iw1=net.IW{1};
b1=net.b{1};
lw2=net.LW{2};
b2=net.b{2};
%仿真预测
out=sim(net,A)
X %实际测得数据
t=1:1:10;
box off;
grid off;
plot(t,out,'b',t,X,'r');%画出二维图形
set(gca,'Xtick',0:1:10,'Ytick',0:.1:1);%设置坐标
title('基于BP网络的设备故障预测');
xlabel('预测次数');
ylabel('预测值');
text(1.5,0.65,'预测曲线(蓝)');
text(1.5,0.6,'实际曲线(红)');
%gtext('预测振动曲线(蓝)与实际测试曲线(红)比较');
%h=legend('预测振动曲线(蓝)与实际测试曲线(红)比较');
%zoom on;
%zoom(0.2); |
|