예제 #1
0
def fully_connected(ctor,
                    starts: Union[MFPopulation, List[MFPopulation]],
                    ends: Union[MFPopulation, List[MFPopulation]],
                    parameters: Union[dict, MFParameters],
                    *args,
                    name: str = None,
                    self_loop_parameters: Union[None,
                                                Union[dict,
                                                      MFParameters]] = None,
                    **kwargs) -> List[MFInput]:

    inputs = []

    if name is None:
        name = ''

    starts = listify(starts)
    ends = listify(ends)

    for start in starts:
        for end in ends:

            inp_name = f'{name} {start.name}-{end.name}'
            inp = Connection.all_to_others(
            ) if start == end else Connection.all_to_all()
            inp_parameters = self_loop_parameters if start == end and self_loop_parameters is not None else parameters

            inp = ctor(start,
                       end,
                       inp_parameters,
                       *args,
                       **kwargs,
                       name=inp_name,
                       connection=inp)
            inputs.append(inp)

    return inputs
예제 #2
0
    def test_model_gen_with_two_sources(self):
        pop = MFLinearPopulation(1, params_pop)
        pop.add_input(
            MFInput(None,
                    pop,
                    params_source,
                    connection=Connection.all_to_all(),
                    name='test1'))
        pop.add_input(
            MFInput(None,
                    pop,
                    params_source,
                    connection=Connection.all_to_all(),
                    name='test2'))

        assert_equations(
            pop.brian2_model, '''
            I_test1 = (0. * siemens) * (v - (0. * volt)) * s_test1 : amp
            I_test2 = (0. * siemens) * (v - (0. * volt)) * s_test2 : amp
            I= I_test1 + I_test2 : amp
            dv/dt = (- (25. * nsiemens) * (v - (-70. * mvolt)) - I) / (0.5 * nfarad) : volt
            ds_test1/dt = - s_test1 / (10. * msecond)  : 1
            ds_test2/dt = - s_test2 / (10. * msecond)  : 1
            ''')
예제 #3
0
    def __init__(self,
                 origin: Union[None, MFPopulation],
                 target: MFPopulation,
                 parameters: Union[Dict, MFParameters] = None,
                 name: str = None,
                 connection: ConnectionStrategy = Connection.all_to_all()):

        self.name = name if name else create_name(self)
        self.ref = create_identifier(self.name)

        self.parameters = MFParameters(
            {}) if not parameters else MFParameters(parameters)
        self.parameters.fill(self.defaults)
        self.parameters.verify(self.arguments)

        self.origin = origin
        self.target = target
        self.connection = connection
예제 #4
0
    def test_simulation_theory(self):
        reset_brian2()

        t = 3000 * ms
        dt = 0.01 * ms
        n = 100

        poisson = MFPoissonPopulation(n, 10 * Hz)
        pop = MFLinearPopulation(
            n, {
                PP.GM: 10 * nsiemens,
                PP.VL: 0 * mV,
                PP.CM: 5 * nfarad,
                PP.VTHR: 0 * mV,
                PP.VRES: 0 * mV,
                PP.TAU_RP: 15 * ms
            })
        syn = MFLinearInput(poisson,
                            pop, {
                                IP.GM: 10 * nsiemens,
                                IP.VREV: 0 * mV,
                                IP.TAU: 20 * ms,
                            },
                            connection=Connection.one_to_one())

        system = MFSystem(pop, poisson)
        solver = MFSolver.rates_voltages(system, solver='mse')
        solver.run()
        theory = syn.g_dyn() / syn.origin.n

        m = StateMonitor(syn.brian2, syn.post_variable_name, record=range(100))
        defaultclock.dt = dt

        net = system.collect_brian2_network(m)
        net.run(t)

        stable_t = int(t / dt * 0.1)
        simulation = m.__getattr__(syn.post_variable_name)[:, stable_t:]
        simulation_mean = np.mean(simulation)

        assert np.isclose(theory, simulation_mean, rtol=0.5, atol=0.5)
