コード例 #1
0
	def kuramotos():
		for i in range(n):
			yield ω + c/(n-1)*sum(
						sin(y(j,t-τ[i,j])-y(i))
						for j in range(n)
						if A[j,i]
					)
コード例 #2
0
ファイル: dde.py プロジェクト: TimeSynth/TimeSynth
    def __init__(self, tau=17., n=10., beta=0.2, gamma=0.1, initial_condition=None, burn_in=500):
        self.vectorizable = True

        # Set system of equations
        f = [- gamma * y(0) + beta * y(0, t-tau) / (1.0 + y(0, t-tau) ** n)]
        self.dde = jitcdde(f)

        # Set initial condition
        if initial_condition is None:
            y_initial = 0.5
            dy = lambda y: -gamma * y + beta * y / (1.0 + y ** n)
            dy_initial = dy(y_initial)
            self.dde.add_past_point(0.0, np.array([y_initial]), np.array([dy_initial]))
            self.dde.add_past_point(tau, np.array([1.0]), np.array([0.0]))
        else:
            for condition in initial_condition:
                time, value, derivative = condition
                self.dde.add_past_point(time, np.array([value]), np.array([derivative]))

        # Prepare DDE
        self.dde.generate_lambdas()
        self.dde.set_integration_parameters()

        # Run burn_in
        self.burn_in = burn_in
        self.dde.integrate_blindly(self.burn_in)
コード例 #3
0
ファイル: test_lyaps.py プロジェクト: neurophysik/jitcdde
import unittest
import numpy as np
from scipy.stats import sem
from jitcdde import t, y, jitcdde_lyap

if platform.system() == "Windows":
	compile_args = None
else:
	from jitcxde_common import DEFAULT_COMPILE_ARGS
	compile_args = DEFAULT_COMPILE_ARGS+["-g","-UNDEBUG"]

omega = np.array([0.88167179, 0.87768425])
delay = 4.5

f = [
	omega[0] * (-y(1) - y(2)),
	omega[0] * (y(0) + 0.165 * y(1)),
	omega[0] * (0.2 + y(2) * (y(0) - 10.0)),
	omega[1] * (-y(4) - y(5)) + 0.25 * (y(0,t-delay) - y(3)),
	omega[1] * (y(3) + 0.165 * y(4)),
	omega[1] * (0.2 + y(5) * (y(3) - 10.0))
	]

