sysidentpy


Namesysidentpy JSON
Version 0.3.3 PyPI version JSON
download
home_page
SummaryA Python Package For System Identification Using NARMAX Models
upload_time2023-09-24 19:12:24
maintainer
docs_urlNone
authorWilson Rocha Lacerda Junior
requires_python<3.12,>=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 No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <p align="center">
<img src="images/sysidentpy-logo.svg" width="640" height="320" />
</p>

[![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)
[![forks](https://img.shields.io/github/forks/wilsonrljr/sysidentpy?style=social)](https://github.com/wilsonrljr/sysidentpy/network/members)
[![stars](https://img.shields.io/github/stars/wilsonrljr/sysidentpy?style=social)](https://github.com/wilsonrljr/sysidentpy/stargazers)


## What is SysIdentPy?

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.

Check our [documentation](https://sysidentpy.org)!

## 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 all numerical algorithms
- Matplotlib >= 3.3.2 for static plotting and visualizations
- Pytorch (>=1.7.1) for building feed-forward neural networks

| Platform | Status |
| --------- | -----:|
| Linux | ok |
| Windows | ok |
| macOS | ok |

A few examples require pandas >= 0.18.0. However, it is not required to use SysIdentPy.

## 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. |
| 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. 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 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/7afBSzU4)


- 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>

### 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": "",
    "name": "sysidentpy",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "<3.12,>=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/0d/4d/82ae5297d1e4460c3c0758679c6e07b78d78a1e4760ff9616db1117c7c33/sysidentpy-0.3.3.tar.gz",
    "platform": null,
    "description": "<p align=\"center\">\r\n<img src=\"images/sysidentpy-logo.svg\" width=\"640\" height=\"320\" />\r\n</p>\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[![forks](https://img.shields.io/github/forks/wilsonrljr/sysidentpy?style=social)](https://github.com/wilsonrljr/sysidentpy/network/members)\r\n[![stars](https://img.shields.io/github/stars/wilsonrljr/sysidentpy?style=social)](https://github.com/wilsonrljr/sysidentpy/stargazers)\r\n\r\n\r\n## What is SysIdentPy?\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\nCheck our [documentation](https://sysidentpy.org)!\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\nSysIdentPy requires:\r\n\r\n- Python (>= 3.7)\r\n- NumPy (>= 1.9.2) for all numerical algorithms\r\n- Matplotlib >= 3.3.2 for static plotting and visualizations\r\n- Pytorch (>=1.7.1) for building feed-forward neural networks\r\n\r\n| Platform | Status |\r\n| --------- | -----:|\r\n| Linux | ok |\r\n| Windows | ok |\r\n| macOS | ok |\r\n\r\nA few examples require pandas >= 0.18.0. However, it is not required to use SysIdentPy.\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| 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. 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 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\t\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/7afBSzU4)\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### 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.3.3",
    "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": "1f10cce282260d7405b802d71fef9d40ae05e0ec2aef218d84ded8f3184f138e",
                "md5": "665db544e5ff5a74df200e54363d4666",
                "sha256": "72d3bd2660dc7d57e178e29a56ac21132e297dbebd40ffbe90e3eb04d3c120e1"
            },
            "downloads": -1,
            "filename": "sysidentpy-0.3.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "665db544e5ff5a74df200e54363d4666",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<3.12,>=3.7",
            "size": 106656,
            "upload_time": "2023-09-24T19:12:15",
            "upload_time_iso_8601": "2023-09-24T19:12:15.946306Z",
            "url": "https://files.pythonhosted.org/packages/1f/10/cce282260d7405b802d71fef9d40ae05e0ec2aef218d84ded8f3184f138e/sysidentpy-0.3.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0d4d82ae5297d1e4460c3c0758679c6e07b78d78a1e4760ff9616db1117c7c33",
                "md5": "10d6989f95a7f71125e035113d964d86",
                "sha256": "8589217bb88a182a398f74d96542d6e5a4ae8c2234ac5467c6c4226ccefd583f"
            },
            "downloads": -1,
            "filename": "sysidentpy-0.3.3.tar.gz",
            "has_sig": false,
            "md5_digest": "10d6989f95a7f71125e035113d964d86",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<3.12,>=3.7",
            "size": 40766537,
            "upload_time": "2023-09-24T19:12:24",
            "upload_time_iso_8601": "2023-09-24T19:12:24.731272Z",
            "url": "https://files.pythonhosted.org/packages/0d/4d/82ae5297d1e4460c3c0758679c6e07b78d78a1e4760ff9616db1117c7c33/sysidentpy-0.3.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-24 19:12:24",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "wilsonrljr",
    "github_project": "sysidentpy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "sysidentpy"
}
        
Elapsed time: 0.11827s