Exact OU processes with JAX
Project description
thermox
This package provides a very simple interface to exactly simulate Ornstein-Uhlenbeck (OU) processes of the form
$$ dx = - A(x - b) dt + \mathcal{N}(0, D dt) $$
To collect samples from this process, define sampling times ts, initial state x0, drift matrix A, displacement vector b, diffusion matrix D and a JAX random key. Then run thermox.sample:
thermox.sample(key, ts, x0, A, b, D)
Samples are then collected by exact diagonalization (therefore there is no discretization error) and JAX scans.
You can access log-probabilities of the OU process by running thermox.log_prob:
thermox.log_prob(ts, xs, A, b, D)
which can be useful for e.g. maximum likelihood estimation of the parameters A, b and D by composing with jax.grad.
Additionally thermox provides a scipy style suit of thermodynamic linear algebra primitives: thermox.linalg.solve, thermox.linalg.inv, thermox.linalg.expm and thermox.linalg.negexpm which all simulate an OU process under the hood. More details can be found in the thermo_linear_algebra.ipynb notebook.
Contributing
Before submitting any pull request, make sure to run pre-commit run --all-files.
Example usage
Here is a simple code example for a 5-dimensional OU process:
import thermox
import jax
import jax.numpy as jnp
import matplotlib.pyplot as plt
# Set random seed
key = jax.random.PRNGKey(0)
# Timeframe
dt = 0.01
ts = jnp.arange(0, 1, dt)
# System parameters for a 5-dimensional OU process
A = jnp.array([[2.0, 0.5, 0.0, 0.0, 0.0],
[0.5, 2.0, 0.5, 0.0, 0.0],
[0.0, 0.5, 2.0, 0.5, 0.0],
[0.0, 0.0, 0.5, 2.0, 0.5],
[0.0, 0.0, 0.0, 0.5, 2.0]])
b, x0 = jnp.zeros(5), jnp.zeros(5) # Zero drift displacement vector and initial state
# Diffusion matrix with correlations between x_1 and x_2
D = jnp.array([[2, 1, 0, 0, 0],
[1, 2, 0, 0, 0],
[0, 0, 2, 0, 0],
[0, 0, 0, 2, 0],
[0, 0, 0, 0, 2]])
# Collect samples
samples = thermox.sample(key, ts, x0, A, b, D)
plt.figure(figsize=(12, 5))
plt.plot(ts, samples, label=[f'Dimension {i+1}' for i in range(5)])
plt.xlabel('Time')
plt.ylabel('Value')
plt.title('Trajectories of 5-Dimensional OU Process')
plt.legend()
plt.show()
Citation
If you use thermox in your research, please cite the library using the following BibTeX entry:
@misc{duffield2024thermox,
title={thermox: Exact OU processes with JAX},
author={Duffield, Samuel and Donatella, Kaelan and Melanson, Denis},
howpublished={\url{https://github.com/normal-computing/thermox}},
year={2024}
}
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file thermox-0.0.5.tar.gz.
File metadata
- Download URL: thermox-0.0.5.tar.gz
- Upload date:
- Size: 14.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0756b355ced96eca2aaec94cb2f6c1c8ee81e72142b22ed8835c51757476b016
|
|
| MD5 |
396ddb47454aaeb112d0c45ec7fa005e
|
|
| BLAKE2b-256 |
aac225fbf5788e89f8818c49818046b1177b793c01bb9ac15fab85dd42585636
|
Provenance
The following attestation bundles were made for thermox-0.0.5.tar.gz:
Publisher:
publish_pypi.yaml on normal-computing/thermox
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
thermox-0.0.5.tar.gz -
Subject digest:
0756b355ced96eca2aaec94cb2f6c1c8ee81e72142b22ed8835c51757476b016 - Sigstore transparency entry: 184943502
- Sigstore integration time:
-
Permalink:
normal-computing/thermox@26ec6ae68e8401be15937e01ed8126087ee2cee6 -
Branch / Tag:
refs/tags/v0.0.5 - Owner: https://github.com/normal-computing
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_pypi.yaml@26ec6ae68e8401be15937e01ed8126087ee2cee6 -
Trigger Event:
release
-
Statement type:
File details
Details for the file thermox-0.0.5-py3-none-any.whl.
File metadata
- Download URL: thermox-0.0.5-py3-none-any.whl
- Upload date:
- Size: 13.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9543c073754247a02d7d47b27a1ad8d53b18f0b270c10895b2b1d146962677cf
|
|
| MD5 |
8725a61674df4f1e6ea432d309193651
|
|
| BLAKE2b-256 |
ec1187c73858e0bcc891459127f454abd2d5f0af14d12fc60a7cbe4398e8ffa8
|
Provenance
The following attestation bundles were made for thermox-0.0.5-py3-none-any.whl:
Publisher:
publish_pypi.yaml on normal-computing/thermox
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
thermox-0.0.5-py3-none-any.whl -
Subject digest:
9543c073754247a02d7d47b27a1ad8d53b18f0b270c10895b2b1d146962677cf - Sigstore transparency entry: 184943506
- Sigstore integration time:
-
Permalink:
normal-computing/thermox@26ec6ae68e8401be15937e01ed8126087ee2cee6 -
Branch / Tag:
refs/tags/v0.0.5 - Owner: https://github.com/normal-computing
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_pypi.yaml@26ec6ae68e8401be15937e01ed8126087ee2cee6 -
Trigger Event:
release
-
Statement type: