{"id":13688691,"url":"https://github.com/google-research/torchsde","last_synced_at":"2025-05-14T06:11:31.750Z","repository":{"id":40601337,"uuid":"277667727","full_name":"google-research/torchsde","owner":"google-research","description":"Differentiable SDE solvers with GPU support and efficient sensitivity analysis. ","archived":false,"fork":false,"pushed_at":"2024-05-25T02:57:17.000Z","size":4372,"stargazers_count":1573,"open_issues_count":29,"forks_count":199,"subscribers_count":34,"default_branch":"master","last_synced_at":"2024-10-29T15:35:09.357Z","etag":null,"topics":["deep-learning","deep-neural-networks","differential-equations","dynamical-systems","neural-differential-equations","pytorch","stochastic-differential-equations","stochastic-processes","stochastic-volatility-models"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/google-research.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-06T23:13:11.000Z","updated_at":"2024-10-29T02:48:01.000Z","dependencies_parsed_at":"2024-11-19T05:50:53.054Z","dependency_job_id":null,"html_url":"https://github.com/google-research/torchsde","commit_stats":{"total_commits":151,"total_committers":9,"mean_commits":16.77777777777778,"dds":0.4437086092715232,"last_synced_commit":"45e68becac83fac90f4bc42696cb96e73e26cea6"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google-research%2Ftorchsde","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google-research%2Ftorchsde/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google-research%2Ftorchsde/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google-research%2Ftorchsde/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/google-research","download_url":"https://codeload.github.com/google-research/torchsde/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254079974,"owners_count":22011299,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deep-learning","deep-neural-networks","differential-equations","dynamical-systems","neural-differential-equations","pytorch","stochastic-differential-equations","stochastic-processes","stochastic-volatility-models"],"created_at":"2024-08-02T15:01:20.279Z","updated_at":"2025-05-14T06:11:31.730Z","avatar_url":"https://github.com/google-research.png","language":"Python","funding_links":[],"categories":["Software and Libraries","Additional Material","Pytorch实用程序","Python"],"sub_categories":["Python","Software and Libraries"],"readme":"# PyTorch Implementation of Differentiable SDE Solvers ![Python package](https://github.com/google-research/torchsde/actions/workflows/run_tests.yml/badge.svg)\nThis library provides [stochastic differential equation (SDE)](https://en.wikipedia.org/wiki/Stochastic_differential_equation) solvers with GPU support and efficient backpropagation.\n\n---\n\u003cp align=\"center\"\u003e\n  \u003cimg width=\"600\" height=\"450\" src=\"./assets/latent_sde.gif\"\u003e\n\u003c/p\u003e\n\n## Installation\n```shell script\npip install torchsde\n```\n\n**Requirements:** Python \u003e=3.8 and PyTorch \u003e=1.6.0.\n\n## Documentation\nAvailable [here](./DOCUMENTATION.md).\n\n## Examples\n### Quick example\n```python\nimport torch\nimport torchsde\n\nbatch_size, state_size, brownian_size = 32, 3, 2\nt_size = 20\n\nclass SDE(torch.nn.Module):\n    noise_type = 'general'\n    sde_type = 'ito'\n\n    def __init__(self):\n        super().__init__()\n        self.mu = torch.nn.Linear(state_size, \n                                  state_size)\n        self.sigma = torch.nn.Linear(state_size, \n                                     state_size * brownian_size)\n\n    # Drift\n    def f(self, t, y):\n        return self.mu(y)  # shape (batch_size, state_size)\n\n    # Diffusion\n    def g(self, t, y):\n        return self.sigma(y).view(batch_size, \n                                  state_size, \n                                  brownian_size)\n\nsde = SDE()\ny0 = torch.full((batch_size, state_size), 0.1)\nts = torch.linspace(0, 1, t_size)\n# Initial state y0, the SDE is solved over the interval [ts[0], ts[-1]].\n# ys will have shape (t_size, batch_size, state_size)\nys = torchsde.sdeint(sde, y0, ts)\n```\n\n### Notebook\n\n[`examples/demo.ipynb`](examples/demo.ipynb) gives a short guide on how to solve SDEs, including subtle points such as fixing the randomness in the solver and the choice of *noise types*.\n\n### Latent SDE\n\n[`examples/latent_sde.py`](examples/latent_sde.py) learns a *latent stochastic differential equation*, as in Section 5 of [\\[1\\]](https://arxiv.org/pdf/2001.01328.pdf).\nThe example fits an SDE to data, whilst regularizing it to be like an [Ornstein-Uhlenbeck](https://en.wikipedia.org/wiki/Ornstein%E2%80%93Uhlenbeck_process) prior process.\nThe model can be loosely viewed as a [variational autoencoder](https://en.wikipedia.org/wiki/Autoencoder#Variational_autoencoder_(VAE)) with its prior and approximate posterior being SDEs. This example can be run via\n```shell script\npython -m examples.latent_sde --train-dir \u003cTRAIN_DIR\u003e\n```\nThe program outputs figures to the path specified by `\u003cTRAIN_DIR\u003e`.\nTraining should stabilize after 500 iterations with the default hyperparameters.\n\n### Neural SDEs as GANs\n[`examples/sde_gan.py`](examples/sde_gan.py) learns an SDE as a GAN, as in [\\[2\\]](https://arxiv.org/abs/2102.03657), [\\[3\\]](https://arxiv.org/abs/2105.13493). The example trains an SDE as the generator of a GAN, whilst using a [neural CDE](https://github.com/patrick-kidger/NeuralCDE) [\\[4\\]](https://arxiv.org/abs/2005.08926) as the discriminator. This example can be run via\n\n```shell script\npython -m examples.sde_gan\n```\n\n## Citation\n\nIf you found this codebase useful in your research, please consider citing either or both of:\n\n```\n@article{li2020scalable,\n  title={Scalable gradients for stochastic differential equations},\n  author={Li, Xuechen and Wong, Ting-Kam Leonard and Chen, Ricky T. Q. and Duvenaud, David},\n  journal={International Conference on Artificial Intelligence and Statistics},\n  year={2020}\n}\n```\n\n```\n@article{kidger2021neuralsde,\n  title={Neural {SDE}s as {I}nfinite-{D}imensional {GAN}s},\n  author={Kidger, Patrick and Foster, James and Li, Xuechen and Oberhauser, Harald and Lyons, Terry},\n  journal={International Conference on Machine Learning},\n  year={2021}\n}\n```\n\n## References\n\n\\[1\\] Xuechen Li, Ting-Kam Leonard Wong, Ricky T. Q. Chen, David Duvenaud. \"Scalable Gradients for Stochastic Differential Equations\". *International Conference on Artificial Intelligence and Statistics.* 2020. [[arXiv]](https://arxiv.org/pdf/2001.01328.pdf)\n\n\\[2\\] Patrick Kidger, James Foster, Xuechen Li, Harald Oberhauser, Terry Lyons. \"Neural SDEs as Infinite-Dimensional GANs\". *International Conference on Machine Learning* 2021. [[arXiv]](https://arxiv.org/abs/2102.03657)\n\n\\[3\\] Patrick Kidger, James Foster, Xuechen Li, Terry Lyons. \"Efficient and Accurate Gradients for Neural SDEs\". 2021. [[arXiv]](https://arxiv.org/abs/2105.13493)\n\n\\[4\\] Patrick Kidger, James Morrill, James Foster, Terry Lyons, \"Neural Controlled Differential Equations for Irregular Time Series\". *Neural Information Processing Systems* 2020. [[arXiv]](https://arxiv.org/abs/2005.08926)\n\n---\nThis is a research project, not an official Google product. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoogle-research%2Ftorchsde","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoogle-research%2Ftorchsde","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoogle-research%2Ftorchsde/lists"}