【转载】Chaotic Time-Series Prediction

 原文地址:https://cn.mathworks.com/help/fuzzy/examples/chaotic-time-series-prediction.html?requestedDomain=www.mathworks.com 

This example shows how to do chaotic time series prediction using ANFIS.

Time Series Data

The data is generated from the Mackey-Glass time-delay differential equation which is defined by

dx(t)/dt = 0.2x(t-tau)/(1+x(t-tau)^10) - 0.1x(t)

When x(0) = 1.2 and tau = 17, we have a non-periodic and non-convergent time series that is very sensitive to initial conditions. (We assume x(t) = 0 when t < 0.)

load mgdata.dat
a = mgdata;
time = a(:, 1);
x_t = a(:, 2);
plot(time, x_t);
xlabel('Time (sec)','fontsize',10); ylabel('x(t)','fontsize',10);
title('Mackey-Glass Chaotic Time Series','fontsize',10);

Preprocessing the Data

Now we want to build an ANFIS that can predict x(t+6) from the past values of this time series, that is, x(t-18), x(t-12), x(t-6), and x(t). Therefore the training data format is

[x(t-18), x(t-12), x(t-6), x(t); x(t+6]

From t = 118 to 1117, we collect 1000 data pairs of the above format. The first 500 are used for training while the others are used for checking. The plot shows the segment of the time series where data pairs were extracted from. The first 100 data points are ignored to avoid the transient portion of the data.

trn_data = zeros(500, 5);
chk_data = zeros(500, 5);

% prepare training data
trn_data(:, 1) = x_t(101:600);
trn_data(:, 2) = x_t(107:606);
trn_data(:, 3) = x_t(113:612);
trn_data(:, 4) = x_t(119:618);
trn_data(:, 5) = x_t(125:624);

% prepare checking data
chk_data(:, 1) = x_t(601:1100);
chk_data(:, 2) = x_t(607:1106);
chk_data(:, 3) = x_t(613:1112);
chk_data(:, 4) = x_t(619:1118);
chk_data(:, 5) = x_t(625:1124);

index = 119:1118; % ts starts with t = 0
plot(time(index), x_t(index));
xlabel('Time (sec)','fontsize',10); ylabel('x(t)','fontsize',10);
title('Mackey-Glass Chaotic Time Series','fontsize',10);

Building the ANFIS Model

We use GENFIS1 to generate an initial FIS matrix from training data. The command is quite simple since default values for MF number (2) and MF type ('gbellmf') are used:

fismat = genfis1(trn_data);

% The initial MFs for training are shown in the plots.
for input_index=1:4,
    subplot(2,2,input_index)
    [x,y]=plotmf(fismat,'input',input_index);
    plot(x,y)
    axis([-inf inf 0 1.2]);
    xlabel(['Input ' int2str(input_index)],'fontsize',10);
end

There are 2^4 = 16 rules in the generated FIS matrix and the number of fitting parameters is 108, including 24 nonlinear parameters and 80 linear parameters. This is a proper balance between number of fitting parameters and number of training data (500). The ANFIS command looks like this:

[trn_fismat,trn_error] = anfis(trn_data, fismat,[],[],chk_data)

To save time, we will load the training results directly.

After ten epochs of training, the final MFs are shown in the plots. Note that these MFs after training do not change drastically. Obviously most of the fitting is done by the linear parameters while the nonlinear parameters are mostly for fine- tuning for further improvement.

% load training results
load mganfis

% plot final MF's on x, y, z, u
for input_index=1:4,
    subplot(2,2,input_index)
    [x,y]=plotmf(trn_fismat,'input',input_index);
    plot(x,y)
    axis([-inf inf 0 1.2]);
    xlabel(['Input ' int2str(input_index)],'fontsize',10);
end

Error Curves

This plot displays error curves for both training and checking data. Note that the training error is higher than the checking error. This phenomenon is not uncommon in ANFIS learning or nonlinear regression in general; it could indicate that the training process is not close to finished yet.

% error curves plot
close all;
epoch_n = 10;
plot([trn_error chk_error]);
hold on; plot([trn_error chk_error], 'o'); hold off;
xlabel('Epochs','fontsize',10);
ylabel('RMSE (Root Mean Squared Error)','fontsize',10);
title('Error Curves','fontsize',10);

Comparison

This plot shows the original time series and the one predicted by ANFIS. The difference is so tiny that it is impossible to tell one from another by eye inspection. That is why you probably see only the ANFIS prediction curve. The prediction errors must be viewed on another scale.

input = [trn_data(:, 1:4); chk_data(:, 1:4)];
anfis_output = evalfis(input, trn_fismat);
index = 125:1124;
plot(time(index), [x_t(index) anfis_output]);
xlabel('Time (sec)','fontsize',10);

Prediction Errors of ANFIS

Prediction error of ANFIS is shown here. Note that the scale is about a hundredth of the scale of the previous plot. Remember that we have only 10 epochs of training in this case; better performance is expected if we have extensive training.

diff = x_t(index)-anfis_output;
plot(time(index), diff);
xlabel('Time (sec)','fontsize',10);
title('ANFIS Prediction Errors','fontsize',10);

转载于:https://www.cnblogs.com/dyl-HelloWorld/p/6058009.html

感谢陆老师,这一版主要是实现了开源,非常好的学习资料。 混沌时间序列分析与预测工具箱 Version3.0 chaotic time series analysis and prediction matlab toolbox - trial version 3.0 (1)产生混沌时间序列(chaotic time series) Logistic映射 - \ChaosAttractors\Main_Logistic.m Henon映射 - \ChaosAttractors\Main_Henon.m Lorenz吸引子 - \ChaosAttractors\Main_Lorenz.m Duffing吸引子 - \ChaosAttractors\Main_Duffing.m Duffing2吸引子 - \ChaosAttractors\Main_Duffing2.m Rossler吸引子 - \ChaosAttractors\Main_Rossler.m Chens吸引子 - \ChaosAttractors\Main_Chens.m Ikeda吸引子 - \ChaosAttractors\Main_Ikeda.m MackeyGLass序列 - \ChaosAttractors\Main_MackeyGLass.m Quadratic序列 - \ChaosAttractors\Main_Quadratic.m (2)求时延(delay time) 自相关法 - \DelayTime_Others\Main_AutoCorrelation.m 平均位移法 - \DelayTime_Others\Main_AverageDisplacement.m (去偏)复自相关法 - \DelayTime_Others\Main_ComplexAutoCorrelation.m 互信息法 - \DelayTime_MutualInformation\Main_Mutual_Information.m (3)求嵌入维(embedding dimension) 假近邻法 - \EmbeddingDimension_FNN\Main_FNN.m (4)同时求时延与嵌入窗(delay time & embedding window) CC方法 - \C-C Method\Main_CC_Method_Luzhenbo.m 改进的CC方法 - \C-C Method Improved\Main_CC_Method_Improved.m (5)求关联维(correlation dimension) GP算法 - \CorrelationDimension_GP\Main_CorrelationDimension_GP.m (6)求K熵(Kolmogorov Entropy) GP算法 - \KolmogorovEntropy_GP\Main_KolmogorovEntropy_GP.m STB算法 - \KolmogorovEntropy_STB\Main_KolmogorovEntropy_STB.m (7)求最大Lyapunov指数(largest Lyapunov exponent) 小数据量法 - \LargestLyapunov_Rosenstein\Main_LargestLyapunov_Rosenstein1.m \LargestLyapunov_Rosenstein\Main_LargestLyapunov_Rosenstein2.m \LargestLyapunov_Rosenstein\Main_LargestLyapunov_Rosenstein3.m (8)求Lyapunov指数谱(Lyapunov exponent spectrum) BBA算法 - \LyapunovSpectrum_BBA\Main_LyapunovSpectrum_BBA1.m \LyapunovSpectrum_BBA\Main_LyapunovSpectrum_BBA2.m (9)求二进制图形的盒子维(box dimension)和广义维(genealized dimension) 覆盖法 - \BoxDimension_2D\Main_BoxDimension_2D.m - \GeneralizedDimension_2D\Main_GeneralizedDimension_2D.m (10)求时间序列的盒子维(box dimension)和广义维(genealized dimension) 覆盖法 - \BoxDimension_TS\Main_BoxDimension_TS.m - \GeneralizedDimension_TS\Main_GeneralizedDimension_TS.m (11)混沌时间序列预测(chaotic time series prediction) RBF神经网络一步预测 - \Prediction_RBF\Main_RBF.m RBF神经网络多步预测 - \Prediction_RBF\Main_RBF_MultiStepPred.m Volterra级数一步预测 - \Prediction_Volterra\Main_Volterra.m Volterra级数多步预测 - \Prediction_Volterra\Main_Volterra_MultiStepPred.m (12)产生替代数据(Surrogate Data) 随机相位法 - \SurrogateData\Main_SurrogateData.m
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值