【转载】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);

时间: 2024-10-13 11:26:01

【转载】Chaotic Time-Series Prediction的相关文章

PP: A dual-stage attention-based recurrent neural network for time series prediction

Problem: time series prediction The nonlinear autoregressive exogenous model: The Nonlinear autoregressive exogenous (NARX) model, which predicts the current value of a time series based upon its previous values as well as the current and past values

Lab 2 MSc: Time Series Prediction with GP

Advanced Aspects of Nature Inspired Search and Optimisation 2019/2020Lab 2 MSc: Time Series Prediction with GPNB! This coursework is only compulsory for MSc students taking the 20cr module.We released a different Lab 2 with an earlier deadline for UG

【转载】先验概率与后验概率,生成模型与判别模型

[注]事情还没有发生,要求这件事情发生的可能性的大小,是先验概率.事情已经发生,要求这件事情发生的原因是由某个因素引起的可能性的大小,是后验概率 Generative Model 与 Discriminative Model [摘要]    - 生成模型(Generative Model) :无穷样本==>概率密度模型 = 产生模型==>预测- 判别模型(Discriminative Model):有限样本==>判别函数 = 预测模型==>预测 [简介] 简单的说,假设o是观察值,

判别式模型和产生式模型 (discriminative model and generative m

最经典的莫过于 Andrew Ng在NIPS2001年有一篇专门比较判别模型和产生式模型的文章: On Discrimitive vs. Generative classifiers: A comparision of logistic regression and naive Bayes (http://robotics.stanford.edu/~ang/papers/nips01-discriminativegenerative.pdf) 转: 判别式模型和产生式模型 (discrimin

朴素贝叶斯分类算法(1)

转自http://blog.csdn.net/lch614730/article/details/17031145 朴素贝叶斯分类算法(Naive Bayesian classification) PS:本文在讲解的时候会用通俗的例子来讲解 本文我们将学习到: (1)什么是朴素贝叶斯? (2)先验概率和条件概率是如何证明的? (3)文本分类的多项式模型和伯努利模型(附加例子说明) (4)垃圾邮件的分类及代码的演示(暂缺以后会补上) (1)什么是朴素贝叶斯(Naive Bayes,以后简称NB)?

(转)Awesome Courses

Awesome Courses  Introduction There is a lot of hidden treasure lying within university pages scattered across the internet. This list is an attempt to bring to light those awesome courses which make their high-quality material i.e. assignments, lect

基于 Keras 用 LSTM 网络做时间序列预测

基于 Keras 用 LSTM 网络做时间序列预测 本文主要参考了 Jason Brownlee 的博文 Time Series Prediction with LSTM Recurrent Neural Networks in Python with Keras 原文使用 python 实现模型,这里是用 R 时间序列预测是一类比较困难的预测问题. 与常见的回归预测模型不同,输入变量之间的"序列依赖性"为时间序列问题增加了复杂度. 一种能够专门用来处理序列依赖性的神经网络被称为 递归

rugarch包与R语言中的garch族模型

来源:http://www.dataguru.cn/article-794-1.html rugarch包是R中用来拟合和检验garch模型的一个包.该包最早在http://rgarch.r-forge.r-project.org上发布,现已发布到CRAN上.简单而言,该包主要包括四个功能: 拟合garch族模型 garch族模型诊断 garch族模型预测 模拟garch序列 拟合序列分布 下面分别说一下. 一.拟合garch族模型 拟合garch族模型分三个步骤:(1)通过ugarchspec

机器学习的8篇文章

Time Series Prediction with LSTM Recurrent Neural Networks in Python with Keras Time series prediction problems are a difficult type of predictive modeling problem. Unlike regression predictive modeling, time series also adds the complexity of a sequ