预测序列模型方程:
该预测模型常用于神经网络的训练:
1. 输入输出数据及处理
load mgdata.dat
time = mgdata(:,1);
x = mgdata(:, 2);
figure(1)
plot(time,x)
title('Mackey-Glass Chaotic Time Series')
xlabel('Time (sec)')
ylabel('x(t)')
%输入输出数据处理
for t = 118:1117
Data(t-117,:) = [x(t-18) x(t-12) x(t-6) x(t) x(t+6)];
end
trnData = Data(1:500,:);
chkData = Data(501:end,:);
2. genfis生成初始系统
% 生成初始Sugeno FIS系统
fis = genfis(trnData(:,1:end-1),trnData(:,end),genfisOptions('GridPartition'));
% genfis 默认每个输入输出量为 2 个generalized bell membership functions 隶属函数,均匀分布
figure
subplot(2,2,1)
plotmf(fis,'input',1)
subplot(2,2,2)
plotmf(fis,'input',2)
subplot(2,2,3)
plotmf(fis,'input',3)
subplot(2,2,4)
plotmf(fis,'input',4)
%**上述生成的初始系统应对16 条规则;
%**4输入1输出
%**待估计参数为104个
%**训练数据为500个
3. ANFIS系统配置及训练
% ANFIS训练
options = anfisOptions('InitialFIS',fis,'ValidationData',chkData);
[fis1,error1,ss,fis2,error2] = anfis(trnData,options);
%**fis1最佳拟合结构;fis2最佳预测结构
训练后系统隶属函数:
% 训练后隶属函数
figure
subplot(2,2,1)
plotmf(fis2,'input',1)
subplot(2,2,2)
plotmf(fis2,'input',2)
subplot(2,2,3)
plotmf(fis2,'input',3)
subplot(2,2,4)
plotmf(fis2,'input',4)
4. 训练效果及拟合误差
% 训练及预测误差曲线
figure
plot([error1 error2])
hold on
plot([error1 error2],'o')
legend('Training error','Checking error')
xlabel('Epochs')
ylabel('Root Mean Squared Error')
title('Error Curves')
% ANFIS系统拟合效果
anfis_output = evalfis(fis2,[trnData(:,1:4); chkData(:,1:4)]);
figure
index = 125:1124;
plot(time(index),[x(index) anfis_output])
xlabel('Time (sec)')
title('MG Time Series and ANFIS Prediction')
% 预测误差
diff = x(index) - anfis_output;
plot(time(index),diff)
xlabel('Time (sec)')
title('Prediction Errors')