test_parameters = {
	"rtol": 1e-7,
	"atol": 1e-7,
	"pws_rtol": 1e-3,
	"pws_atol": 1e-3,
	"first_step": 30,
	"max_step": 100,
	"min_step": 1e-30,
コード例 #4
0
	:linenos:

Note that `integrate` does not only return local Lyapunov exponents but also the length of the time interval to which they apply (which differs from the time spanned by the `integrate` command and may even be zero). This length should be used to weigh the local Lyapunov exponents for statistical processing, like in line 31.
"""

if __name__ == "__main__":
	from jitcdde import jitcdde_lyap, y, t
	import numpy
	from scipy.stats import sem
	
	τ = 15
	n = 10
	β = 0.25
	γ = 0.1
	
	f = [ β * y(0,t-τ) / (1 + y(0,t-τ)**n) - γ*y(0) ]
	n_lyap = 4
	DDE = jitcdde_lyap(f, n_lyap=n_lyap)
	
	DDE.constant_past([1.0])
	
	DDE.step_on_discontinuities(max_step=1.0)
	
	data = []
	lyaps = []
	weights = []
	for time in numpy.arange(DDE.t, DDE.t+10000, 10):
		state, lyap, weight = DDE.integrate(time)
		data.append(state)
		lyaps.append(lyap)
		weights.append(weight)
コード例 #5
0
#!/usr/bin/python3
# -*- coding: utf-8 -*-

from jitcdde import jitcdde, y, t
import numpy

f = [ -y(0,t-2-y(0)**2) + 5 ]
DDE = jitcdde(f,max_delay=1e10)

eps = 0.1
DDE.add_past_point(-2.0    , [ 4.5], [0.0])
DDE.add_past_point(-1.0-eps, [ 4.5], [0.0])
DDE.add_past_point(-1.0+eps, [-0.5], [0.0])
DDE.add_past_point( 0.0    , [-0.5], [0.0])

DDE.integrate_blindly(0.01)

data = []
for time in numpy.arange(0,2.0,0.001)+DDE.t:
	data.append([time, DDE.integrate(time)])
numpy.savetxt("timeseries.dat", data)

コード例 #6
0
	compile_args = None
else:
	from jitcxde_common import DEFAULT_COMPILE_ARGS
	compile_args = DEFAULT_COMPILE_ARGS+["-g","-UNDEBUG"]

a = -0.025794
b =  0.01
c =  0.02
τ =  1.0
k = Symbol("k")

scenarios = [
	{
	"f":
		[
			y(0)*(a-y(0))*(y(0)-1.0) - y(3) + k*(y(1)-y(0)),
			y(1)*(a-y(1))*(y(1)-1.0) - y(4) + k*(y(2)-y(1)),
			y(2)*(a-y(2))*(y(2)-1.0) - y(5) + k*(y(0)-y(2)),
			b*y(0) - c*y(3,t-τ),
			b*y(1) - c*y(4,t-τ),
			b*y(2) - c*y(5,t-τ),
		],
	"vectors":
		[
			( [1.,1.,1.,0.,0.,0.], [0.,0.,0.,0.,0.,0.] ) ,
			( [0.,0.,0.,0.,0.,0.], [1.,1.,1.,0.,0.,0.] ) ,
			( [0.,0.,0.,1.,1.,1.], [0.,0.,0.,0.,0.,0.] ) ,
			( [0.,0.,0.,0.,0.,0.], [0.,0.,0.,1.,1.,1.] ) ,
		],
	"groups":
		( [0,1,2], [3,4,5] )
コード例 #7
0
ファイル: laminar_chaos.py プロジェクト: neurophysik/jitcdde
from jitcdde import t, y, jitcdde
from symengine import sin
import numpy as np

T = 200
A = 0.9/2/np.pi
τ_0 = 1.50
f = lambda z: 4*z*(1-z)
τ = τ_0 + A*sin(2*np.pi*t)

model = [ T*( -y(0) + f(y(0,t-τ)) ) ]

DDE = jitcdde(model,max_delay=τ_0+A)
DDE.past_from_function([0.4+0.2*sin(t)])
DDE.set_integration_parameters(max_step=0.01,first_step=0.01)
DDE.integrate_blindly(τ_0+A,0.01)

for time in DDE.t + 100 + np.arange(0,10,0.01):
	print(DDE.integrate(time)[0])
コード例 #8
0
ファイル: test_ode.py プロジェクト: neurophysik/jitcdde
f_of_y0 = np.array([
	0.0045396904008868,
	0.00002265673,
	0.0043665702488807,
	0.000328463955
	])

a  = -0.025794
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)
	]

class basic_test(unittest.TestCase):
	@classmethod
	def setUpClass(self):
		self.ODE = jitcdde(f)
	
	def setUp(self):
		self.ODE.purge_past()
		self.ODE.add_past_point(-1.0, y0, f_of_y0)
		self.ODE.add_past_point( 0.0, y0, f_of_y0)
	
コード例 #9
0
ファイル: two_Roesslers.py プロジェクト: neurophysik/jitcdde
from jitcdde import t, y, jitcdde
import numpy as np

ω = np.random.normal(0.89, 0.0089, 2)
k = 0.25
delay = 4.5

f = [
	ω[0] * (-y(1) - y(2)),
	ω[0] * (y(0) + 0.165 * y(1)),
	ω[0] * (0.2 + y(2) * (y(0) - 10.0)),
	ω[1] * (-y(4) - y(5)) + k * (y(0,t-delay) - y(3)),
	ω[1] * (y(3) + 0.165 * y(4)),
	ω[1] * (0.2 + y(5) * (y(3) - 10.0))
	]

DDE = jitcdde(f)

start_state = np.random.uniform(-0.5,0.5,6)

DDE.add_past_point(-delay, start_state, np.zeros(6))
DDE.add_past_point(0.0   , start_state, np.zeros(6))

DDE.step_on_discontinuities()

times = np.arange(DDE.t,DDE.t+1000,0.1)
data = np.vstack(DDE.integrate(T) for T in times)
np.savetxt("two_roesslers.dat", data)

コード例 #10
0
def display_endemic_progress():
    """Display how a typical endemic progresses in time"""
    beta = 0.000001
    k = 6
    gamma = 0.0002
    delta = 0.3
    # pylint: disable=invalid-name
    mu = 0.1
    d_one = 0.005
    d_two = 0.001
    tau = 5
    initially_susceptible = 99980
    initially_infected = 20

    list_of_odes = [
        gamma * y(4) - beta * k * y(0) * y(2),
        beta * k * y(0) * y(2) - beta * k * y(0, t - tau) * y(2, t - tau),
        beta * k * y(0, t - tau) * y(2, t - tau) - d_one * y(2) - delta * y(2),
        delta * y(2) - d_two * y(3) - mu * y(3), mu * y(3) - gamma * y(4)
    ]

    delayed_differential_equation = jitcdde(list_of_odes)
    delayed_differential_equation.add_past_point(
        -10.0, [initially_susceptible, 0, initially_infected, 0, 0],
        [0, 0, 0, 0, 0])
    delayed_differential_equation.add_past_point(
        0, [initially_susceptible, 0, initially_infected, 0, 0],
        [0, 0, 0, 0, 0])

    delayed_differential_equation.step_on_discontinuities()

    stoptime = 180
    numpoints = 18000
    times = delayed_differential_equation.t + \
        np.linspace(1, stoptime, numpoints)

    data = []
    for time in times:
        data.append(delayed_differential_equation.integrate(time))

    npdata = np.array(data)
    susceptible = npdata[:, 0]
    exposed = npdata[:, 1]
    infected = npdata[:, 2]
    quarantined = npdata[:, 3]
    recovered = npdata[:, 4]

    fig = plt.figure()
    subplot = fig.add_subplot(1, 1, 1)
    subplot.plot(times, susceptible, label='Susceptible people')
    subplot.plot(times, exposed, '-', label='Exposed people')
    subplot.plot(times, infected, '--', label='Infected people')
    subplot.plot(times, quarantined, '-.', label='Quarantined people')
    subplot.plot(times, recovered, ':', label='Recovered people')
    subplot.set_xlabel('Days from outbreak')
    subplot.set_ylabel('Population')
    subplot.legend(loc='best')
    plt.savefig('all_compartments.svg', format="svg", dpi=1200)
コード例 #11
0
def f():
	yield omega[0] * (-y(1) - y(2))
	yield omega[0] * (y(0) + 0.165 * y(1))
	yield omega[0] * (0.2 + y(2) * (y(0) - 10.0))
	yield omega[1] * (-y(4) - y(5)) + k * (y(0,t-delay) - y(3))
	yield omega[1] * (y(3) + 0.165 * y(4))
	yield omega[1] * (0.2 + y(5) * (y(3) - 10.0))
	yield 0
	yield 0
コード例 #12
0
ファイル: test_jitcdde.py プロジェクト: neurophysik/jitcdde
	def test_check_index_too_high(self):
		DDE = jitcdde([y(1)])
		with self.assertRaises(ValueError):
			DDE.check()
コード例 #13
0
	def setUp(self):
		double_mackey_glass = [
				.25*y(0,t-15) / (1+y(0,t-15)**10) - 0.1*y(0),
				.25*y(1,t-15) / (1+y(1,t-15)**10) - 0.1*y(1)
				]
		self.DDE = jitcdde(double_mackey_glass)
コード例 #14
0
ファイル: test_jitcdde.py プロジェクト: neurophysik/jitcdde
	def test_check_index_negative(self):
		DDE = jitcdde([y(-1)])
		with self.assertRaises(ValueError):
			DDE.check()
コード例 #15
0
ファイル: test_jitcdde.py プロジェクト: neurophysik/jitcdde
	def test_dynamic_dependent_delay(self):
		g = lambda: [y(0,t-y(0))]
		with self.assertRaises(ValueError):
			_find_max_delay(_get_delays(g))
コード例 #16
0
ファイル: test_jitcdde.py プロジェクト: neurophysik/jitcdde
	def test_time_dependent_delay(self):
		g = lambda: [y(0,2*t)]
		with self.assertRaises(ValueError):
			_find_max_delay(_get_delays(g))
コード例 #17
0
ファイル: test_jitcdde.py プロジェクト: neurophysik/jitcdde
def f_generator():
	yield omega[0] * (-y(1) - y(2))
	yield omega[0] * (y(0) + 0.165 * y(1))
	yield omega[0] * (0.2 + y(2) * (y(0) - 10.0))
	yield omega[1] * (-y(4) - y(5)) + 0.25  * (y(0,t-delay) - y(3))
	yield omega[1] * (y(3) + 0.165 * y(4))
	yield omega[1] * (0.2 + y(5) * (y(3) - 10.0))
コード例 #18
0
ファイル: test_jitcdde.py プロジェクト: neurophysik/jitcdde
import symengine
import numpy as np
from numpy.testing import assert_allclose
import unittest

if platform.system() == "Windows":
	compile_args = None
else:
	from jitcxde_common import DEFAULT_COMPILE_ARGS
	compile_args = DEFAULT_COMPILE_ARGS+["-g","-UNDEBUG"]

omega = np.array([0.88167179, 0.87768425])
delay = 4.5

f = [
		omega[0] * (-y(1) - y(2)),
		omega[0] * (y(0) + 0.165 * y(1)),
		omega[0] * (0.2 + y(2) * (y(0) - 10.0)),
		omega[1] * (-y(4) - y(5)) + 0.25 * (y(0,t-delay) - y(3)),
		omega[1] * (y(3) + 0.165 * y(4)),
		omega[1] * (0.2 + y(5) * (y(3) - 10.0))
	]

def get_past_points():
	data = np.loadtxt("two_Roessler_past.dat")
	for point in data:
		yield (point[0], np.array(point[1:7]), np.array(point[7:13]))

y_10_ref = np.loadtxt("two_Roessler_y10.dat")
T = 10