SysIdentPy: A Python package for modeling nonlinear dynamical data | by Wilson Rocha | Towards Data Science

Mathematical models plays a key role and science and engineering. We see researchers and data-driven professionals using many different models to analyse and predict load demand, cash demand, stock exchange data, biomedical data, chemical process and many more.
When the data is a result of a dynamical system, autoregressive models are frequently a safe choice for further tests. In this respect, ARMAX (Autoregressive models with Moving Average and Exogenous Input) models and its variants (ARX, ARMA, ARIMA, etc.) are one of the most used model class. However, the aforementioned models works well for linear data because they are linear models. And this is where SysIdentPy comes in: a python package for nonlinear dynamical systems.
Systems are inherently nonlinear. One can argue that in most cases a linear approximation works great and you don’t need a nonlinear model... and I couldn’t agree more. However, what if you want to obtain a dynamic nonlinear model? Well, you can use SysIdentPy for that!
SysIdentPy is an open source package for System Identification using NARMAX models (Nonlinear Autoregressive models with Moving Average and Exogenous Input) developed by me with the collaboration of my friends Luan Pascoal, Samuel Oliveira, and Samir Martins.
NARMAX models are a generalization of ARMAX family. However, NARMAX model are not a simple extension of ARMAX models and are capable to describe many different and complex nonlinear systems.
SysIdentPy aims to be a friendly user and powerful tool. With a few lines of code you can build a NARMAX model. The code below shows a simple example of how to use the library: loading sample data, setting the model parameters, fitting and predicting the model, show model details and plot the results with two residues tests. Pretty straightforward, right?
from sysidentpy.polynomial_basis import PolynomialNarmaxfrom sysidentpy.metrics import root_relative_squared_errorfrom sysidentpy.utils.generate_data import get_miso_data, get_siso_datax_train, x_valid, y_train, y_valid = get_siso_data(n=1000,                                                   colored_noise=False,                                                   sigma=0.001,                                                   train_percentage=90)model = PolynomialNarmax(non_degree=2,                         order_selection=True,                         n_info_values=10,                         extended_least_squares=False,                         ylag=2, xlag=2,                         info_criteria='aic',                         estimator='least_squares',                         )model.fit(x_train, y_train)yhat = model.predict(x_valid, y_valid)rrse = root_relative_squared_error(y_valid, yhat)print(rrse)results = pd.DataFrame(model.results(err_precision=8,                                     dtype='dec'),                       columns=['Regressors', 'Parameters', 'ERR'])print(results)ee, ex, extras, lam = model.residuals(x_valid, y_valid, yhat)model.plot_result(y_valid, yhat, ee, ex)
You can install SysIdentPy using
pip install sysidentpy
So far we have implemented several tradicional algorithms concerning NARMAX models. Some of those methods are listed here:
Forward Regression Orthogonal Least Squares (FROLS)
Error Reduction Ratio
Householder reflection
Extended Least Squares FROLS
Ordinary Least Squares
Total Least Squares
Recursive Least Squares
Least Mean Squares (and many variants)
Akaike Information Criteria
Bayesian Information Criteria
Final Prediction Error
and more
The reader is referred to official documentation and repository for further details:
wilsonrljr.github.io
github.com
Many additional features are already in progress. It will be a pleasure to have the collaboration of all of you to make the library more and more complete.
Feel free to contact me on Linkedin or Discord (wilsonrljr#3777). Also, we have a Discord server to talk about SysIdentpy (questions, contributions and so on). You can join us on Discord here.