def test1(self):
        def func(m, t, V):
            alpha = 0.1 * (V + 40) / (1 - np.exp(-(V + 40) / 10))
            beta = 4.0 * np.exp(-(V + 65) / 18)
            dmdt = alpha * (1 - m) - beta * m
            return dmdt

        odeint(method='exponential_euler', show_code=True, f=func)
    def test6(self):
        with pytest.raises(errors.CodeError):

            def func(math, t, exp):
                alpha = 0.1 * (exp + 40) / (1 - np.exp(-(exp + 40) / 10))
                beta = 4.0 * np.exp(-(exp + 65) / 18)
                dmdt = alpha * (1 - math) - beta * math
                return dmdt

            odeint(method='exponential_euler', show_code=True, f=func)
    def test4(self):
        with pytest.raises(errors.CodeError):

            def func(m, t, m_new):
                alpha = 0.1 * (m_new + 40) / (1 - np.exp(-(m_new + 40) / 10))
                beta = 4.0 * np.exp(-(m_new + 65) / 18)
                dmdt = alpha * (1 - m) - beta * m
                return dmdt

            odeint(method='exponential_euler', show_code=True, f=func)
    def test2(self):
        with pytest.raises(errors.CodeError):

            def func(f, t, V):
                alpha = 0.1 * (V + 40) / (1 - np.exp(-(V + 40) / 10))
                beta = 4.0 * np.exp(-(V + 65) / 18)
                dmdt = alpha * (1 - f) - beta * f
                return dmdt

            odeint(method='exponential_euler', show_code=True, f=func)
예제 #5
0
    def __init__(self,
                 pre,
                 post,
                 conn,
                 g_max=1.,
                 delay=0.,
                 tau=8.0,
                 method='exp_auto',
                 name=None):
        super(ExpCUBA, self).__init__(pre=pre, post=post, conn=conn, name=name)
        self.check_pre_attrs('spike')
        self.check_post_attrs('input', 'V')

        # parameters
        self.tau = tau
        self.delay = delay
        self.g_max = g_max

        # connection
        assert self.conn is not None
        self.pre2post = self.conn.require('pre2post')

        # variables
        self.g = bm.Variable(bm.zeros(self.post.num))
        self.pre_spike = ConstantDelay(self.pre.num,
                                       delay=delay,
                                       dtype=pre.spike.dtype)

        # function
        self.integral = odeint(lambda g, t: -g / self.tau, method=method)
예제 #6
0
  def __init__(self, size, V_rest=-65., V_reset=-68., V_th=-30., V_T=-59.9, delta_T=3.48, a=1.,
               b=1., tau=10., tau_w=30., R=1., method='exp_auto', name=None):
    super(AdExIF, self).__init__(size=size, name=name)

    # parameters
    self.V_rest = V_rest
    self.V_reset = V_reset
    self.V_th = V_th
    self.V_T = V_T
    self.delta_T = delta_T
    self.a = a
    self.b = b
    self.tau = tau
    self.tau_w = tau_w
    self.R = R

    # variables
    self.w = bm.Variable(bm.zeros(self.num))
    self.refractory = bm.Variable(bm.zeros(self.num, dtype=bool))
    self.V = bm.Variable(bm.zeros(self.num))
    self.input = bm.Variable(bm.zeros(self.num))
    self.spike = bm.Variable(bm.zeros(self.num, dtype=bool))
    self.t_last_spike = bm.Variable(bm.ones(self.num) * -1e7)

    # functions
    self.integral = odeint(method=method, f=JointEq([self.dV, self.dw]))
예제 #7
0
    def test_euler(self):
        print('Test Euler method:')
        print()
        odeint(method='euler', show_code=True, f=lambda v, t, p: t)

        with pytest.raises(errors.CodeError):
            odeint(method='euler', show_code=True, f=lambda f, t, dt: t)

        with pytest.raises(errors.CodeError):
            odeint(method='euler', show_code=True, f=lambda v, t, dt: t)

        with pytest.raises(errors.CodeError):
            odeint(method='euler', show_code=True, f=lambda v, t, v_new: t)

        with pytest.raises(errors.CodeError):
            odeint(method='euler', show_code=True, f=lambda v, t, dv_k1: t)

        print('-' * 40)
