def test_save_and_load_with_jac(self): self.ODE = jitcode_lyap(**vanilla,n_lyap=n,wants_jacobian=True) filename = self.ODE.save_compiled(overwrite=True) self.ODE = jitcode_lyap((),n=n,n_lyap=n,module_location=filename) self.ODE.set_integrator("vode") self.assertTrue(_is_C(self.ODE.f)) self.assertTrue(_is_C(self.ODE.jac))
def test_save_and_load_with_jac(self): self.ODE = jitcode_lyap(**vanilla, n_lyap=n, wants_jacobian=True) filename = self.ODE.save_compiled(overwrite=True) self.ODE = jitcode_lyap((), n=n, n_lyap=n, module_location=filename) self.ODE.set_integrator("vode") self.assertTrue(_is_C(self.ODE.f)) self.assertTrue(_is_C(self.ODE.jac))
def test_identity_of_lyaps(self): n = len(f) x = np.random.random((n+1)*n) ODE1 = jitcode_lyap(f, n_lyap=n) ODE2 = jitcode_lyap(f_alt, get_f_alt_helpers(), n_lyap=n) ODE1.set_integrator("dopri5") ODE2.set_integrator("dopri5") assert_allclose(ODE1.f(0.0,x), ODE2.f(0.0,x))
def test_regular(self): self.ODE = jitcode_lyap(**vanilla, n_lyap=n) self.ODE.set_integrator("dopri5")
import numpy as np a = -0.025794 b1 = 0.0065 b2 = 0.0135 c = 0.02 k = 0.128 t, y = provide_basic_symbols() f = [ y(0) * (a - y(0)) * (y(0) - 1.0) - y(1) + k * (y(2) - y(0)), b1 * y(0) - c * y(1), y(2) * (a - y(2)) * (y(2) - 1.0) - y(3) + k * (y(0) - y(2)), b2 * y(2) - c * y(3) ] initial_state = np.array([1., 2., 3., 4.]) n = len(f) ODE = jitcode_lyap(f, n_lyap=n) ODE.set_integrator("vode") ODE.set_initial_value(initial_state, 0.0) data = np.vstack(ODE.integrate(T) for T in range(10, 100000, 10)) for i in range(n): lyap = np.average(data[1000:, n + i]) stderr = sem(data[1000:, n + i]) print("%i. Lyapunov exponent: % .4f ± %.4f" % (i + 1, lyap, stderr))
def evaluate(scenario): ODE = jitcode_lyap(**scenario, n_lyap=n) ODE.compile_C() return ODE.f(0.0, x)
def test_lyapunov_with_helpers_and_jac(self): self.ODE = jitcode_lyap(f_alt, get_f_alt_helpers(), n_lyap=self.n) self.ODE.set_integrator("vode")
def test_lyapunov_with_helpers(self): self.ODE = jitcode_lyap(f_alt, get_f_alt_helpers(), n_lyap=self.n) self.ODE.set_integrator("dopri5")
def test_lyapunov_with_jac(self): self.ODE = jitcode_lyap(f, n_lyap=self.n) self.ODE.set_integrator("vode")
b1 = 0.0065 b2 = 0.0135 c = 0.02 k = 0.128 f = [ y(0) * ( a-y(0) ) * ( y(0)-1.0 ) - y(1) + k * (y(2) - y(0)), b1*y(0) - c*y(1), y(2) * ( a-y(2) ) * ( y(2)-1.0 ) - y(3) + k * (y(0) - y(2)), b2*y(2) - c*y(3) ] initial_state = np.array([1.,2.,3.,4.]) n = len(f) ODE = jitcode_lyap(f, n_lyap=n) ODE.set_integrator("vode") ODE.set_initial_value(initial_state,0.0) times = range(10,100000,10) lyaps = [] for time in times: lyaps.append(ODE.integrate(time)[1]) # converting to NumPy array for easier handling lyaps = np.vstack(lyaps) for i in range(n): lyap = np.average(lyaps[1000:,i]) stderr = sem(lyaps[1000:,i]) # Note that this only an estimate print("%i. Lyapunov exponent: % .4f ± %.4f" % (i+1,lyap,stderr))
def test_regular(self): self.ODE = jitcode_lyap(**vanilla,n_lyap=n) self.ODE.set_integrator("dopri5")
def test_lyapunov(self): self.ODE = jitcode_lyap(f, n_lyap=self.n) self.ODE.set_integrator("dopri5")
def test_jac(self): self.ODE = jitcode_lyap(**vanilla, n_lyap=n) self.ODE.set_integrator("lsoda")
def evaluate(scenario): ODE = jitcode_lyap(**scenario,n_lyap=n) ODE.compile_C() return ODE.f(0.0,x)
def test_jac(self): self.ODE = jitcode_lyap(**vanilla,n_lyap=n) self.ODE.set_integrator("lsoda")