https://github.com/i-a-morozov/ndmap
Higher order partial derivatives computation with respect to one or several tensor-like variables, applications to nonlinear dynamics
https://github.com/i-a-morozov/ndmap
automatic-differentiation fixed-point nonlinear-dynamics pytorch
Last synced: 9 months ago
JSON representation
Higher order partial derivatives computation with respect to one or several tensor-like variables, applications to nonlinear dynamics
- Host: GitHub
- URL: https://github.com/i-a-morozov/ndmap
- Owner: i-a-morozov
- License: mit
- Created: 2023-01-30T05:09:03.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-10-28T05:43:45.000Z (over 1 year ago)
- Last Synced: 2025-01-18T08:44:37.616Z (over 1 year ago)
- Topics: automatic-differentiation, fixed-point, nonlinear-dynamics, pytorch
- Language: Python
- Homepage:
- Size: 24.1 MB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.MD
- License: LICENSE
Awesome Lists containing this project
README
# ndmap, 2022-2023
Higher order partial derivatives computation with respect to one or several tensor-like variables.
Taylor series function approximation (derivative table and series function representation).
Parametric fixed point computation.
# Install & build
```
$ pip install git+https://github.com/i-a-morozov/ndmap.git@main
```
or
```
$ pip install ndmap -U
```
# Documentation
[](https://colab.research.google.com/github/i-a-morozov/ndmap/blob/main/docs/source/examples/ndmap.ipynb)
[https://i-a-morozov.github.io/ndmap/](https://i-a-morozov.github.io/ndmap/)
# Derivative (composable jacobian)
Compute higher order function (partial) derivatives.
```python
>>> from ndmap.derivative import derivative
>>> def fn(x):
... return 1 + x + x**2 + x**3 + x**4 + x**5
...
>>> import torch
>>> x = torch.tensor(0.0)
>>> derivative(5, fn, x)
[tensor(1.), tensor(1.), tensor(2.), tensor(6.), tensor(24.), tensor(120.)]
```
```python
>>> from ndmap.derivative import derivative
>>> def fn(x):
... x1, x2 = x
... return x1**2 + x1*x2 + x2**2
...
>>> import torch
>>> x = torch.tensor([0.0, 0.0])
>>> derivative(2, fn, x, intermediate=False)
tensor([[2., 1.],
[1., 2.]])
```
```python
>>> from ndmap.derivative import derivative
>>> def fn(x, y):
... x1, x2 = x
... return x1**2*(1 + y) + x2**2*(1 - y)
...
>>> import torch
>>> x = torch.tensor([0.0, 0.0])
>>> y = torch.tensor(0.0)
>>> derivative((2, 1), fn, x, y)
[[tensor(0.), tensor(0.)], [tensor([0., 0.]), tensor([0., 0.])], [tensor([[2., 0.],
[0., 2.]]), tensor([[ 2., 0.],
[ 0., -2.]])]]
```
# Derivative (gradient)
Compute higher order function (partial) derivatives.
```python
>>> from ndmap.gradient import series
>>> def fn(x):
... return 1 + x + x**2 + x**3 + x**4 + x**5
...
>>> import torch
>>> x = torch.tensor([0.0])
>>> series((5, ), fn, x, retain=False, series=False)
{(0,): tensor([1.]),
(1,): tensor([1.]),
(2,): tensor([2.]),
(3,): tensor([6.]),
(4,): tensor([24.]),
(5,): tensor([120.])}
```
```python
>>> from ndmap.gradient import series
>>> def fn(x):
... x1, x2 = x
... return x1**2 + x1*x2 + x2**2
...
>>> import torch
>>> x = torch.tensor([0.0, 0.0])
>>> series((2, ), fn, x, intermediate=False, retain=False, series=False)
{(2, 0): tensor(2.), (1, 1): tensor(1.), (0, 2): tensor(2.)}
```
```python
>>> from ndmap.gradient import series
>>> def fn(x, y):
... x1, x2 = x
... y1, = y
... return x1**2*(1 + y1) + x2**2*(1 - y1)
...
>>> import torch
>>> x = torch.tensor([0.0, 0.0])
>>> y = torch.tensor([0.0])
>>> series((2, 1), fn, x, y, retain=False, series=False)
{(0, 0, 0): tensor(0.),
(0, 0, 1): tensor(0.),
(1, 0, 0): tensor(0.),
(0, 1, 0): tensor(0.),
(1, 0, 1): tensor(0.),
(0, 1, 1): tensor(-0.),
(2, 0, 0): tensor(2.),
(1, 1, 0): tensor(0.),
(0, 2, 0): tensor(2.),
(2, 0, 1): tensor(2.),
(1, 1, 1): tensor(0.),
(0, 2, 1): tensor(-2.)}
```
# Desription
```python
>>> import ndmap
>>> ndmap.__about__
```
# Animations
Stable and unstable invariant manifolds approximation
Collision of fixed points
Reduce real part of a hyperbolic fixed point