Created
October 20, 2023 14:34
-
-
Save dlozeve/4924e71097e1d86933e8d5528cd2f6b4 to your computer and use it in GitHub Desktop.
Randomness and Certainty
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Randomness and Certainty | |
# https://www.lms.ac.uk/sites/default/files/inline-files/NLMS_505_for%20web.pdf#page=24 | |
import matplotlib.pyplot as plt | |
import numpy as np | |
from diffrax import diffeqsolve, ODETerm, Dopri5, SaveAt | |
N = 300 | |
rng = np.random.default_rng(42) | |
noise_data = rng.normal(size=N) | |
def f(t, y, args): | |
return y - y**3 + 0.4 * args[t.astype(int)] | |
term = ODETerm(f) | |
solver = Dopri5() | |
saveat = SaveAt(ts=np.arange(start=0, stop=N, step=0.1)) | |
solution = diffeqsolve( | |
term, | |
solver, | |
t0=0, | |
t1=N, | |
dt0=0.1, | |
y0=1, | |
saveat=saveat, | |
args=noise_data, | |
) | |
fig, ax = plt.subplots() | |
ax.plot(solution.ts, solution.ys) | |
ax.set_xlabel("$t$") | |
ax.set_ylabel("$y(t)$") | |
fig.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
numpy | |
jax[cpu] | |
diffrax | |
matplotlib |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment