class brainpy.dyn.InputVar(size, keep_size=False, sharding=None, name=None, mode=None, method='exp_auto')[source]#

Define an input variable.


import brainpy as bp

class Exponential(bp.Projection):
    def __init__(self, pre, post, prob, g_max, tau, E=0.):
        self.proj = bp.dyn.ProjAlignPostMg2(
            comm=bp.dnn.EventCSRLinear(bp.conn.FixedProb(prob, pre=pre.num, post=post.num), g_max),
            syn=bp.dyn.Expon.desc(post.num, tau=tau),

class EINet(bp.DynSysGroup):
    def __init__(self, num_exc, num_inh, method='exp_auto'):
        super(EINet, self).__init__()

        # neurons
        pars = dict(V_rest=-60., V_th=-50., V_reset=-60., tau=20., tau_ref=5.,
                    V_initializer=bp.init.Normal(-55., 2.), method=method)
        self.E = bp.dyn.LifRef(num_exc, **pars)
        self.I = bp.dyn.LifRef(num_inh, **pars)

        # synapses
        w_e = 0.6  # excitatory synaptic weight
        w_i = 6.7  # inhibitory synaptic weight

        # Neurons connect to each other randomly with a connection probability of 2%
        self.E2E = Exponential(self.E, self.E, 0.02, g_max=w_e, tau=5., E=0.)
        self.E2I = Exponential(self.E, self.I, 0.02, g_max=w_e, tau=5., E=0.)
        self.I2E = Exponential(self.I, self.E, 0.02, g_max=w_i, tau=10., E=-80.)
        self.I2I = Exponential(self.I, self.I, 0.02, g_max=w_i, tau=10., E=-80.)

        # define input variables given to E/I populations
        self.Ein = bp.dyn.InputVar(self.E.varshape)
        self.Iin = bp.dyn.InputVar(self.I.varshape)
        self.E.add_inp_fun('', self.Ein)
        self.I.add_inp_fun('', self.Iin)

net = EINet(3200, 800, method='exp_auto')  # "method": the numerical integrator method
runner = bp.DSRunner(net, monitors=['E.spike', 'I.spike'], inputs=[('Ein.input', 20.), ('Iin.input', 20.)])

# visualization
bp.visualize.raster_plot(runner.mon.ts, runner.mon['E.spike'],
                         title='Spikes of Excitatory Neurons', show=True)
bp.visualize.raster_plot(runner.mon.ts, runner.mon['I.spike'],
                         title='Spikes of Inhibitory Neurons', show=True)
clear_input(*args, **kwargs)[source]#

Empty function of clearing inputs.

reset_state(batch_or_mode=None, **kwargs)[source]#

Reset function which resets local states in this model.

Simply speaking, this function should implement the logic of resetting of local variables in this node.

See for details.

update(*args, **kwargs)[source]#

The function to specify the updating rule.