Skip to content

Instantly share code, notes, and snippets.

@dlozeve
Created October 20, 2023 14:34
Show Gist options
  • Save dlozeve/4924e71097e1d86933e8d5528cd2f6b4 to your computer and use it in GitHub Desktop.
Save dlozeve/4924e71097e1d86933e8d5528cd2f6b4 to your computer and use it in GitHub Desktop.
Randomness and Certainty
# 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()
numpy
jax[cpu]
diffrax
matplotlib
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment