Sysidentpy
A Python Package For System Identification Using NARMAX Models
Install / Use
/learn @wilsonrljr/SysidentpyREADME
SysIdentPy offers State-of-the-Art techniques to build your NARMAX models, including its variants NARX, NARMA, NAR, NFIR, ARMAX, ARX, ARMA and others. It also includes tons of interesting examples to help you build nonlinear forecasting models using SysIdentPy.
Table of Contents
- What is SysIdentPy?
- How do I install SysIdentPy?
- Features
- Why does SysIdentPy exist?
- How do I use SysIdentPy?
- Examples
- Communication
- Citation
- Inspiration
- Contributors
- Sponsors
Introduction
SysIdentPy is an open-source Python module for System Identification using NARMAX models built on top of numpy and is distributed under the 3-Clause BSD license. SysIdentPy provides an easy-to-use and flexible framework for building Dynamical Nonlinear Models for time series and dynamic systems.
With SysIdentPy, you can:
- Build and customize nonlinear forecasting models.
- Utilize state-of-the-art techniques for model structure selection and parameter estimation.
- Experiment with neural NARX models and other advanced algorithms.
Check our documentation!
For an in depth documentation, check our companion book:
<a href="https://sysidentpy.org/book/0-Preface/"> <img src="https://github.com/wilsonrljr/sysidentpy-data/blob/4085901293ba5ed5674bb2911ef4d1fa20f3438d/book/assets/Nonlinear_System_identification.png?raw=true" alt="Nonlinear System Identification" style="width: 200px; height: auto;" /> </a>How do I install SysIdentPy?
The easiest way to get SysIdentPy running is to install it using pip
pip install sysidentpy
Requirements
SysIdentPy requires:
- Python (>= 3.10)
- NumPy (>= 1.19.2) for numerical algorithms
- Matplotlib >= 3.3.2 for static plotting and visualizations
- Pytorch (>=1.7.1) for building NARX neural networks
- scipy (>= 1.8.0) for numerical and optimization algorithms
The library is compatible with Linux, Windows, and macOS. Some examples may also require additional packages like pandas.
For more details, check our installation guide
What are the main features of SysIdentPy?
| Feature | What is this? | |----------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | NARMAX philosophy | You can build variations of NARMAX models like NARX, NAR, NARMA, NFIR, ARMA, ARX, AR, and others. | | Model Structure Selection | Easy-to-use methods to select the best terms to build your models, including FROLS, MetaMSS, AOLS, UOFR, Entropic Regression, RMSS, and Orthogonal Floating Search (OSF, OIF, OOS/O2S), with several combinations with parameter estimation techniques to select the model terms. | | Basis Function | You can use up to 8 different basis functions to build your models. You can set linear and nonlinear basis functions and ensemble them to get custom NARMAX models. | | Parameter Estimation | More than 15 methods to estimate the model parameters and test different structure selection scenarios. | | Multiobjective Parameter Estimation | You can use affine information to estimate the model parameters minimizing different objective functions. | | Model Simulation | You can reproduce results from papers easily with SimulateNARMAX class. Moreover, you can test published models with different parameter estimation methods and compare the performance. | | Neural NARX | You can use SysIdentPy with Pytorch to create custom neural NARX models architectures which support all the optimizers and loss functions from Pytorch. | | General Estimators | You can use estimators from packages like scikit-learn, Catboost, and many other compatible interfaces and composition tools to create NARMAX models. |
Why does SysIdentPy exist?
SysIdentPy aims to be a free and open-source package to help the community to design NARMAX models for System Identification and TimeSeries Forecasting. More than that, be a free and robust alternative to one of the most used tools to build NARMAX models, which is the Matlab's System Identification Toolbox.
The project is actively maintained by Wilson R. L. Junior and looking for contributors.
How do I use SysIdentPy?
The SysIdentPy documentation includes more than 20 examples to help get you started:
- Quickstart guide, for an entry-level description of the main SysIdentPy concepts
- A dedicated section focusing on SysIdentPy features, like model structure selection algorithms, basis functions, parameter estimation, and more.
- A dedicated section focusing on use cases using SysIdentPy with real world datasets. Besides, there is some brief comparisons and benchmarks against other time series tools, like Prophet, Neural Prophet, ARIMA, and more.
Examples
from torch import nn
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sysidentpy.metrics import root_relative_squared_error
from sysidentpy.utils.generate_data import get_siso_data
# Generate a dataset of a simulated dynamical system
x_train, x_valid, y_train, y_valid = get_siso_data(
n=1000,
colored_noise=False,
sigma=0.001,
train_percentage=80
)
Building Polynomial NARX models with FROLS algorithm
from sysidentpy.model_structure_selection import FROLS
from sysidentpy.basis_function import Polynomial
from sysidentpy.parameter_estimation import LeastSquares
from sysidentpy.metrics import root_relative_squared_error
from sysidentpy.utils.generate_data import get_siso_data
from sysidentpy.utils.display_results import results
from sysidentpy.utils.plotting import plot_residues_correlation, plot_results
from sysidentpy.residues.residues_correlation import (
compute_residues_autocorrelation,
compute_cross_correlation,
)
basis_function = Polynomial(degree=2)
estimator = LeastSquares()
model = FROLS(
order_selection=True,
n_info_values=3,
ylag=2,
xlag=2,
info_criteria="aic",
estimator=estimator,
err_tol=None,
basis_function=basis_function,
)
model.fit(X=x_train, y=y_train)
yhat = model.predict(X=x_valid, y=y_valid)
rrse = root_relative_squared_error(y_valid, yhat)
print(rrse)
r = pd.DataFrame(
results(
model.final_model, model.theta, model.err,
model.n_terms, err_precision=8, dtype='sci'
),
columns=['Regressors', 'Parameters', 'ERR'])
print(r)
Regressors Parameters ERR
0 x1(k-2) 0.9000 0.95556574
1 y(k-1) 0.1999 0.04107943
2 x1(k-1)y(k-1) 0.1000 0.00335113
plot_results(y=y_valid, yhat=yhat, n=100, figsize=(14, 3), linewidth=1.5)

NARX Neural Network
from sysidentpy.neural_network import NARXNN
from sysidentpy.basis_function import Polynomial
from sysidentpy.utils.plotting import plot_residues_correlation, plot_results
from sysidentpy.residues.residues_correlation import compute_residues_autocorrelation
from sysidentpy.residues.residues_correlation import compute_cross_correlation
class NARX(nn.Module):
def __init__(self):
supe
