Machine Learning

Time-Series Prediction using GMDH in MATLAB

Get the code
Comments

Predict a time series with GMDH in MATLAB using lagged inputs, polynomial neurons, validation-based selection, and a global ice-volume example.

Illustration for Time-Series Prediction using GMDH in MATLAB
On this page

Time-series prediction can be treated as a special case of nonlinear regression and function approximation. So nonlinear regression methods, such as Artificial Neural Networks and the Group Method of Data Handling (GMDH), can be applied to time-series forecasting.

This post shares MATLAB code for time-series prediction using GMDH. It is applied to the modeling and prediction of a global ice volume time series.

The MATLAB implementation of GMDH was shared earlier on Yarpiz, on this page. The same code is used here for time-series modeling and forecasting. If you know MATLAB, you should find it easy to use the code in your research and projects.

From a time series to a regression problem

A time series is a sequence of values x1,x2,…,xTx_1, x_2, \dots, x_T measured at equal time steps. A one step ahead prediction model estimates the next value from a few past values:

x^t=f(xt−1,xt−2,…,xt−d)\hat{x}_t = f(x_{t-1}, x_{t-2}, \dots, x_{t-d})

The past values are called lagged inputs, or delays. Each time step tt with t>dt > d gives one training sample: the inputs are the dd previous values and the target is xtx_t. After this step, any regression method can learn ff. Here, ff is a GMDH network.

In the code, the function CreateTimeSeriesData(x, Delays) builds these samples. With Delays = [1 2 3 4 5], each sample has five inputs, xt−1x_{t-1} to xt−5x_{t-5}.

The data

The file global_ice_volume.mat holds one time series of 219 values of the global ice volume, which covers the last 440,000 years. With five delays, it gives 214 samples. The same data is used in the post Time-Series Prediction using ANFIS in MATLAB, so the two methods can be compared on the same problem.

How GMDH builds the model

GMDH builds a network of neurons, each of which fits a quadratic polynomial of two inputs by least squares. In each layer, it tries every pair of inputs, ranks the neurons by their error on a validation part of the training data, keeps the best ones, and passes their outputs to the next layer. The GMDH post explains the method in detail.

Parameters in the code

The parameters are set in main.m:

Parameter Meaning Value
Delays Lags used as inputs [1 2 3 4 5]
pTrain Share of the samples used for training (the rest is the test set) 0.7
params.MaxLayerNeurons Maximum number of neurons in a layer 25
params.MaxLayers Maximum number of layers 5
params.alpha Selection pressure 0
params.pTrain Share of the training samples used to fit the neurons (the rest is used for validation) 0.7

With alpha = 0, the selection threshold equals the error of the worst neuron, so no neuron is removed by the threshold. Only the limit of 25 neurons per layer prunes the network. A larger alpha gives a stronger selection.

This copy of GMDH.m builds layers until a layer has one neuron or the maximum number of layers is reached. It does not include the early stop of the GMDH post, which ends training when the validation error of a new layer gets worse.

How to run the code

Open the folder in MATLAB and run main.m. The script:

  1. loads the series and creates the lagged samples,
  2. splits the samples in time order: the first 70% for training and the last 30% for testing in the stored sequence,
  3. trains the GMDH network on the training samples,
  4. predicts all samples with ApplyGMDH,
  5. plots the targets and outputs for the training, test and full data, and also draws regression plots when the plotregression function is available.

To use your own series, replace x with a row vector of your data. You can also change Delays, for example to [1 2 3] for fewer inputs.

Check the result

Confirm which end of the stored series is earlier in time and preserve that chronology in any train-test split. The internal fitting and validation split must also respect the forecasting question. The default lagged samples use observed past values for one-step prediction, which differs from recursive multi-step forecasting. Compare held-out errors with a persistence baseline and with ANFIS using the same splits and delays. This copy has different stopping behavior from the standalone GMDH package, so do not assume the two downloads are identical.

Applications

The same approach applies to many forecasting tasks, such as demand and load forecasting, financial and economic series, and environmental and hydrological data.

Downloads

How to cite

If you use this code or tutorial in your work, articles or publications, please cite it.

Plain text
Mostapha Kalami Heris, Time-Series Prediction using GMDH in MATLAB (YPML120), Yarpiz, 2015. https://yarpiz.com/time-series-prediction-using-gmdh-ypml120
BibTeX
@misc{yarpiz-ypml120,
  author = {{Mostapha Kalami Heris}},
  title = {{Time-Series Prediction using GMDH in MATLAB}},
  howpublished = {Yarpiz},
  year = {2015},
  note = {Code YPML120},
  url = {https://yarpiz.com/time-series-prediction-using-gmdh-ypml120}
}

Comments

Sign in or create a free account to join the discussion. No password needed.