sysidentpy


Namesysidentpy JSON
Version 0.4.1 PyPI version JSON
download
home_pageNone
SummaryA Python Package For System Identification Using NARMAX Models
upload_time2024-08-11 20:42:40
maintainerNone
docs_urlNone
authorWilson Rocha Lacerda Junior
requires_python<3.13,>=3.7
licenseBSD 3-Clause License Copyright (c) 2019, Wilson Rocha; Luan Pascoal; Samuel Oliveira; Samir Martins All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
keywords data-science forecasting narmax narx system-identification machine-learning time-series time-series-analysis time-series-classification time-series-regression
VCS
bugtrack_url
requirements matplotlib numpy scipy torch
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <div align="center">
<img src="images/sysidentpy-logo.svg" width="640" height="320" />

[![DOI](https://img.shields.io/badge/DOI-10.21105%2Fjoss.02384-%23FF7800)](https://joss.theoj.org/papers/10.21105/joss.02384)
[![PyPI version](https://img.shields.io/pypi/v/sysidentpy?color=%23ff7800)](https://pypi.org/project/sysidentpy/)
[![License](https://img.shields.io/pypi/l/sysidentpy?color=%23FF7800)](https://opensource.org/licenses/BSD-3-Clause)
[![openissues](https://img.shields.io/github/issues/wilsonrljr/sysidentpy?color=%23FF7800)](https://github.com/wilsonrljr/sysidentpy/issues)
[![issuesclosed](https://img.shields.io/github/issues-closed-raw/wilsonrljr/sysidentpy?color=%23FF7800)](https://github.com/wilsonrljr/sysidentpy/issues)
[![downloads](https://img.shields.io/pypi/dm/sysidentpy?color=%23FF7800)](https://pypi.org/project/sysidentpy/)
[![python](https://img.shields.io/pypi/pyversions/sysidentpy?color=%23FF7800)](https://pypi.org/project/sysidentpy/)
[![status](https://img.shields.io/pypi/status/sysidentpy?color=%23FF7800)](https://pypi.org/project/sysidentpy/)
[![discord](https://img.shields.io/discord/711610087700955176?color=%23FF7800&label=discord)](https://discord.gg/7afBSzU4)
[![contributors](https://img.shields.io/github/contributors/wilsonrljr/sysidentpy?color=%23FF7800)](https://github.com/wilsonrljr/sysidentpy/graphs/contributors)
[![stars](https://img.shields.io/github/stars/wilsonrljr/sysidentpy?style=social)](https://github.com/wilsonrljr/sysidentpy/stargazers)

<h1 align="center"> NARMAX Methods For System Identification and Timeseries Forecasting </h1>
<h3 align="center">From Classical Approaches to Neural Networks</h3>

**SysIdentPy** offers State of the Art techniques to build your NARMAX models, including it's 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.

</div>

## Table of Contents

- [What is SysIdentPy?](#what-is-sysidentpy)
- [How do I install SysIdentPy?](#how-do-i-install_sysidentpy)
- [Features](#what-are-the-main-features-of-sysidentpy)
- [Why does SysIdentPy exist?](#why-does-sysidentpy-exist)
- [How do I use sysIdentPy?](#how-do-i-use-sysIdentPy)
- [Examples](#examples)
- [Communication](#communication)
- [Citation](#citation)
- [Inspiration](#inspiration)
- [Contributors](#contributors)
- [Sponsors](#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](https://sysidentpy.org)!

For an in depth documentation, check our companion book:

<a href="https://sysidentpy.org/book/preface/">
  <img src="./docs/book/assets/Nonlinear_System_identification.png" 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``
``` console
pip install sysidentpy
```

### Requirements

`SysIdentPy` requires:

- Python (>= 3.7)
- NumPy (>= 1.9.2) for numerical algorithms
- Matplotlib >= 3.3.2 for static plotting and visualizations
- Pytorch (>=1.7.1) for building NARX neural networks
- scipy (>= 1.7.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](https://sysidentpy.org/landing-page/getting-started/)

## 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 and MetaMSS and several combinations with parameter estimation techniques to select the model terms. |
| Basis Function | You can use 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](https://sysidentpy.org) includes more than 20 examples to help get you started:
- Typical "Hello World" example, for an [entry-level description of the main SysIdentPy concepts](https://sysidentpy.org/examples/basic_steps/)
- 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
```python
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

```python
from sysidentpy.model_structure_selection import FROLS
from sysidentpy.basis_function import Polynomial
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
from sysidentpy.residues.residues_correlation import compute_cross_correlation

basis_function=Polynomial(degree=2)
model = FROLS(
  order_selection=True,
  n_info_values=10,
  extended_least_squares=False,
  ylag=2,
  xlag=2,
  info_criteria='aic',
  estimator='least_squares',
  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=1000)
ee = compute_residues_autocorrelation(y_valid, yhat)
plot_residues_correlation(data=ee, title="Residues", ylabel="$e^2$")
x1e = compute_cross_correlation(y_valid, yhat, x2_val)
plot_residues_correlation(data=x1e, title="Residues", ylabel="$x_1e$")
```
![polynomial](./examples/figures/polynomial_narmax.png)

#### NARX Neural Network
```python
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):
        super().__init__()
        self.lin = nn.Linear(4, 10)
        self.lin2 = nn.Linear(10, 10)
        self.lin3 = nn.Linear(10, 1)
        self.tanh = nn.Tanh()

    def forward(self, xb):
        z = self.lin(xb)
        z = self.tanh(z)
        z = self.lin2(z)
        z = self.tanh(z)
        z = self.lin3(z)
        return z

basis_function=Polynomial(degree=1)

narx_net = NARXNN(
  net=NARX(),
  ylag=2,
  xlag=2,
  basis_function=basis_function,
  model_type="NARMAX",
  loss_func='mse_loss',
  optimizer='Adam',
  epochs=200,
  verbose=False,
  optim_params={'betas': (0.9, 0.999), 'eps': 1e-05} # optional parameters of the optimizer
)

narx_net.fit(X=x_train, y=y_train)
yhat = narx_net.predict(X=x_valid, y=y_valid)
plot_results(y=y_valid, yhat=yhat, n=1000)
ee = compute_residues_autocorrelation(y_valid, yhat)
plot_residues_correlation(data=ee, title="Residues", ylabel="$e^2$")
x1e = compute_cross_correlation(y_valid, yhat, x_valid)
plot_residues_correlation(data=x1e, title="Residues", ylabel="$x_1e$")
```
![neural](/examples/figures/narx_network.png)

#### Catboost-narx
```python
from catboost import CatBoostRegressor
from sysidentpy.general_estimators import NARX
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


basis_function=Polynomial(degree=1)

catboost_narx = NARX(
  base_estimator=CatBoostRegressor(
    iterations=300,
    learning_rate=0.1,
    depth=6),
  xlag=2,
  ylag=2,
  basis_function=basis_function,
  fit_params={'verbose': False}
)

catboost_narx.fit(X=x_train, y=y_train)
yhat = catboost_narx.predict(X=x_valid, y=y_valid)
plot_results(y=y_valid, yhat=yhat, n=1000)
ee = compute_residues_autocorrelation(y_valid, yhat)
plot_residues_correlation(data=ee, title="Residues", ylabel="$e^2$")
x1e = compute_cross_correlation(y_valid, yhat, x_valid)
plot_residues_correlation(data=x1e, title="Residues", ylabel="$x_1e$")
```
![catboost](/examples/figures/catboost_narx.png)

#### Catboost without NARX configuration

The following is the Catboost performance without the NARX configuration.


```python

def plot_results_tmp(y_valid, yhat):
    _, ax = plt.subplots(figsize=(14, 8))
    ax.plot(y_valid[:200], label='Data', marker='o')
    ax.plot(yhat[:200], label='Prediction', marker='*')
    ax.set_xlabel("$n$", fontsize=18)
    ax.set_ylabel("$y[n]$", fontsize=18)
    ax.grid()
    ax.legend(fontsize=18)
    plt.show()

catboost = CatBoostRegressor(
  iterations=300,
  learning_rate=0.1,
  depth=6
)
catboost.fit(x_train, y_train, verbose=False)
plot_results_tmp(y_valid, catboost.predict(x_valid))
```
![catboost](/examples/figures/catboost.png)

The examples directory has several Jupyter notebooks with tutorials of how to use the package and some specific applications of sysidentpy. Try it out!

## Communication

- Discord server: https://discord.gg/8eGE3PQ

  [![discord](https://img.shields.io/discord/711610087700955176?color=%23FF7800&label=discord)](https://discord.gg/8eGE3PQ)


- Website: http://sysidentpy.org

## Citation
[![DOI](https://img.shields.io/badge/DOI-10.21105%2Fjoss.02384-%23FF7800)](https://joss.theoj.org/papers/10.21105/joss.02384)

If you use SysIdentPy on your project, please [drop me a line](mailto:wilsonrljr@outlook.com).

If you use SysIdentPy on your scientific publication, we would appreciate citations to the following paper:

- Lacerda et al., (2020). SysIdentPy: A Python package for System Identification using NARMAX models. Journal of Open Source Software, 5(54), 2384, https://doi.org/10.21105/joss.02384

```
@article{Lacerda2020,
  doi = {10.21105/joss.02384},
  url = {https://doi.org/10.21105/joss.02384},
  year = {2020},
  publisher = {The Open Journal},
  volume = {5},
  number = {54},
  pages = {2384},
  author = {Wilson Rocha Lacerda Junior and Luan Pascoal Costa da Andrade and Samuel Carlos Pessoa Oliveira and Samir Angelo Milani Martins},
  title = {SysIdentPy: A Python package for System Identification using NARMAX models},
  journal = {Journal of Open Source Software}
}
```

## Inspiration

The documentation and structure (even this section) is openly inspired by sklearn, einsteinpy, and many others as we used (and keep using) them to learn.

## Contributors

<a href="https://github.com/wilsonrljr/sysidentpy/graphs/contributors">
  <img src="https://contributors-img.web.app/image?repo=wilsonrljr/sysidentpy" width = 500/>
</a>


## Sponsors
<!-- sponsors -->
**Special thanks** to our **sponsors**

<hr />


### Gold Sponsors

<a href="https://github.com/ml-technium">
    <img alt="Technium" src="https://avatars.githubusercontent.com/u/83768197?v=4" width="90" height="90">
</a>

### Monthly Sponsors

<a href="https://github.com/statisticallyinsifnificant">
    <img alt="statisticallyinsifnificant" src="https://avatars.githubusercontent.com/u/158107107?v=4" width="90" height="90">
</a>

### Individual Sponsors

<a href="https://github.com/nataliakeles">
    <img alt="Nath Keles" src="https://avatars.githubusercontent.com/u/61664158?v=4" width="90" height="90">
</a>

<hr />

  [wilsonrljr's sponsor profile]: https://github.com/sponsors/wilsonrljr

<!-- sponsors -->

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "sysidentpy",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<3.13,>=3.7",
    "maintainer_email": "Wilson Rocha Lacerda Junior <wilsonrljr@outlook.com>",
    "keywords": "data-science, forecasting, NARMAX, NARX, system-identification, machine-learning, time-series, time-series-analysis, time-series-classification, time-series-regression",
    "author": "Wilson Rocha Lacerda Junior",
    "author_email": "wilsonrljr@outlook.com",
    "download_url": "https://files.pythonhosted.org/packages/9d/67/fd72f30cf78af4ab544c42ce359aa0e036977ada64d34cdccf70e494bb7a/sysidentpy-0.4.1.tar.gz",
    "platform": null,
    "description": "<div align=\"center\">\r\n<img src=\"images/sysidentpy-logo.svg\" width=\"640\" height=\"320\" />\r\n\r\n[![DOI](https://img.shields.io/badge/DOI-10.21105%2Fjoss.02384-%23FF7800)](https://joss.theoj.org/papers/10.21105/joss.02384)\r\n[![PyPI version](https://img.shields.io/pypi/v/sysidentpy?color=%23ff7800)](https://pypi.org/project/sysidentpy/)\r\n[![License](https://img.shields.io/pypi/l/sysidentpy?color=%23FF7800)](https://opensource.org/licenses/BSD-3-Clause)\r\n[![openissues](https://img.shields.io/github/issues/wilsonrljr/sysidentpy?color=%23FF7800)](https://github.com/wilsonrljr/sysidentpy/issues)\r\n[![issuesclosed](https://img.shields.io/github/issues-closed-raw/wilsonrljr/sysidentpy?color=%23FF7800)](https://github.com/wilsonrljr/sysidentpy/issues)\r\n[![downloads](https://img.shields.io/pypi/dm/sysidentpy?color=%23FF7800)](https://pypi.org/project/sysidentpy/)\r\n[![python](https://img.shields.io/pypi/pyversions/sysidentpy?color=%23FF7800)](https://pypi.org/project/sysidentpy/)\r\n[![status](https://img.shields.io/pypi/status/sysidentpy?color=%23FF7800)](https://pypi.org/project/sysidentpy/)\r\n[![discord](https://img.shields.io/discord/711610087700955176?color=%23FF7800&label=discord)](https://discord.gg/7afBSzU4)\r\n[![contributors](https://img.shields.io/github/contributors/wilsonrljr/sysidentpy?color=%23FF7800)](https://github.com/wilsonrljr/sysidentpy/graphs/contributors)\r\n[![stars](https://img.shields.io/github/stars/wilsonrljr/sysidentpy?style=social)](https://github.com/wilsonrljr/sysidentpy/stargazers)\r\n\r\n<h1 align=\"center\"> NARMAX Methods For System Identification and Timeseries Forecasting </h1>\r\n<h3 align=\"center\">From Classical Approaches to Neural Networks</h3>\r\n\r\n**SysIdentPy** offers State of the Art techniques to build your NARMAX models, including it's 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.\r\n\r\n</div>\r\n\r\n## Table of Contents\r\n\r\n- [What is SysIdentPy?](#what-is-sysidentpy)\r\n- [How do I install SysIdentPy?](#how-do-i-install_sysidentpy)\r\n- [Features](#what-are-the-main-features-of-sysidentpy)\r\n- [Why does SysIdentPy exist?](#why-does-sysidentpy-exist)\r\n- [How do I use sysIdentPy?](#how-do-i-use-sysIdentPy)\r\n- [Examples](#examples)\r\n- [Communication](#communication)\r\n- [Citation](#citation)\r\n- [Inspiration](#inspiration)\r\n- [Contributors](#contributors)\r\n- [Sponsors](#sponsors)\r\n\r\n\r\n## Introduction\r\n\r\nSysIdentPy 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.\r\n\r\nWith SysIdentPy, you can:\r\n\r\n- Build and customize nonlinear forecasting models.\r\n- Utilize state-of-the-art techniques for model structure selection and parameter estimation.\r\n- Experiment with neural NARX models and other advanced algorithms.\r\n\r\nCheck our [documentation](https://sysidentpy.org)!\r\n\r\nFor an in depth documentation, check our companion book:\r\n\r\n<a href=\"https://sysidentpy.org/book/preface/\">\r\n  <img src=\"./docs/book/assets/Nonlinear_System_identification.png\" alt=\"Nonlinear System Identification\" style=\"width: 200px; height: auto;\" />\r\n</a>\r\n\r\n\r\n## How do I install SysIdentPy?\r\n\r\nThe easiest way to get SysIdentPy running is to install it using ``pip``\r\n``` console\r\npip install sysidentpy\r\n```\r\n\r\n### Requirements\r\n\r\n`SysIdentPy` requires:\r\n\r\n- Python (>= 3.7)\r\n- NumPy (>= 1.9.2) for numerical algorithms\r\n- Matplotlib >= 3.3.2 for static plotting and visualizations\r\n- Pytorch (>=1.7.1) for building NARX neural networks\r\n- scipy (>= 1.7.0) for numerical and optimization algorithms\r\n\r\nThe library is compatible with Linux, Windows, and macOS. Some examples may also require additional packages like pandas.\r\n\r\nFor more details, check our [installation guide](https://sysidentpy.org/landing-page/getting-started/)\r\n\r\n## What are the main features of SysIdentPy?\r\n\r\n| Feature | What is this? |\r\n|----------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\r\n| NARMAX philosophy | You can build variations of NARMAX models like NARX, NAR, NARMA, NFIR, ARMA, ARX, AR, and others. |\r\n| Model Structure Selection | Easy-to-use methods to select the best terms to build your models, including FROLS and MetaMSS and several combinations with parameter estimation techniques to select the model terms. |\r\n| Basis Function | You can use different basis functions to build your models. You can set linear and nonlinear basis functions and ensemble them to get custom NARMAX models. |\r\n| Parameter Estimation | More than 15 methods to estimate the model parameters and test different structure selection scenarios. |\r\n| Multiobjective Parameter Estimation | You can use affine information to estimate the model parameters minimizing different objective functions. |\r\n| 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. |\r\n| 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. |\r\n| General Estimators | You can use estimators from packages like scikit-learn, Catboost, and many other compatible interfaces and composition tools, to create NARMAX models. |\r\n\r\n## Why does SysIdentPy exist?\r\n\r\nSysIdentPy 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.\r\n\r\nThe project is actively maintained by Wilson R. L. Junior and looking for contributors.\r\n\r\n## How do I use sysIdentPy?\r\n\r\nThe [SysIdentPy documentation](https://sysidentpy.org) includes more than 20 examples to help get you started:\r\n- Typical \"Hello World\" example, for an [entry-level description of the main SysIdentPy concepts](https://sysidentpy.org/examples/basic_steps/)\r\n- A dedicated section focusing on SysIdentPy features, like model structure selection algorithms, basis functions, parameter estimation, and more.\r\n- 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.\r\n\r\n\r\n### Examples\r\n```python\r\nfrom torch import nn\r\nimport numpy as np\r\nimport pandas as pd\r\nimport matplotlib.pyplot as plt\r\nfrom sysidentpy.metrics import root_relative_squared_error\r\nfrom sysidentpy.utils.generate_data import get_siso_data\r\n\r\n\r\n# Generate a dataset of a simulated dynamical system\r\nx_train, x_valid, y_train, y_valid = get_siso_data(\r\n  n=1000,\r\n  colored_noise=False,\r\n  sigma=0.001,\r\n  train_percentage=80\r\n)\r\n```\r\n\r\n#### Building Polynomial NARX models with FROLS algorithm\r\n\r\n```python\r\nfrom sysidentpy.model_structure_selection import FROLS\r\nfrom sysidentpy.basis_function import Polynomial\r\nfrom sysidentpy.utils.display_results import results\r\nfrom sysidentpy.utils.plotting import plot_residues_correlation, plot_results\r\nfrom sysidentpy.residues.residues_correlation import compute_residues_autocorrelation\r\nfrom sysidentpy.residues.residues_correlation import compute_cross_correlation\r\n\r\nbasis_function=Polynomial(degree=2)\r\nmodel = FROLS(\r\n  order_selection=True,\r\n  n_info_values=10,\r\n  extended_least_squares=False,\r\n  ylag=2,\r\n  xlag=2,\r\n  info_criteria='aic',\r\n  estimator='least_squares',\r\n  basis_function=basis_function\r\n)\r\nmodel.fit(X=x_train, y=y_train)\r\nyhat = model.predict(X=x_valid, y=y_valid)\r\nrrse = root_relative_squared_error(y_valid, yhat)\r\nprint(rrse)\r\nr = pd.DataFrame(\r\n\tresults(\r\n\t\tmodel.final_model, model.theta, model.err,\r\n\t\tmodel.n_terms, err_precision=8, dtype='sci'\r\n\t\t),\r\n\tcolumns=['Regressors', 'Parameters', 'ERR'])\r\nprint(r)\r\n\r\nRegressors     Parameters        ERR\r\n0        x1(k-2)     0.9000  0.95556574\r\n1         y(k-1)     0.1999  0.04107943\r\n2  x1(k-1)y(k-1)     0.1000  0.00335113\r\n\r\nplot_results(y=y_valid, yhat=yhat, n=1000)\r\nee = compute_residues_autocorrelation(y_valid, yhat)\r\nplot_residues_correlation(data=ee, title=\"Residues\", ylabel=\"$e^2$\")\r\nx1e = compute_cross_correlation(y_valid, yhat, x2_val)\r\nplot_residues_correlation(data=x1e, title=\"Residues\", ylabel=\"$x_1e$\")\r\n```\r\n![polynomial](./examples/figures/polynomial_narmax.png)\r\n\r\n#### NARX Neural Network\r\n```python\r\nfrom sysidentpy.neural_network import NARXNN\r\nfrom sysidentpy.basis_function import Polynomial\r\nfrom sysidentpy.utils.plotting import plot_residues_correlation, plot_results\r\nfrom sysidentpy.residues.residues_correlation import compute_residues_autocorrelation\r\nfrom sysidentpy.residues.residues_correlation import compute_cross_correlation\r\n\r\nclass NARX(nn.Module):\r\n    def __init__(self):\r\n        super().__init__()\r\n        self.lin = nn.Linear(4, 10)\r\n        self.lin2 = nn.Linear(10, 10)\r\n        self.lin3 = nn.Linear(10, 1)\r\n        self.tanh = nn.Tanh()\r\n\r\n    def forward(self, xb):\r\n        z = self.lin(xb)\r\n        z = self.tanh(z)\r\n        z = self.lin2(z)\r\n        z = self.tanh(z)\r\n        z = self.lin3(z)\r\n        return z\r\n\r\nbasis_function=Polynomial(degree=1)\r\n\r\nnarx_net = NARXNN(\r\n  net=NARX(),\r\n  ylag=2,\r\n  xlag=2,\r\n  basis_function=basis_function,\r\n  model_type=\"NARMAX\",\r\n  loss_func='mse_loss',\r\n  optimizer='Adam',\r\n  epochs=200,\r\n  verbose=False,\r\n  optim_params={'betas': (0.9, 0.999), 'eps': 1e-05} # optional parameters of the optimizer\r\n)\r\n\r\nnarx_net.fit(X=x_train, y=y_train)\r\nyhat = narx_net.predict(X=x_valid, y=y_valid)\r\nplot_results(y=y_valid, yhat=yhat, n=1000)\r\nee = compute_residues_autocorrelation(y_valid, yhat)\r\nplot_residues_correlation(data=ee, title=\"Residues\", ylabel=\"$e^2$\")\r\nx1e = compute_cross_correlation(y_valid, yhat, x_valid)\r\nplot_residues_correlation(data=x1e, title=\"Residues\", ylabel=\"$x_1e$\")\r\n```\r\n![neural](/examples/figures/narx_network.png)\r\n\r\n#### Catboost-narx\r\n```python\r\nfrom catboost import CatBoostRegressor\r\nfrom sysidentpy.general_estimators import NARX\r\nfrom sysidentpy.basis_function import Polynomial\r\nfrom sysidentpy.utils.plotting import plot_residues_correlation, plot_results\r\nfrom sysidentpy.residues.residues_correlation import compute_residues_autocorrelation\r\nfrom sysidentpy.residues.residues_correlation import compute_cross_correlation\r\n\r\n\r\nbasis_function=Polynomial(degree=1)\r\n\r\ncatboost_narx = NARX(\r\n  base_estimator=CatBoostRegressor(\r\n    iterations=300,\r\n    learning_rate=0.1,\r\n    depth=6),\r\n  xlag=2,\r\n  ylag=2,\r\n  basis_function=basis_function,\r\n  fit_params={'verbose': False}\r\n)\r\n\r\ncatboost_narx.fit(X=x_train, y=y_train)\r\nyhat = catboost_narx.predict(X=x_valid, y=y_valid)\r\nplot_results(y=y_valid, yhat=yhat, n=1000)\r\nee = compute_residues_autocorrelation(y_valid, yhat)\r\nplot_residues_correlation(data=ee, title=\"Residues\", ylabel=\"$e^2$\")\r\nx1e = compute_cross_correlation(y_valid, yhat, x_valid)\r\nplot_residues_correlation(data=x1e, title=\"Residues\", ylabel=\"$x_1e$\")\r\n```\r\n![catboost](/examples/figures/catboost_narx.png)\r\n\r\n#### Catboost without NARX configuration\r\n\r\nThe following is the Catboost performance without the NARX configuration.\r\n\r\n\r\n```python\r\n\r\ndef plot_results_tmp(y_valid, yhat):\r\n    _, ax = plt.subplots(figsize=(14, 8))\r\n    ax.plot(y_valid[:200], label='Data', marker='o')\r\n    ax.plot(yhat[:200], label='Prediction', marker='*')\r\n    ax.set_xlabel(\"$n$\", fontsize=18)\r\n    ax.set_ylabel(\"$y[n]$\", fontsize=18)\r\n    ax.grid()\r\n    ax.legend(fontsize=18)\r\n    plt.show()\r\n\r\ncatboost = CatBoostRegressor(\r\n  iterations=300,\r\n  learning_rate=0.1,\r\n  depth=6\r\n)\r\ncatboost.fit(x_train, y_train, verbose=False)\r\nplot_results_tmp(y_valid, catboost.predict(x_valid))\r\n```\r\n![catboost](/examples/figures/catboost.png)\r\n\r\nThe examples directory has several Jupyter notebooks with tutorials of how to use the package and some specific applications of sysidentpy. Try it out!\r\n\r\n## Communication\r\n\r\n- Discord server: https://discord.gg/8eGE3PQ\r\n\r\n  [![discord](https://img.shields.io/discord/711610087700955176?color=%23FF7800&label=discord)](https://discord.gg/8eGE3PQ)\r\n\r\n\r\n- Website: http://sysidentpy.org\r\n\r\n## Citation\r\n[![DOI](https://img.shields.io/badge/DOI-10.21105%2Fjoss.02384-%23FF7800)](https://joss.theoj.org/papers/10.21105/joss.02384)\r\n\r\nIf you use SysIdentPy on your project, please [drop me a line](mailto:wilsonrljr@outlook.com).\r\n\r\nIf you use SysIdentPy on your scientific publication, we would appreciate citations to the following paper:\r\n\r\n- Lacerda et al., (2020). SysIdentPy: A Python package for System Identification using NARMAX models. Journal of Open Source Software, 5(54), 2384, https://doi.org/10.21105/joss.02384\r\n\r\n```\r\n@article{Lacerda2020,\r\n  doi = {10.21105/joss.02384},\r\n  url = {https://doi.org/10.21105/joss.02384},\r\n  year = {2020},\r\n  publisher = {The Open Journal},\r\n  volume = {5},\r\n  number = {54},\r\n  pages = {2384},\r\n  author = {Wilson Rocha Lacerda Junior and Luan Pascoal Costa da Andrade and Samuel Carlos Pessoa Oliveira and Samir Angelo Milani Martins},\r\n  title = {SysIdentPy: A Python package for System Identification using NARMAX models},\r\n  journal = {Journal of Open Source Software}\r\n}\r\n```\r\n\r\n## Inspiration\r\n\r\nThe documentation and structure (even this section) is openly inspired by sklearn, einsteinpy, and many others as we used (and keep using) them to learn.\r\n\r\n## Contributors\r\n\r\n<a href=\"https://github.com/wilsonrljr/sysidentpy/graphs/contributors\">\r\n  <img src=\"https://contributors-img.web.app/image?repo=wilsonrljr/sysidentpy\" width = 500/>\r\n</a>\r\n\r\n\r\n## Sponsors\r\n<!-- sponsors -->\r\n**Special thanks** to our **sponsors**\r\n\r\n<hr />\r\n\r\n\r\n### Gold Sponsors\r\n\r\n<a href=\"https://github.com/ml-technium\">\r\n    <img alt=\"Technium\" src=\"https://avatars.githubusercontent.com/u/83768197?v=4\" width=\"90\" height=\"90\">\r\n</a>\r\n\r\n### Monthly Sponsors\r\n\r\n<a href=\"https://github.com/statisticallyinsifnificant\">\r\n    <img alt=\"statisticallyinsifnificant\" src=\"https://avatars.githubusercontent.com/u/158107107?v=4\" width=\"90\" height=\"90\">\r\n</a>\r\n\r\n### Individual Sponsors\r\n\r\n<a href=\"https://github.com/nataliakeles\">\r\n    <img alt=\"Nath Keles\" src=\"https://avatars.githubusercontent.com/u/61664158?v=4\" width=\"90\" height=\"90\">\r\n</a>\r\n\r\n<hr />\r\n\r\n  [wilsonrljr's sponsor profile]: https://github.com/sponsors/wilsonrljr\r\n\r\n<!-- sponsors -->\r\n",
    "bugtrack_url": null,
    "license": "BSD 3-Clause License  Copyright (c) 2019, Wilson Rocha; Luan Pascoal; Samuel Oliveira; Samir Martins All rights reserved.  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:  * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.  * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ",
    "summary": "A Python Package For System Identification Using NARMAX Models",
    "version": "0.4.1",
    "project_urls": {
        "changelog": "https://github.com/wilsonrljr/sysidentpy/blob/master/CHANGELOG",
        "documentation": "http://sysidentpy.org/",
        "homepage": "http://sysidentpy.org",
        "repository": "https://github.com/wilsonrljr/sysidentpy"
    },
    "split_keywords": [
        "data-science",
        " forecasting",
        " narmax",
        " narx",
        " system-identification",
        " machine-learning",
        " time-series",
        " time-series-analysis",
        " time-series-classification",
        " time-series-regression"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "70f5284a37a83f09a27237ac7a59648282d28edeba2cbe8c85c75545807dab83",
                "md5": "3797a1bdaf1800f960552b964db8d0ae",
                "sha256": "c6260404e44b58e0a1393a78ada60b9c000e601fca2e624b146234bc7306bfbc"
            },
            "downloads": -1,
            "filename": "sysidentpy-0.4.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3797a1bdaf1800f960552b964db8d0ae",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<3.13,>=3.7",
            "size": 117778,
            "upload_time": "2024-08-11T20:42:34",
            "upload_time_iso_8601": "2024-08-11T20:42:34.269089Z",
            "url": "https://files.pythonhosted.org/packages/70/f5/284a37a83f09a27237ac7a59648282d28edeba2cbe8c85c75545807dab83/sysidentpy-0.4.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9d67fd72f30cf78af4ab544c42ce359aa0e036977ada64d34cdccf70e494bb7a",
                "md5": "6d8afdf48f1b208ad41e997243aebdbf",
                "sha256": "60a6d35da6ae3277c47743888babf24e05fef2fae0bab64dfca36f790941a9a4"
            },
            "downloads": -1,
            "filename": "sysidentpy-0.4.1.tar.gz",
            "has_sig": false,
            "md5_digest": "6d8afdf48f1b208ad41e997243aebdbf",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<3.13,>=3.7",
            "size": 98756927,
            "upload_time": "2024-08-11T20:42:40",
            "upload_time_iso_8601": "2024-08-11T20:42:40.594350Z",
            "url": "https://files.pythonhosted.org/packages/9d/67/fd72f30cf78af4ab544c42ce359aa0e036977ada64d34cdccf70e494bb7a/sysidentpy-0.4.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-11 20:42:40",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "wilsonrljr",
    "github_project": "sysidentpy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "matplotlib",
            "specs": []
        },
        {
            "name": "numpy",
            "specs": [
                [
                    "<=",
                    "1.24.3"
                ]
            ]
        },
        {
            "name": "scipy",
            "specs": []
        },
        {
            "name": "torch",
            "specs": [
                [
                    ">=",
                    "1.7.1"
                ]
            ]
        }
    ],
    "lcname": "sysidentpy"
}
        
Elapsed time: 0.31486s