paramfittorchdemo
================
<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->
This file will become your README and also the index of your
documentation.
## Install
``` sh
pip install paramfittorchdemo
```
## How to use
Using the integration routines in the library torchdiffeq we can
integrate differential equations using torch modules as the base class
for describing the systems. This allows for gradients to be computed
with respect to the model parameters. This can be combined with the
local optimization schemes used to train neural networks to give a
powerful framework for fitting differential equation models found in the
scientific literature.
In this package I provide a few example systems and parameter fitting
routines for fitting the parameters.
The below code demonstrates how the van der Pol oscillator system
defined as \`torch.nn.module1 can be integrated against inside of
pytorch.
``` python
import torch
from torchdiffeq import odeint_adjoint as odeint
import matplotlib.pyplot as plt
vdp_model = VDP(mu=0.5)
ts = torch.linspace(0,30.0,1000)
# Create a batch of initial conditions
batch_size = 30
initial_conditions = torch.tensor([0.01, 0.01]) + 0.2*torch.randn((batch_size,2))
sol = odeint(vdp_model, initial_conditions, ts, method='dopri5').detach().numpy()
# Check the solution
plt.plot(sol[:,:,0], sol[:,:,1], color='black', lw=0.5);
plt.title("Phase plot of the VDP oscillator");
plt.xlabel("x");
plt.ylabel("y");
```
![](index_files/figure-commonmark/cell-2-output-1.png)
The automatic batching dimensions means we can easily integrate a
collection of initial conditions at the same time using these routines
as well. The above shows the phase plane plot of the VDP oscillator for
30 random initial conditions.
Raw data
{
"_id": null,
"home_page": "https://github.com/khannay/paramfittorchdemo",
"name": "paramfittorchdemo",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": "",
"keywords": "nbdev jupyter notebook python",
"author": "Kevin Hannay",
"author_email": "13168556+khannay@users.noreply.github.com",
"download_url": "https://files.pythonhosted.org/packages/59/46/7b271dcc71340f687baa3df79ed9bc6e21330d19656c9d741cc70fb987b8/paramfittorchdemo-0.0.1.tar.gz",
"platform": null,
"description": "paramfittorchdemo\n================\n\n<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->\n\nThis file will become your README and also the index of your\ndocumentation.\n\n## Install\n\n``` sh\npip install paramfittorchdemo\n```\n\n## How to use\n\nUsing the integration routines in the library torchdiffeq we can\nintegrate differential equations using torch modules as the base class\nfor describing the systems. This allows for gradients to be computed\nwith respect to the model parameters. This can be combined with the\nlocal optimization schemes used to train neural networks to give a\npowerful framework for fitting differential equation models found in the\nscientific literature.\n\nIn this package I provide a few example systems and parameter fitting\nroutines for fitting the parameters.\n\nThe below code demonstrates how the van der Pol oscillator system\ndefined as \\`torch.nn.module1 can be integrated against inside of\npytorch.\n\n``` python\nimport torch \nfrom torchdiffeq import odeint_adjoint as odeint\nimport matplotlib.pyplot as plt\nvdp_model = VDP(mu=0.5)\nts = torch.linspace(0,30.0,1000)\n# Create a batch of initial conditions \nbatch_size = 30\ninitial_conditions = torch.tensor([0.01, 0.01]) + 0.2*torch.randn((batch_size,2))\nsol = odeint(vdp_model, initial_conditions, ts, method='dopri5').detach().numpy()\n\n\n# Check the solution\nplt.plot(sol[:,:,0], sol[:,:,1], color='black', lw=0.5);\nplt.title(\"Phase plot of the VDP oscillator\");\nplt.xlabel(\"x\");\nplt.ylabel(\"y\");\n```\n\n![](index_files/figure-commonmark/cell-2-output-1.png)\n\nThe automatic batching dimensions means we can easily integrate a\ncollection of initial conditions at the same time using these routines\nas well. The above shows the phase plane plot of the VDP oscillator for\n30 random initial conditions.\n\n\n",
"bugtrack_url": null,
"license": "Apache Software License 2.0",
"summary": "How to use pytorch to fit parameters of differential equations",
"version": "0.0.1",
"split_keywords": [
"nbdev",
"jupyter",
"notebook",
"python"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "17fbe89bdae2858ade7545173f35ba667bd63c8bd1aabacfddb275a9d883b26e",
"md5": "cf88bf98b5c8799a3673cf1faf15f73c",
"sha256": "70e905ca0de1b5490535bd7951af0d6f865ab388941313198ff6a15c11773df5"
},
"downloads": -1,
"filename": "paramfittorchdemo-0.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "cf88bf98b5c8799a3673cf1faf15f73c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 10288,
"upload_time": "2023-01-25T19:40:50",
"upload_time_iso_8601": "2023-01-25T19:40:50.570006Z",
"url": "https://files.pythonhosted.org/packages/17/fb/e89bdae2858ade7545173f35ba667bd63c8bd1aabacfddb275a9d883b26e/paramfittorchdemo-0.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "59467b271dcc71340f687baa3df79ed9bc6e21330d19656c9d741cc70fb987b8",
"md5": "77ea96d73e4d8ef747811b2fb3f33d01",
"sha256": "7f240d455f0eff274bca27dccd4371a56d8f538b984a2f4e1019d9f5d36884af"
},
"downloads": -1,
"filename": "paramfittorchdemo-0.0.1.tar.gz",
"has_sig": false,
"md5_digest": "77ea96d73e4d8ef747811b2fb3f33d01",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 10191,
"upload_time": "2023-01-25T19:40:52",
"upload_time_iso_8601": "2023-01-25T19:40:52.373941Z",
"url": "https://files.pythonhosted.org/packages/59/46/7b271dcc71340f687baa3df79ed9bc6e21330d19656c9d741cc70fb987b8/paramfittorchdemo-0.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-01-25 19:40:52",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "khannay",
"github_project": "paramfittorchdemo",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "paramfittorchdemo"
}