code = """ dx0 = i1 - sinf(x0) + alpha * (i2 - sinf(x1)) + (a1 + alpha * a2) * cosf(omega * t + phi0); dx1 = i2 - sinf(x1) + alpha * (i1 - sinf(x0)) + (alpha * a1 + a2) * cosf(omega * t + phi0); """ ns_map = {0: ['ns0', 0], 1: [0, 'ns0']} period_map = { 0: sde.PeriodInfo(period=2.0 * math.pi, freq=1), 1: sde.PeriodInfo(period=2.0 * math.pi, freq=1) } sdei = sde.SDE(code, sim_params, num_vars=2, num_noises=2, const_pars=const_pars, noise_map=ns_map, period_map=period_map, local_vars=local_vars) output = { 'path': { 'main': [sde.OutputDecl(func=sde.avg_moments, vars=[0, 1])], }, 'summary': { 'main': [sde.OutputDecl(func=sde.drift_velocity, vars=[0, 1])], # 'abs': [sde.OutputDecl(func=sde.abs_drift_velocity, vars=[0, 1])], } } sdei.prepare(sde.SRK2, init_vector, freq_var='omega')
# Solves the lorenz SDE and draws one generated path import sde import numpy as np # define the lorenz SDE sigma, rho, beta, lam = 10.0, 28.0, 8 / 3.0, 0.1 def a(X_t): x, y, z = X_t return np.array([sigma * (y - x), x * (rho - z) - y, x * y - beta * z]) def b(X_t): x, y, z = X_t return lam * (x + y + z) * np.ones((3, 3)) x_0 = [0.1, 0.2, 0.0] lorenz = sde.SDE(a, b, x_0) lorenz.solve(method='euler_maruyama', T=50, N=100000) lorenz.draw_path_3(max_pts=1000)
(alpha * (a1 + a3) + a2) * cosf(omega * t); dx2 = r3 * (i3 - ic3 * sinf(x2) + alpha * (i2 - ic2 * sinf(x1)) + (a3 + alpha * a2) * cosf(omega * t); """ ns_map = {0: ['ns0'], 1: ['ns0']} period_map = { 0: sde.PeriodInfo(period=2.0 * math.pi, freq=1), 1: sde.PeriodInfo(period=2.0 * math.pi, freq=1), 2: sde.PeriodInfo(period=2.0 * math.pi, freq=1) } sdei = sde.SDE(code, sim_params, num_vars=3, num_noises=1, noise_map=ns_map, period_map=period_map, local_vars=local_vars) output = { 'path': { 'main': [sde.OutputDecl(func=sde.avg_moments, vars=[0, 1, 2])], }, 'summary': { 'main': [sde.OutputDecl(func=sde.drift_velocity, vars=[0, 1, 2])], } } sdei.prepare(sde.SRK2, init_vector, freq_var='omega') sdei.simulate(output)
local_vars = { 'ns': lambda sdei: sympy.sqrt(sdei.S.d0 * sdei.S.dt * 2.0 * sdei.S.gamma_) } code = """ dx0 = x1; dx1 = -psd * sinf(x0) - gamma_ * x1 + force; """ noise_map = {1: ['ns']} period_map = {0: sde.PeriodInfo(period=2.0 * numpy.pi, freq=1)} sde_ = sde.SDE(code, params, num_vars=2, num_noises=1, noise_map=noise_map, period_map=period_map, local_vars=local_vars) output = { 'summary': { 'main': [sde.OutputDecl(func=sde.diffusion_coefficient, vars=[0])], }, 'path': { 'main': [ sde.OutputDecl(func=diffusion_coefficient, vars=[0]), sde.OutputDecl(func=max_min, vars=[0]) ], 'vhist': [sde.OutputDecl(func=myhist, vars=[1])], }