Created
February 7, 2022 19:32
-
-
Save jmbr/fb802360fc25beeef03770a4ab03d054 to your computer and use it in GitHub Desktop.
Example of how to compute mean first passage times by brute force in parallel.
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
from joblib import Parallel, delayed | |
import numpy as np | |
n = 10000 # Number of experiments | |
dt: float = 1e-5 # Time step length | |
def integrate_until_exit(random_seed): | |
np.random.seed(random_seed) | |
t = 0.0 | |
x = np.zeros(2) | |
while True: | |
if np.linalg.norm(x) >= 1.0: | |
break | |
x += np.sqrt(dt) * np.random.randn(2) | |
t += dt | |
return t | |
fpts = Parallel(n_jobs=-1, verbose=1)( | |
delayed(integrate_until_exit)(i) for i in range(n)) | |
print('MFPT', np.mean(fpts), '+/-', np.std(fpts)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment