njet


Namenjet JSON
Version 0.5.1 PyPI version JSON
download
home_page
SummaryLightweight automatic differentiation package for higher-order differentiation.
upload_time2023-03-28 19:06:32
maintainer
docs_urlNone
authorMalte Titze
requires_python<3.11,>=3.8
licenseGPL-3.0-or-later
keywords ad jet njet automatic differentiation
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![Documentation Status](https://readthedocs.org/projects/njet/badge/?version=latest)](https://njet.readthedocs.io/en/latest/?badge=latest)

# njet: Lightweight automatic differentiation

A lightweight AD package, using forward-mode automatic differentiation, in order to determine the
higher-order derivatives of a given function in several variables.

## Features

- Higher-order (forward-mode) automatic differentiation in several variables.
- Support for NumPy, SymPy and mpmath.
- Differentiation of expressions containing nested higher-order derivatives.
- Complex differentiation (Wirtinger calculus) possible.
- Faa di Bruno's formula for vector-valued functions implemented.
- Lightweight and easy to use.

## Installation

Install this module with pip

```sh
pip install njet
```

## Quickstart

An example function we want to differentiate
```python
from njet.functions import exp
f = lambda x, y, z: exp(-0.23*x**2 - 0.33*x*y - 0.11*z**2)
```

Generate a class to handle the derivatives of the given function (in this example up to order 3)
```python
from njet import derive
df = derive(f, order=3)
```

Evaluate the derivatives at a specific point
```python
df(0.4, 2.1, 1.73)

{(0, 0, 0): 0.5255977986928584,
 (0, 0, 1): -0.2000425221825019,
 (1, 0, 0): -0.46094926945363685,
 (0, 1, 0): -0.06937890942745731,
 (0, 0, 2): -0.03949533176976862,
 (0, 2, 0): 0.009158016044424365,
 (1, 0, 1): 0.1754372919540542,
 (0, 1, 1): 0.026405612928090252,
 (2, 0, 0): 0.1624775219121247,
 (1, 1, 0): -0.11260197000076322,
 (2, 1, 0): 0.2827794849469999,
 (1, 1, 1): 0.04285630978229049,
 (0, 1, 2): 0.005213383793609458,
 (0, 2, 1): -0.0034855409065079135,
 (0, 3, 0): -0.0012088581178640162,
 (3, 0, 0): 0.2815805411804125,
 (2, 0, 1): -0.061838944839754675,
 (0, 0, 3): 0.10305063303187477,
 (1, 2, 0): 0.03775850015116166,
 (1, 0, 2): 0.034637405962087094}
```
The indices here correspond to the powers of the variables x, y, z
in the multivariate Taylor expansion. They can be translated to
the tensor indices of the corresponding multilinear map using a
built-in routine. Example:

Obtain the gradient and the Hessian
```python
df.grad()

{(2,): -0.2000425221825019,
 (0,): -0.46094926945363685,
 (1,): -0.06937890942745731}
```

```python
df.hess()

{(2, 2): -0.03949533176976862,
 (1, 1): 0.009158016044424365,
 (0, 2): 0.1754372919540542,
 (1, 2): 0.026405612928090252,
 (0, 0): 0.1624775219121247,
 (0, 1): -0.11260197000076322}
```

## Further reading

https://njet.readthedocs.io/en/latest/index.html

## License

njet: Automatic Differentiation Library

Copyright (C) 2021, 2022, 2023 by Malte Titze

njet is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

njet is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with njet. If not, see <https://www.gnu.org/licenses/>.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "njet",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "<3.11,>=3.8",
    "maintainer_email": "",
    "keywords": "AD jet njet automatic differentiation",
    "author": "Malte Titze",
    "author_email": "mtitze@users.noreply.github.com",
    "download_url": "https://files.pythonhosted.org/packages/98/a1/abd4b7d180ebbbc1da9caa2962526a3f15453b0b9860e5da6de0be4fd2bd/njet-0.5.1.tar.gz",
    "platform": null,
    "description": "[![Documentation Status](https://readthedocs.org/projects/njet/badge/?version=latest)](https://njet.readthedocs.io/en/latest/?badge=latest)\n\n# njet: Lightweight automatic differentiation\n\nA lightweight AD package, using forward-mode automatic differentiation, in order to determine the\nhigher-order derivatives of a given function in several variables.\n\n## Features\n\n- Higher-order (forward-mode) automatic differentiation in several variables.\n- Support for NumPy, SymPy and mpmath.\n- Differentiation of expressions containing nested higher-order derivatives.\n- Complex differentiation (Wirtinger calculus) possible.\n- Faa di Bruno's formula for vector-valued functions implemented.\n- Lightweight and easy to use.\n\n## Installation\n\nInstall this module with pip\n\n```sh\npip install njet\n```\n\n## Quickstart\n\nAn example function we want to differentiate\n```python\nfrom njet.functions import exp\nf = lambda x, y, z: exp(-0.23*x**2 - 0.33*x*y - 0.11*z**2)\n```\n\nGenerate a class to handle the derivatives of the given function (in this example up to order 3)\n```python\nfrom njet import derive\ndf = derive(f, order=3)\n```\n\nEvaluate the derivatives at a specific point\n```python\ndf(0.4, 2.1, 1.73)\n\n{(0, 0, 0): 0.5255977986928584,\n (0, 0, 1): -0.2000425221825019,\n (1, 0, 0): -0.46094926945363685,\n (0, 1, 0): -0.06937890942745731,\n (0, 0, 2): -0.03949533176976862,\n (0, 2, 0): 0.009158016044424365,\n (1, 0, 1): 0.1754372919540542,\n (0, 1, 1): 0.026405612928090252,\n (2, 0, 0): 0.1624775219121247,\n (1, 1, 0): -0.11260197000076322,\n (2, 1, 0): 0.2827794849469999,\n (1, 1, 1): 0.04285630978229049,\n (0, 1, 2): 0.005213383793609458,\n (0, 2, 1): -0.0034855409065079135,\n (0, 3, 0): -0.0012088581178640162,\n (3, 0, 0): 0.2815805411804125,\n (2, 0, 1): -0.061838944839754675,\n (0, 0, 3): 0.10305063303187477,\n (1, 2, 0): 0.03775850015116166,\n (1, 0, 2): 0.034637405962087094}\n```\nThe indices here correspond to the powers of the variables x, y, z\nin the multivariate Taylor expansion. They can be translated to\nthe tensor indices of the corresponding multilinear map using a\nbuilt-in routine. Example:\n\nObtain the gradient and the Hessian\n```python\ndf.grad()\n\n{(2,): -0.2000425221825019,\n (0,): -0.46094926945363685,\n (1,): -0.06937890942745731}\n```\n\n```python\ndf.hess()\n\n{(2, 2): -0.03949533176976862,\n (1, 1): 0.009158016044424365,\n (0, 2): 0.1754372919540542,\n (1, 2): 0.026405612928090252,\n (0, 0): 0.1624775219121247,\n (0, 1): -0.11260197000076322}\n```\n\n## Further reading\n\nhttps://njet.readthedocs.io/en/latest/index.html\n\n## License\n\nnjet: Automatic Differentiation Library\n\nCopyright (C) 2021, 2022, 2023 by Malte Titze\n\nnjet is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nnjet is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with njet. If not, see <https://www.gnu.org/licenses/>.\n",
    "bugtrack_url": null,
    "license": "GPL-3.0-or-later",
    "summary": "Lightweight automatic differentiation package for higher-order differentiation.",
    "version": "0.5.1",
    "split_keywords": [
        "ad",
        "jet",
        "njet",
        "automatic",
        "differentiation"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e409a8ec59f068f59aeafa595ad2333e673ab084ee4dbc2b9177c3ff06b5f116",
                "md5": "7b7af27b3a56aec1ac9b0d3165e34efd",
                "sha256": "179bb42b177ffd86482690339a6246e6a0637580fd3462e4301ae351f93fdcbd"
            },
            "downloads": -1,
            "filename": "njet-0.5.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7b7af27b3a56aec1ac9b0d3165e34efd",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<3.11,>=3.8",
            "size": 62683,
            "upload_time": "2023-03-28T19:06:30",
            "upload_time_iso_8601": "2023-03-28T19:06:30.235527Z",
            "url": "https://files.pythonhosted.org/packages/e4/09/a8ec59f068f59aeafa595ad2333e673ab084ee4dbc2b9177c3ff06b5f116/njet-0.5.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "98a1abd4b7d180ebbbc1da9caa2962526a3f15453b0b9860e5da6de0be4fd2bd",
                "md5": "42853cccb00543142e9788196123a057",
                "sha256": "8c53a832ef1125c9e91a61e72ee6549a68fe91934a9d48c08f531a1fef540063"
            },
            "downloads": -1,
            "filename": "njet-0.5.1.tar.gz",
            "has_sig": false,
            "md5_digest": "42853cccb00543142e9788196123a057",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<3.11,>=3.8",
            "size": 89659,
            "upload_time": "2023-03-28T19:06:32",
            "upload_time_iso_8601": "2023-03-28T19:06:32.867987Z",
            "url": "https://files.pythonhosted.org/packages/98/a1/abd4b7d180ebbbc1da9caa2962526a3f15453b0b9860e5da6de0be4fd2bd/njet-0.5.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-28 19:06:32",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "njet"
}
        
Elapsed time: 0.59663s