Пример #1
0
    def __init__(self,
                 size,
                 t_refractory=1.,
                 V_rest=0.,
                 V_reset=-5.,
                 V_th=20.,
                 R=1.,
                 tau=10.,
                 has_noise=True,
                 **kwargs):
        # parameters
        self.V_rest = V_rest
        self.V_reset = V_reset
        self.V_th = V_th
        self.R = R
        self.tau = tau
        self.t_refractory = t_refractory

        # variables
        self.t_last_spike = bp.ops.ones(size) * -1e7
        self.refractory = bp.ops.zeros(size)
        self.input = bp.ops.zeros(size)
        self.spike = bp.ops.zeros(size)
        self.V = bp.ops.ones(size) * V_reset

        if has_noise:
            self.int_V = bp.sdeint(f=self.f_v, g=self.g_v)
        else:
            self.int_V = bp.odeint(f=self.f_v)

        super(StochasticLIF, self).__init__(size=size, **kwargs)
Пример #2
0
def test_sde():
    def lorenz_g(x, y, z, t, sigma=10, beta=8 / 3, rho=28, p=0.1):
        return p * x, p * y, p * z

    def lorenz_f(x, y, z, t, sigma=10, beta=8 / 3, rho=28, p=0.1):
        dx = sigma * (y - x)
        dy = x * (rho - z) - y
        dz = x * y - beta * z
        return dx, dy, dz

    # for method in euler_and_milstein.__all__:
    for method in ['euler', 'milstein']:
        for sde_type in bp.SUPPORTED_SDE_TYPE:
            if method == 'heun' and sde_type == bp.ITO_SDE:
                continue
            for var_type in bp.SUPPORTED_VAR_TYPE:
                for wiener_type in bp.SUPPORTED_WIENER_TYPE:
                    print(
                        f'"{method}" method, "{sde_type}" sde type, '
                        f'"{var_type}" var type, "{wiener_type}" wiener type:')
                    bp.sdeint(f=lorenz_f,
                              g=lorenz_g,
                              show_code=True,
                              method=method,
                              var_type=var_type,
                              sde_type=sde_type,
                              wiener_type=wiener_type)
                    print()

    for method in [
            'exponential_euler', 'srk1w1_scalar', 'srk2w1_scalar',
            'KlPl_scalar'
    ]:
        for var_type in bp.SUPPORTED_VAR_TYPE:
            for wiener_type in bp.SUPPORTED_WIENER_TYPE:
                with pytest.raises(bp.errors.IntegratorError):
                    bp.sdeint(f=lorenz_f,
                              g=lorenz_g,
                              show_code=True,
                              method=method,
                              var_type=var_type,
                              sde_type=bp.STRA_SDE,
                              wiener_type=wiener_type)
Пример #3
0
def test_sde():
    def lorenz_g(x, y, z, t, sigma=10, beta=8 / 3, rho=28, p=0.1):
        return p * x, p * y, p * z

    def lorenz_f(x, y, z, t, sigma=10, beta=8 / 3, rho=28, p=0.1):
        dx = sigma * (y - x)
        dy = x * (rho - z) - y
        dz = x * y - beta * z
        return dx, dy, dz

    # for method in euler_and_milstein.__all__:
    for method in ['milstein', ]:
        for sde_type in [bp.ITO_SDE, bp.STRA_SDE]:
            print(f'{sde_type} type, {method} method:')

            bp.sdeint(f=lorenz_f, g=lorenz_g, show_code=True, method=method,
                      var_type=bp.SCALAR_VAR, sde_type=sde_type)
            print()

    for method in ['euler', 'exponential_euler']:
        sde_type = bp.ITO_SDE
        print(f'{sde_type} type, {method} method:')

        bp.sdeint(f=lorenz_f, g=lorenz_g, show_code=True, method=method,
                  var_type=bp.SCALAR_VAR, sde_type=sde_type)
        print()

    for method in ['heun']:
        sde_type = bp.STRA_SDE
        print(f'{sde_type} type, {method} method:')

        bp.sdeint(f=lorenz_f, g=lorenz_g, show_code=True, method=method,
                  var_type=bp.SCALAR_VAR, sde_type=sde_type)
        print()
        def __init__(cls, size, t_refractory=1., V_rest=0.,
                     V_reset=-5., V_th=20., R=1., tau=10., **kwargs):
            # parameters
            cls.V_rest = V_rest
            cls.V_reset = V_reset
            cls.V_th = V_th
            cls.R = R
            cls.tau = tau
            cls.t_refractory = t_refractory

            # variables
            cls.t_last_spike = bp.ops.ones(size) * -1e7
            cls.refractory = bp.ops.zeros(size)
            cls.input = bp.ops.zeros(size)
            cls.spike = bp.ops.zeros(size)
            cls.V = bp.ops.ones(size) * V_reset

            cls.int_V = bp.sdeint(f=cls.f_v, g=cls.g_v)

            super(LIF, cls).__init__(size=size, **kwargs)