import numpy as np import sys, os import math cwd = os.getcwd() sys.path.append(cwd + '/..') import spaths from spaths.reactions import intermediate, Reaction # seed setting seed = 3579 rng = np.random.default_rng(seed) rng.integers(10**3, size=10**3) # warm up of RNG # solver em = spaths.EulerMaruyama(rng) # simulation parameters dt = 1e-4 nsam = 10 tspan = (0.0, 10.0) # initial conditions x0, y0 = [100.0] * nsam, [100.0] * nsam Y = intermediate(1) X = intermediate(0) X2 = intermediate(0, 2) c1 = 1.0 c2 = 100.0
def dispersion_rqp(t, x, dx): dx[0, 1] = np.sqrt(2 * temp / tsep) dx[1, 0] = np.sqrt(2 * temp) dx[1, 1] = 2 * x[0] * np.sqrt(2 * temp / tsep) # corresponding sde sde_rqp = spaths.ItoSDE(drift_rqp, dispersion_rqp, noise_mixing_dim=2) # seed setting and solvers seed = 3579 rng_Fou = np.random.default_rng(seed) rng_rqp = np.random.default_rng(seed) rng_Fou.integers(10**4), rng_rqp.integers(10**4) # warm up of RNG em_Fou = spaths.EulerMaruyama(rng_Fou) em_rqp = spaths.EulerMaruyama(rng_rqp) # simulation params dt = .1 * tsep nsam = 4000 x0, y0 = 0.0, 0.0 tspan = (0.0, 5) tsteps = (0.0, 10) ens0 = np.array([[x0, y0] * nsam], dtype=np.float32).reshape(-1, 2) x0 = ens0.T print(np.allclose(sde_Fou.drif(0, x0), sde_rqp.drif(0, x0))) print(np.allclose(sde_Fou.disp(0, x0), sde_rqp.disp(0, x0)))