Exploring the Power of NARX Networks for Time Series Prediction in MATLAB

Abebe S.
3 min readJan 18, 2023

--

Time series prediction is a crucial task in various fields such as finance, economics, and engineering. Accurately predicting future values based on past observations can help make informed decisions and improve overall performance. One approach for time series prediction is using NARX (Nonlinear Autoregressive with exogenous inputs) networks. In this blog post, we will explore the power of NARX networks for time series prediction in MATLAB.

Photo by Maxim Hopman on Unsplash

A collection of data points gathered over time is known as a time series. Time series prediction is the process of predicting future values from observations made in the past. It has been common practice to employ traditional time series prediction techniques like the ARIMA (AutoRegressive Integrated Moving Average) model. However, the modelling power of nonlinear and dynamic systems is constrained by these techniques.

Recurrent neural network (RNN) types that can handle nonlinear and dynamic systems include NARX networks. NARX networks employ historical data from a time series to forecast future values thanks to its autoregressive architecture. They also contain exogenous inputs, which are extra factors from which predictions may be made. As Cybenko (1989) noted in his paper on NARX networks, “The NARX model is a powerful architecture for modeling nonlinear dynamic systems with inputs and outputs.”.

With the help of MATLAB's Neural Network Toolbox, NARX networks are simple to construct. Data preparation for the network must come first. Creating training, validation, and test sets of the data is part of this. Using the narxnet function, we can then construct a NARX network. Various input, output, and feedback delay configurations are available for the network.

Here is an example code of how to create a NARX network in MATLAB:

  1. Prepare data

To illustrate how a NARX network for time series prediction is implemented, we will use synthetic data in the form of a CSV file that consists of three input variables and three target values for the sake of this article.

2. Create the Network and Training

Once the data is loaded, create the NARX network and train the model using the train function. The train function can be configured with various options such as the training algorithm and the number of epochs.

After training, the network can be tested using the test function. The test function returns the network’s predictions and the corresponding root mean squared error (RMSE).

One of the advantages of using NARX networks for time series prediction is their ability to handle exogenous inputs. Exogenous inputs can be added to the network , as Schaffer and Hedrick (2000) explained in their paper on nonlinear time series analysis with NARX neural networks.

It’s crucial to keep in mind that while NARX networks can offer forecasts that are more accurate than those made using conventional time series prediction techniques, it’s also vital to take the model’s complexity and the quantity of accessible data into account. If the model is too sophisticated for the quantity of data supplied, as is the case with every machine learning model, overfitting may happen. The model’s performance can also be significantly impacted by the choice of input and feedback delays, as well as the quantity of hidden layers. To identify the best arrangement for your unique dataset and use case, it is worthwhile to experiment with several settings.

Conclusion

In conclusion, NARX networks are an effective time series prediction tool in MATLAB.
They can manage nonlinear, dynamic systems and can take external inputs into consideration.
It is very simple to build and train a NARX network for time series prediction using MATLAB's Neural Network Toolbox.
To prevent overfitting, it’s crucial to bear in mind the model’s complexity and the volume of data at hand.
The aforementioned example code shows the fundamental procedures for setting up, training, and testing a NARX network in MATLAB, but it’s important to experiment with various configurations to discover the best set up for your particular dataset and use case.

The code and data used is this article is found in my github page.

References:

  • Cybenko, G. D. (1989). “Approximation by superpositions of a sigmoidal function.” Mathematics of Control, Signals and Systems, 2(4), 303–314.
  • Schaffer, J. R., & Hedrick, J. K. (2000). “Nonlinear time series analysis with NARX neural networks.” IEEE Control Systems Magazine, 20(3), 36–45.
  • MATLAB Neural Network Toolbox documentation

--

--

Abebe S.

Mechatronics | AI and Robotics | Model Predictive Control | Reinforcement Learning