예제 #5
0
}

modelling.fully_connected(MFLinearInput, [pop_e] + pop_e_sel,
                          pop_i,
                          ei_ampa,
                          name='AMPA')

# I->I GABA
MFLinearInput(pop_i,
              pop_i, {
                  IP.GM: g_GABA_I,
                  IP.VREV: V_I,
                  IP.TAU: tau_GABA,
              },
              name='II GABA',
              connection=Connection.all_to_others())

# I->E GABA
ie_gaba = {
    IP.GM: g_GABA_E,
    IP.VREV: V_I,
    IP.TAU: tau_GABA,
}

modelling.fully_connected(MFLinearInput,
                          pop_i, [pop_e] + pop_e_sel,
                          ie_gaba,
                          name='GABA')

# monitors
N_activity_plot = 15
예제 #6
0
def one_subpopulation():

    # populations
    N = 250
    N_E = int(N * 0.8)  # pyramidal neurons
    N_I = int(N * 0.2)  # interneurons

    # voltage
    V_L = -70. * mV
    V_thr = -50. * mV
    V_reset = -55. * mV
    V_E = 0. * mV
    V_I = -70. * mV

    # membrane capacitance
    C_m_E = 0.5 * nF
    C_m_I = 0.2 * nF

    # membrane leak
    g_m_E = 25. * nS
    g_m_I = 20. * nS

    # refractory period
    tau_rp_E = 2. * ms
    tau_rp_I = 1. * ms

    # external stimuli
    rate = 3 * Hz
    C_ext = 800

    # AMPA (excitatory)
    g_AMPA_ext_E = 2.08 * nS
    g_AMPA_rec_E = 0.104 * nS * 800. / N_E
    g_AMPA_ext_I = 1.62 * nS
    g_AMPA_rec_I = 0.081 * nS * 800. / N_E
    tau_AMPA = 2. * ms

    # NMDA (excitatory)
    g_NMDA_E = 0.327 * nS * 800. / N_E
    g_NMDA_I = 0.258 * nS * 800. / N_E
    tau_NMDA_rise = 2. * ms
    tau_NMDA_decay = 100. * ms
    alpha = 0.5 / ms
    beta = 0.062
    gamma = 1. / 3.57
    Mg2 = 1.

    # GABAergic (inhibitory)
    g_GABA_E = 1.25 * nS * 200. / N_I
    g_GABA_I = 0.973 * nS * 200. / N_I
    tau_GABA = 10. * ms

    # subpopulations
    f = 0.1
    p = 1
    N_sub = int(N_E * f)
    N_non = int(N_E * (1. - f * p))
    w_plus = 2.1
    w_minus = 1. - f * (w_plus - 1.) / (1. - f)

    # modeling
    E_params = {
        PP.GM: g_m_E,
        PP.CM: C_m_E,
        PP.VL: V_L,
        PP.VTHR: V_thr,
        PP.VRES: V_reset,
        PP.TAU_RP: tau_rp_E
    }

    I_params = {
        PP.GM: g_m_I,
        PP.CM: C_m_I,
        PP.VL: V_L,
        PP.VTHR: V_thr,
        PP.VRES: V_reset,
        PP.TAU_RP: tau_rp_I,
    }

    pop_e1 = MFLinearPopulation(N_non, E_params, name="E")
    pop_e2 = MFLinearPopulation(N_sub, E_params, name="Edown")
    pop_i = MFLinearPopulation(N_I, I_params, name="I")

    # noise pops
    MFStaticInput(C_ext,
                  rate,
                  pop_e1, {
                      IP.GM: g_AMPA_ext_E,
                      IP.VREV: V_E,
                      IP.TAU: tau_AMPA,
                  },
                  name="E_noise1")

    MFStaticInput(C_ext,
                  rate,
                  pop_e2, {
                      IP.GM: g_AMPA_ext_E,
                      IP.VREV: V_E,
                      IP.TAU: tau_AMPA,
                  },
                  name="E_noise2")

    MFStaticInput(C_ext,
                  rate,
                  pop_i, {
                      IP.GM: g_AMPA_ext_I,
                      IP.VREV: V_E,
                      IP.TAU: tau_AMPA,
                  },
                  name="I_noise")

    # E->E NMDA
    ee_nmda = MFParameters({
        IP.GM: g_NMDA_E,
        IP.VREV: V_E,
        IP.TAU: tau_NMDA_decay,
        IP.TAU_NMDA_RISE: tau_NMDA_rise,
        IP.ALPHA: alpha,
        IP.BETA: beta,
        IP.GAMMA: gamma,
        IP.MG: Mg2,
    })

    MFNonLinearNMDAInput(pop_e1,
                         pop_e1,
                         ee_nmda + {IP.W: 1},
                         name='EE NMDA 1',
                         connection=Connection.all_to_others())

    MFNonLinearNMDAInput(pop_e1,
                         pop_e2,
                         ee_nmda + {IP.W: w_minus},
                         name='EE NMDA 2')

    MFNonLinearNMDAInput(pop_e2,
                         pop_e2,
                         ee_nmda + {IP.W: w_plus},
                         name='EE NMDA 3',
                         connection=Connection.all_to_others())

    MFNonLinearNMDAInput(pop_e2, pop_e1, ee_nmda + {IP.W: 1}, name='EE NMDA 4')

    # E->E AMPA
    ee_ampa = MFParameters({
        IP.GM: g_AMPA_rec_E,
        IP.VREV: V_E,
        IP.TAU: tau_AMPA,
    })

    MFLinearInput(pop_e1, pop_e1, ee_ampa + {IP.W: 1}, name='EE AMPA 1')

    MFLinearInput(pop_e1,
                  pop_e2,
                  ee_ampa + {IP.W: w_minus},
                  name='EE AMPA 2',
                  connection=Connection.all_to_others())

    MFLinearInput(pop_e2, pop_e1, ee_ampa + {IP.W: w_plus}, name='EE AMPA 3')

    MFLinearInput(pop_e2,
                  pop_e2,
                  ee_ampa + {IP.W: 1},
                  name='EE AMPA 4',
                  connection=Connection.all_to_others())

    # E->I NMDA
    ei_nmda = {
        IP.GM: g_NMDA_I,
        IP.VREV: V_E,
        IP.W: 1,
        IP.TAU: tau_NMDA_decay,
        IP.TAU_NMDA_RISE: tau_NMDA_rise,
        IP.ALPHA: alpha,
        IP.BETA: beta,
        IP.GAMMA: gamma,
        IP.MG: Mg2,
    }

    MFNonLinearNMDAInput(pop_e1, pop_i, ei_nmda, name='EI NMDA')

    MFNonLinearNMDAInput(pop_e2, pop_i, ei_nmda, name='EI NMDA 2')

    # E->I AMPA
    ei_ampa = {
        IP.GM: g_AMPA_rec_E,
        IP.VREV: V_E,
        IP.TAU: tau_AMPA,
    }

    MFLinearInput(pop_e1, pop_i, ei_ampa, name='EI AMPA')

    MFLinearInput(pop_e2, pop_i, ei_ampa, name='EI AMPA 2')

    # I->I GABA
    MFLinearInput(pop_i,
                  pop_i, {
                      IP.GM: g_GABA_I,
                      IP.VREV: V_I,
                      IP.TAU: tau_GABA,
                  },
                  name='II GABA',
                  connection=Connection.all_to_others())

    # I->E GABA
    ie_gaba = {
        IP.GM: g_GABA_E,
        IP.VREV: V_I,
        IP.TAU: tau_GABA,
    }

    MFLinearInput(pop_i, pop_e1, ie_gaba, name='IE GABA 1')

    MFLinearInput(pop_i, pop_e2, ie_gaba, name='IE GABA 2')

    return MFSystem(pop_e1, pop_e2, pop_i, name="Brunel Wang 2001")