예제 #8
0
  def __init__(self, size, V_rest=0., V_reset=-5., V_th=20., tau=10.,
               tau_ref=1., method='exp_auto', name=None):
    # initialization
    super(LIF, self).__init__(size=size, name=name)

    # parameters
    self.V_rest = V_rest
    self.V_reset = V_reset
    self.V_th = V_th
    self.tau = tau
    self.tau_ref = tau_ref

    # variables
    self.V = bm.Variable(bm.zeros(self.num))
    self.input = bm.Variable(bm.zeros(self.num))
    self.spike = bm.Variable(bm.zeros(self.num, dtype=bool))
    self.t_last_spike = bm.Variable(bm.ones(self.num) * -1e7)
    self.refractory = bm.Variable(bm.zeros(self.num, dtype=bool))

    # integral
    self.int_V = odeint(method=method, f=self.dV)
예제 #9
0
    def __init__(self,
                 pre,
                 post,
                 conn,
                 delay=0.,
                 g_max=0.42,
                 E=0.,
                 alpha=0.98,
                 beta=0.18,
                 T=0.5,
                 T_duration=0.5,
                 method='exp_auto',
                 **kwargs):
        super(AMPA, self).__init__(pre=pre, post=post, conn=conn, **kwargs)
        self.check_pre_attrs('spike')
        self.check_post_attrs('input', 'V')

        # parameters
        self.delay = delay
        self.g_max = g_max
        self.E = E
        self.alpha = alpha
        self.beta = beta
        self.T = T
        self.T_duration = T_duration

        # connection
        assert self.conn is not None
        self.pre_ids, self.post_ids = self.conn.require('pre_ids', 'post_ids')

        # variables
        self.g = bm.Variable(bm.zeros(self.num))
        self.pre_spike = ConstantDelay(self.pre.num,
                                       delay,
                                       dtype=pre.spike.dtype)
        self.spike_arrival_time = bm.Variable(bm.ones(self.pre.num) * -1e7)

        # functions
        self.integral = odeint(method=method, f=self.derivative)
예제 #10
0
  def __init__(self, size, a=0.02, b=0.20, c=-65., d=8., tau_ref=0.,
               V_th=30., method='exp_auto', name=None):
    # initialization
    super(Izhikevich, self).__init__(size=size, name=name)

    # params
    self.a = a
    self.b = b
    self.c = c
    self.d = d
    self.V_th = V_th
    self.tau_ref = tau_ref

    # variables
    self.u = bm.Variable(bm.ones(self.num))
    self.refractory = bm.Variable(bm.zeros(self.num, dtype=bool))
    self.V = bm.Variable(bm.zeros(self.num))
    self.input = bm.Variable(bm.zeros(self.num))
    self.spike = bm.Variable(bm.zeros(self.num, dtype=bool))
    self.t_last_spike = bm.Variable(bm.ones(self.num) * -1e7)

    # functions
    self.integral = odeint(method=method, f=JointEq([self.dV, self.du]))
  def test_rkf45(self):
    method = 'rkf45'
    for adaptive in [True, False]:

      print(f'Test {"adaptive" if adaptive else ""} {method} method:')
      print()
      ode.odeint(method=method, show_code=True, adaptive=adaptive, f=lambda v, t, p: t)

      with pytest.raises(errors.CodeError):
        ode.odeint(method=method, show_code=True, adaptive=adaptive, f=lambda f, t, dt: t)

      with pytest.raises(errors.CodeError):
        ode.odeint(method=method, show_code=True, adaptive=adaptive, f=lambda v, t, dt: t)

      with pytest.raises(errors.CodeError):
        ode.odeint(method=method, show_code=True, adaptive=adaptive, f=lambda v, t, v_new: t)

      with pytest.raises(errors.CodeError):
        ode.odeint(method=method, show_code=True, adaptive=adaptive, f=lambda v, t, dv_k1: t)

      with pytest.raises(errors.CodeError):
        ode.odeint(method=method, show_code=True, adaptive=adaptive, f=lambda v, t, dv_k2: t)

      with pytest.raises(errors.CodeError):
        ode.odeint(method=method, show_code=True, adaptive=adaptive, f=lambda v, t, k2_v_arg: t)

      with pytest.raises(errors.CodeError):
        ode.odeint(method=method, show_code=True, adaptive=adaptive, f=lambda v, t, k2_t_arg: t)

      with pytest.raises(errors.CodeError):
        ode.odeint(method=method, show_code=True, adaptive=adaptive, f=lambda v, t, k3_v_arg: t)

      with pytest.raises(errors.CodeError):
        ode.odeint(method=method, show_code=True, adaptive=adaptive, f=lambda v, t, k3_t_arg: t)

      with pytest.raises(errors.CodeError):
        ode.odeint(method=method, show_code=True, adaptive=adaptive, f=lambda v, t, k4_v_arg: t)

      with pytest.raises(errors.CodeError):
        ode.odeint(method=method, show_code=True, adaptive=adaptive, f=lambda v, t, k4_t_arg: t)

      if adaptive:
        with pytest.raises(errors.CodeError):
          ode.odeint(method=method, show_code=True, adaptive=adaptive, f=lambda v, t, error: t)

        with pytest.raises(errors.CodeError):
          ode.odeint(method=method, show_code=True, adaptive=adaptive, f=lambda v, t, v_te: t)

        with pytest.raises(errors.CodeError):
          ode.odeint(method=method, show_code=True, adaptive=adaptive, f=lambda v, t, dt_new: t)

      print('-' * 40)
