CFSpy


NameCFSpy JSON
Version 1.0.13 PyPI version JSON
download
home_pagehttps://github.com/iperezav/CFSpy/
SummaryChen-Fliess series computation
upload_time2024-07-17 21:52:54
maintainerNone
docs_urlNone
authorIvan Perez Avellaneda
requires_pythonNone
licenseMIT
keywords chen-fliess series nonlinear system input-output system odes control system system theory python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <div align="center">
<img src="https://raw.githubusercontent.com/iperezav/CFSpy/main/logo/CFSpy_logo.png" alt="CFSpy" / >

---

[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/cfspy)][py-versions]
[![PyPI - Version](https://img.shields.io/pypi/v/cfspy)][pypi-latest-version]
![PyPI - Status](https://img.shields.io/pypi/status/cfspy)
[![PyPI - Downloads](https://img.shields.io/pypi/dd/cfspy)][downloads]
[![PyPI - License](https://img.shields.io/pypi/l/cfspy)][license]

</div>

# CFSpy

CFSpy is a package to simulate the output of a control system by means of the Chen-Fliess series.

It provides:

- The list of iterated integrals indexed by words of a certain length or less. 
- The list of Lie derivatives indexed by words of a certain length or less.
- A single iterated integral indexed by a given word.
- A single Lie derivative indexed by a given word.


## Overview

CFSpy is a Python library that contains the following functions:

| Function | Description |
| ---- | --- |
| [**iter_int**](https://github.com/iperezav/CFSpy/blob/main/build/lib/CFS/iter_int.py) | A function for the numerical computation of a list of iterated integrals |
| [**iter_lie**](https://github.com/iperezav/CFSpy/blob/main/build/lib/CFS/iter_lie.py) | A function for the analytical computation of a list of Lie derivatives |
| [**single_iter_int**](https://github.com/iperezav/CFSpy/blob/main/build/lib/CFS/single_iter_int.py) | A function for the numerical computation of a single iterated integral |
| [**single_iter_lie**](https://github.com/iperezav/CFSpy/blob/main/build/lib/CFS/single_iter_lie.py) | A function for the analytical computation of a single Lie derivative |

CFSpy is used for:

- Simulation of the output of a control systems.
- Reachability analysis of a control system.


# Installation 
Currently, `CFSpy` supports releases of Python 3.12.4 onwards.
To install the current release:

```shell
$ pip install --upgrade CFSpy
```


# Getting Started

## Minimal Example
```python
from CFS import iter_int, iter_lie, single_iter_int, single_iter_lie

import numpy as np
from scipy.integrate import solve_ivp
import matplotlib.pyplot as plt
import sympy as sp

# Define the Lotka-Volterra system
def system(t, x, u1_func, u2_func):
    x1, x2 = x
    u1 = u1_func(t)
    u2 = u2_func(t)
    dx1 = -x1*x2 +  x1 * u1
    dx2 = x1*x2 - x2* u2
    return [dx1, dx2]

# Input 1
def u1_func(t):
    return np.sin(t)

# Input 2
def u2_func(t):
    return np.cos(t)

# Initial condition
x0 = [1/3,2/3]

# Time range
t0 = 0
tf = 3
dt = 0.001
t_span = (t0, tf)

# Simulation of the system
solution = solve_ivp(system, t_span, x0, args=(u1_func, u2_func), dense_output=True)

# Partition of the time interval
t = np.linspace(t_span[0], t_span[1], int((tf-t0)//dt+1))
y = solution.sol(t)

# Define the symbolic variables
x1, x2 = sp.symbols('x1 x2')
x = sp.Matrix([x1, x2])


# Define the system symbolically
g = sp.transpose(sp.Matrix([[-x1*x2, x1*x2], [x1, 0], [0, - x2]]))

# Define the output symbolically
h = x1

# The truncation of the length of the words that index the Chen-Fliess series
Ntrunc = 4

# Coefficients of the Chen-Fliess series evaluated at the initial state
Ceta = np.array(iter_lie(h,g,x,Ntrunc).subs([(x[0], 1/3),(x[1], 2/3)]))

# inputs as arrays
u1 = np.sin(t)
u2 = np.cos(t)

# input array
u = np.vstack([u1, u2])

# List of iterated integral
Eu = iter_int(u,t0, tf, dt, Ntrunc)

# Chen-Fliess series
F_cu = x0[0]+np.sum(Ceta*Eu, axis = 0)

# Graph of the output and the Chen-Fliess series
plt.figure(figsize = (12,5))
plt.plot(t, y[0].T)
plt.plot(t, F_cu, color='red', linewidth=5, linestyle = '--', alpha = 0.5)
plt.xlabel('$t$')
plt.ylabel('$x_1$')
plt.legend(['Output of the system','Chen-Fliess series'])
plt.grid()
plt.show()
```
<img src="https://raw.githubusercontent.com/iperezav/CFSpy/main/examples/output_chenfliess.png" alt="iter_int(), iter_lie()" />

For more examples, see the [CFSpy demos](https://github.com/iperezav/CFSpy/blob/main/examples/)


# Resources

- [**PyPi**](https://pypi.org/project/CFSpy/)
- [**Documentation**](https://github.com/iperezav/CFSpy/blob/main/README.md)
- [**Issue tracking**](https://github.com/iperezav/CFSpy/issues)


# Contributing

All feedback is welcome. 


# Asking for help
Please reach out if you have any questions:
1. [Github CFSpy discussions](https://github.com/iperezav/CFSpy/discussions/).
2. [Github CFSpy issues](https://github.com/iperezav/CFSpy/issues).


# License

CFSpy is open-source and released under the [MIT License](LICENSE).


# BibTeX
Feel free to cite my work:

```bibtex
@article{iperezave,
  title={CFSpy},
  author={Perez Avellaneda, Ivan},
  journal={GitHub. Note: https://github.com/iperezav/CFSpy},
  volume={1},
  year={2024}
}
```

[issues]: https://github.com/iperezav/CFSpy/issues
[demos]: https://github.com/iperezav/CFSpy/blob/main/examples/

[downloads]: https://pepy.tech/projects/cfspy
[py-versions]: https://pypi.org/project/cfspy/
[pypi-latest-version]: https://pypi.org/project/cfspy/
[license]: https://github.com/iperezav/CFSpy/blob/main/LICENSE

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/iperezav/CFSpy/",
    "name": "CFSpy",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "Chen-Fliess series, nonlinear system, input-output system, ODEs, control system, system theory, python",
    "author": "Ivan Perez Avellaneda",
    "author_email": "<iperezave@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/79/95/dedfeae9fee545b37d29cba99846bbf0e6bb1baa09dec3aa084d390acfdf/cfspy-1.0.13.tar.gz",
    "platform": null,
    "description": "<div align=\"center\">\r\n<img src=\"https://raw.githubusercontent.com/iperezav/CFSpy/main/logo/CFSpy_logo.png\" alt=\"CFSpy\" / >\r\n\r\n---\r\n\r\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/cfspy)][py-versions]\r\n[![PyPI - Version](https://img.shields.io/pypi/v/cfspy)][pypi-latest-version]\r\n![PyPI - Status](https://img.shields.io/pypi/status/cfspy)\r\n[![PyPI - Downloads](https://img.shields.io/pypi/dd/cfspy)][downloads]\r\n[![PyPI - License](https://img.shields.io/pypi/l/cfspy)][license]\r\n\r\n</div>\r\n\r\n# CFSpy\r\n\r\nCFSpy is a package to simulate the output of a control system by means of the Chen-Fliess series.\r\n\r\nIt provides:\r\n\r\n- The list of iterated integrals indexed by words of a certain length or less. \r\n- The list of Lie derivatives indexed by words of a certain length or less.\r\n- A single iterated integral indexed by a given word.\r\n- A single Lie derivative indexed by a given word.\r\n\r\n\r\n## Overview\r\n\r\nCFSpy is a Python library that contains the following functions:\r\n\r\n| Function | Description |\r\n| ---- | --- |\r\n| [**iter_int**](https://github.com/iperezav/CFSpy/blob/main/build/lib/CFS/iter_int.py) | A function for the numerical computation of a list of iterated integrals |\r\n| [**iter_lie**](https://github.com/iperezav/CFSpy/blob/main/build/lib/CFS/iter_lie.py) | A function for the analytical computation of a list of Lie derivatives |\r\n| [**single_iter_int**](https://github.com/iperezav/CFSpy/blob/main/build/lib/CFS/single_iter_int.py) | A function for the numerical computation of a single iterated integral |\r\n| [**single_iter_lie**](https://github.com/iperezav/CFSpy/blob/main/build/lib/CFS/single_iter_lie.py) | A function for the analytical computation of a single Lie derivative |\r\n\r\nCFSpy is used for:\r\n\r\n- Simulation of the output of a control systems.\r\n- Reachability analysis of a control system.\r\n\r\n\r\n# Installation \r\nCurrently, `CFSpy` supports releases of Python 3.12.4 onwards.\r\nTo install the current release:\r\n\r\n```shell\r\n$ pip install --upgrade CFSpy\r\n```\r\n\r\n\r\n# Getting Started\r\n\r\n## Minimal Example\r\n```python\r\nfrom CFS import iter_int, iter_lie, single_iter_int, single_iter_lie\r\n\r\nimport numpy as np\r\nfrom scipy.integrate import solve_ivp\r\nimport matplotlib.pyplot as plt\r\nimport sympy as sp\r\n\r\n# Define the Lotka-Volterra system\r\ndef system(t, x, u1_func, u2_func):\r\n    x1, x2 = x\r\n    u1 = u1_func(t)\r\n    u2 = u2_func(t)\r\n    dx1 = -x1*x2 +  x1 * u1\r\n    dx2 = x1*x2 - x2* u2\r\n    return [dx1, dx2]\r\n\r\n# Input 1\r\ndef u1_func(t):\r\n    return np.sin(t)\r\n\r\n# Input 2\r\ndef u2_func(t):\r\n    return np.cos(t)\r\n\r\n# Initial condition\r\nx0 = [1/3,2/3]\r\n\r\n# Time range\r\nt0 = 0\r\ntf = 3\r\ndt = 0.001\r\nt_span = (t0, tf)\r\n\r\n# Simulation of the system\r\nsolution = solve_ivp(system, t_span, x0, args=(u1_func, u2_func), dense_output=True)\r\n\r\n# Partition of the time interval\r\nt = np.linspace(t_span[0], t_span[1], int((tf-t0)//dt+1))\r\ny = solution.sol(t)\r\n\r\n# Define the symbolic variables\r\nx1, x2 = sp.symbols('x1 x2')\r\nx = sp.Matrix([x1, x2])\r\n\r\n\r\n# Define the system symbolically\r\ng = sp.transpose(sp.Matrix([[-x1*x2, x1*x2], [x1, 0], [0, - x2]]))\r\n\r\n# Define the output symbolically\r\nh = x1\r\n\r\n# The truncation of the length of the words that index the Chen-Fliess series\r\nNtrunc = 4\r\n\r\n# Coefficients of the Chen-Fliess series evaluated at the initial state\r\nCeta = np.array(iter_lie(h,g,x,Ntrunc).subs([(x[0], 1/3),(x[1], 2/3)]))\r\n\r\n# inputs as arrays\r\nu1 = np.sin(t)\r\nu2 = np.cos(t)\r\n\r\n# input array\r\nu = np.vstack([u1, u2])\r\n\r\n# List of iterated integral\r\nEu = iter_int(u,t0, tf, dt, Ntrunc)\r\n\r\n# Chen-Fliess series\r\nF_cu = x0[0]+np.sum(Ceta*Eu, axis = 0)\r\n\r\n# Graph of the output and the Chen-Fliess series\r\nplt.figure(figsize = (12,5))\r\nplt.plot(t, y[0].T)\r\nplt.plot(t, F_cu, color='red', linewidth=5, linestyle = '--', alpha = 0.5)\r\nplt.xlabel('$t$')\r\nplt.ylabel('$x_1$')\r\nplt.legend(['Output of the system','Chen-Fliess series'])\r\nplt.grid()\r\nplt.show()\r\n```\r\n<img src=\"https://raw.githubusercontent.com/iperezav/CFSpy/main/examples/output_chenfliess.png\" alt=\"iter_int(), iter_lie()\" />\r\n\r\nFor more examples, see the [CFSpy demos](https://github.com/iperezav/CFSpy/blob/main/examples/)\r\n\r\n\r\n# Resources\r\n\r\n- [**PyPi**](https://pypi.org/project/CFSpy/)\r\n- [**Documentation**](https://github.com/iperezav/CFSpy/blob/main/README.md)\r\n- [**Issue tracking**](https://github.com/iperezav/CFSpy/issues)\r\n\r\n\r\n# Contributing\r\n\r\nAll feedback is welcome. \r\n\r\n\r\n# Asking for help\r\nPlease reach out if you have any questions:\r\n1. [Github CFSpy discussions](https://github.com/iperezav/CFSpy/discussions/).\r\n2. [Github CFSpy issues](https://github.com/iperezav/CFSpy/issues).\r\n\r\n\r\n# License\r\n\r\nCFSpy is open-source and released under the [MIT License](LICENSE).\r\n\r\n\r\n# BibTeX\r\nFeel free to cite my work:\r\n\r\n```bibtex\r\n@article{iperezave,\r\n  title={CFSpy},\r\n  author={Perez Avellaneda, Ivan},\r\n  journal={GitHub. Note: https://github.com/iperezav/CFSpy},\r\n  volume={1},\r\n  year={2024}\r\n}\r\n```\r\n\r\n[issues]: https://github.com/iperezav/CFSpy/issues\r\n[demos]: https://github.com/iperezav/CFSpy/blob/main/examples/\r\n\r\n[downloads]: https://pepy.tech/projects/cfspy\r\n[py-versions]: https://pypi.org/project/cfspy/\r\n[pypi-latest-version]: https://pypi.org/project/cfspy/\r\n[license]: https://github.com/iperezav/CFSpy/blob/main/LICENSE\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Chen-Fliess series computation",
    "version": "1.0.13",
    "project_urls": {
        "Homepage": "https://github.com/iperezav/CFSpy/"
    },
    "split_keywords": [
        "chen-fliess series",
        " nonlinear system",
        " input-output system",
        " odes",
        " control system",
        " system theory",
        " python"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c12480ec053a041ea577e81349cc3211309625dc6b2e707bda2918cca5058d29",
                "md5": "d115364df7eb00d835bc224a3d3bd116",
                "sha256": "7be4cd1a168b4a450d6c4bb8a9f3bb5fa587587516e6d5cff73d3cd37c91ffc8"
            },
            "downloads": -1,
            "filename": "CFSpy-1.0.13-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d115364df7eb00d835bc224a3d3bd116",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 10045,
            "upload_time": "2024-07-17T21:52:51",
            "upload_time_iso_8601": "2024-07-17T21:52:51.921548Z",
            "url": "https://files.pythonhosted.org/packages/c1/24/80ec053a041ea577e81349cc3211309625dc6b2e707bda2918cca5058d29/CFSpy-1.0.13-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7995dedfeae9fee545b37d29cba99846bbf0e6bb1baa09dec3aa084d390acfdf",
                "md5": "e54dccdcb57d64b1e00668f3b08bbe34",
                "sha256": "d4dad963cc51d448032552290aa7c42b74d44e5151a2a701b844146e94f3aa13"
            },
            "downloads": -1,
            "filename": "cfspy-1.0.13.tar.gz",
            "has_sig": false,
            "md5_digest": "e54dccdcb57d64b1e00668f3b08bbe34",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 8257,
            "upload_time": "2024-07-17T21:52:54",
            "upload_time_iso_8601": "2024-07-17T21:52:54.499915Z",
            "url": "https://files.pythonhosted.org/packages/79/95/dedfeae9fee545b37d29cba99846bbf0e6bb1baa09dec3aa084d390acfdf/cfspy-1.0.13.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-17 21:52:54",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "iperezav",
    "github_project": "CFSpy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "cfspy"
}
        
Elapsed time: 0.29139s