예제 #12
0
    def test_order3_rk(self):
        for method in ['rk3', 'heun3', 'ralston3', 'ssprk3']:
            print(f'Test {method} method:')
            print()
            odeint(method=method, show_code=True, f=lambda v, t, p: t)

            with pytest.raises(errors.CodeError):
                odeint(method=method, show_code=True, f=lambda f, t, dt: t)

            with pytest.raises(errors.CodeError):
                odeint(method=method, show_code=True, f=lambda v, t, dt: t)

            with pytest.raises(errors.CodeError):
                odeint(method=method, show_code=True, f=lambda v, t, v_new: t)

            with pytest.raises(errors.CodeError):
                odeint(method=method, show_code=True, f=lambda v, t, dv_k1: t)

            with pytest.raises(errors.CodeError):
                odeint(method=method, show_code=True, f=lambda v, t, dv_k2: t)

            with pytest.raises(errors.CodeError):
                odeint(method=method, show_code=True, f=lambda v, t, dv_k3: t)

            with pytest.raises(errors.CodeError):
                odeint(method=method,
                       show_code=True,
                       f=lambda v, t, k2_v_arg: t)

            with pytest.raises(errors.CodeError):
                odeint(method=method,
                       show_code=True,
                       f=lambda v, t, k2_t_arg: t)

            with pytest.raises(errors.CodeError):
                odeint(method=method,
                       show_code=True,
                       f=lambda v, t, k3_v_arg: t)

            with pytest.raises(errors.CodeError):
                odeint(method=method,
                       show_code=True,
                       f=lambda v, t, k3_t_arg: t)

            print('-' * 40)
예제 #13
0
    def test_rk2(self):
        method = 'rk2'

        print(f'Test {method} method:')
        print()
        odeint(method=method, show_code=True, f=lambda v, t, p: t)

        with pytest.raises(errors.CodeError):
            odeint(method=method, show_code=True, f=lambda f, t, dt: t)

        with pytest.raises(errors.CodeError):
            odeint(method=method, show_code=True, f=lambda v, t, dt: t)

        with pytest.raises(errors.CodeError):
            odeint(method=method, show_code=True, f=lambda v, t, v_new: t)

        with pytest.raises(errors.CodeError):
            odeint(method=method, show_code=True, f=lambda v, t, dv_k1: t)

        with pytest.raises(errors.CodeError):
            odeint(method=method, show_code=True, f=lambda v, t, dv_k2: t)

        with pytest.raises(errors.CodeError):
            odeint(method=method, show_code=True, f=lambda v, t, k2_v_arg: t)

        with pytest.raises(errors.CodeError):
            odeint(method=method, show_code=True, f=lambda v, t, k2_t_arg: t)

        print('-' * 40)