Exemple #1
0
    def test_theory(self):
        reset_brian2()

        def for_rate(rate):
            pop = MFLinearPopulation(100, {
                PP.GM: 25. * nS,
                PP.CM: 0.5 * nF,
                PP.VL: -70. * mV,
                PP.VTHR: -50. * mV,
                PP.VRES: -55. * mV,
                PP.TAU_RP: 2. * ms
            })
            pop.rate = 10 * Hz

            noise = MFStaticInput(1000, rate * Hz, pop, {
                IP.GM: 2 * nS,
                IP.VREV: 0 * volt,
                IP.TAU: 2. * ms,
            })
            pop.add_noise(noise)

            system = MFSystem(pop)

            solver = MFSolver.rates_voltages(system, solver='mse', maxiter=1)
            print(solver.state)
            sol = solver.run()
            return sol.state[0]

        rates = np.linspace(1, 10, 20)
        dom = np.array([for_rate(r) for r in rates])
        plt.plot(rates, dom)
        plt.xlabel('Noise rate (Hz) per 1000')
        plt.ylabel('Population rate (Hz) per 100')
        plt.show()
Exemple #2
0
    def test_simulation_theory(self):
        reset_brian2()

        t = 1000 * ms
        dt = 0.01 * ms
        defaultclock.dt = dt

        pop = MFLinearPopulation(
            100, {
                PP.GM: 25. * nS,
                PP.CM: 0.5 * nF,
                PP.VL: -70. * mV,
                PP.VTHR: -50. * mV,
                PP.VRES: -55. * mV,
                PP.TAU_RP: 2. * ms
            })
        pop.rate = 1 * Hz

        noise = MFStaticInput(1000, 1 * Hz, pop, {
            IP.GM: 2 * nS,
            IP.VREV: 0 * volt,
            IP.TAU: 2. * ms,
        })

        rec = MFLinearInput(pop, pop, {
            IP.GM: 0.973 / 100 * nS,
            IP.VREV: -70 * volt,
            IP.TAU: 10. * ms,
        })

        system = MFSystem(pop)

        solver = MFSolver.rates_voltages(system, solver='mse', maxiter=1)
        sol = solver.run()
        theory = sol.state[0]

        rate = PopulationRateMonitor(pop.brian2)

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

        #brian2_introspect(net, globals())

        stable_t = int(t / dt * 0.1)
        isolated = np.array(rate.rate)[stable_t:-stable_t]
        print(isolated.mean())

        if False:
            plt.plot(rate.t / ms, rate.smooth_rate(width=25 * ms) / Hz)
            plt.plot(np.ones(10000) * isolated.mean(), label='simulation mean')
            plt.plot(np.ones(10000) * theory, label='theory mean')
            plt.ylabel('Population rate (Hz) per 100')
            plt.xlabel('Simulation time (ms)')
            plt.title('Poisson noise 5 Hz per 1000')
            plt.legend()
            plt.show()
Exemple #3
0
    def test_model_gen(self):
        reset_brian2()
        pop = MFLinearPopulation(1, params_pop)
        source = MFInput(None, pop, params_source, name='test')

        assert_equations(
            source.brian2_model, '''
            I_test = (0. * siemens) * (v - (0. * volt)) * s_test : amp
            ds_test / dt = -s_test / (10. * msecond) : 1
            ''')
Exemple #4
0
    def test_sim(self):
        reset_brian2()
        up, down, inter = self.system.populations

        # MFState < Eup - rate: 1.055, Eup - v_mean: -0.054, Edown - rate: 4.285, Edown - v_mean: -0.053, I - rate: 11.463, I - v_mean: -0.053 >

        rate_up = PopulationRateMonitor(up.brian2)
        rate_down = PopulationRateMonitor(down.brian2)
        rate_inter = PopulationRateMonitor(inter.brian2)

        net = self.system.collect_brian2_network(rate_up, rate_down, rate_inter)
        net.run(3 * units.second)

        plt.plot(rate_up.t / ms, rate_up.smooth_rate(width=200 * ms) / Hz, label='up')
        plt.plot(rate_down.t / ms, rate_down.smooth_rate(width=200 * ms) / Hz, label='down')
        plt.plot(rate_inter.t / ms, rate_inter.smooth_rate(width=200 * ms) / Hz, label='inter')
        plt.legend()
        plt.show()
Exemple #5
0
    def test_simulation_theory(self):
        reset_brian2()

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

        poisson = MFPoissonPopulation(n, 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 = MFLinearNMDAInput(
            poisson, pop, {
                IP.GM: 10 * nsiemens,
                IP.VREV: 0 * mV,
                IP.TAU: 20 * ms,
                IP.TAU_NMDA: 30 * ms,
                IP.BETA: 1,
                IP.GAMMA: 1,
            })

        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)
        print(simulation)

        assert np.isclose(theory, simulation_mean, rtol=0.5, atol=0.5)
Exemple #6
0
def with_rate(rate):
    reset_brian2()

    pop = MFLinearPopulation(n_pop, {
        PP.GM: 25. * nS,
        PP.CM: 0.5 * nF,
        PP.VL: -70. * mV,
        PP.VTHR: -50. * mV,
        PP.VRES: -55. * mV,
        PP.TAU_RP: 2. * ms
    })
    pop.rate = 10 * Hz

    MFStaticInput(n_noise, rate * Hz, pop, {
        IP.GM: 2.08 * nS,
        IP.VREV: 0 * volt,
        IP.TAU: 1.5 * ms,
    })

    system = MFSystem(pop)

    rate = PopulationRateMonitor(pop.brian2)
    net = system.collect_brian2_network(rate)
    net.run(t)

    margin = round(0.5 * second / defaultclock.dt)
    stable = rate.smooth_rate(width=20 * ms)[margin:-margin]

    mean_simu = np.mean(stable)
    std_simu = np.reshape(stable, (samples, -1)).mean(axis=1).std() / np.sqrt(samples) * 1.96
    print(std_simu)

    solver = MFSolver.rates_voltages(system, solver='simplex', maxiter=1)
    sol = solver.run()
    mean_theo = sol.state[0]

    return [mean_theo, mean_simu, std_simu]
Exemple #7
0
        def for_rate(rate):
            reset_brian2()

            pop = MFLinearPopulation(
                n_pop, {
                    PP.GM: 25. * nS,
                    PP.CM: 0.5 * nF,
                    PP.VL: -70. * mV,
                    PP.VTHR: -50. * mV,
                    PP.VRES: -55. * mV,
                    PP.TAU_RP: 2. * ms
                })
            pop.rate = 1 * Hz

            MFStaticInput(n_noise, rate * Hz, pop, {
                IP.GM: 2 * nS,
                IP.VREV: 0 * volt,
                IP.TAU: 2. * ms,
            })

            t = 500 * ms
            dt = 0.1 * ms

            system = MFSystem(pop)
            rate = PopulationRateMonitor(pop.brian2)
            net = system.collect_brian2_network(rate)
            net.run(t)
            stable_t = int(t / dt * 0.1)
            isolated = np.array(rate.rate)[stable_t:-stable_t]
            sim = np.mean(isolated)

            solver = MFSolver.rates_voltages(system,
                                             solver='simplex',
                                             maxiter=1)
            sol = solver.run()
            return [sol.state[0], sim]
Exemple #8
0
    def test_simulation_theory(self):
        reset_brian2()

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

        alpha = 0.5

        poisson = MFPoissonPopulation(n, 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 = MFLinear3TSInput(
            poisson, pop, {
                IP.GM: 10 * nsiemens,
                IP.VREV: 0 * mvolt,
                IP.TAU: 0 * ms,
                IP.TAU_RISE: 2 * ms,
                IP.TAU_D1: 20 * ms,
                IP.TAU_D2: 30 * ms,
                IP.ALPHA: alpha
            })

        system = MFSystem(pop, poisson)

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

        print(syn.brian2)

        m1 = StateMonitor(syn.brian2,
                          syn.post_variable_name[0],
                          record=range(100))
        m2 = StateMonitor(syn.brian2,
                          syn.post_variable_name[1],
                          record=range(100))
        m3 = StateMonitor(syn.brian2,
                          syn.post_variable_name[2],
                          record=range(100))
        m4 = StateMonitor(syn.brian2,
                          syn.post_variable_name[3],
                          record=range(100))
        defaultclock.dt = dt

        net = system.collect_brian2_network(m1, m2, m3, m4)
        net.run(t)

        stable_t = int(t / dt * 0.1)
        simulation_1 = m1.__getattr__(syn.post_variable_name[0])[:, stable_t:]
        simulation_mean_1 = np.mean(simulation_1)
        simulation_2 = m2.__getattr__(syn.post_variable_name[1])[:, stable_t:]
        simulation_mean_2 = np.mean(simulation_2)
        simulation_3 = m3.__getattr__(syn.post_variable_name[2])[:, stable_t:]
        simulation_mean_3 = np.mean(simulation_3)
        simulation_4 = m4.__getattr__(syn.post_variable_name[3])[:, stable_t:]
        simulation_mean_4 = np.mean(simulation_4)

        simulation_mean = alpha * simulation_mean_1 + (
            1 - alpha) * simulation_mean_2 + -alpha * simulation_mean_3 - (
                1 - alpha) * simulation_mean_4

        assert np.isclose(theory, simulation_mean, rtol=0.5, atol=0.5)
Exemple #9
0
from meanfield import plots, modelling
from core.MFSystem import MFSystem
from meanfield.inputs.MFLinearInput import MFLinearInput
from meanfield.inputs.MFNonLinearNMDAInput import MFNonLinearNMDAInput
from meanfield.inputs.MFStaticInput import MFStaticInput
from meanfield.parameters import Connection
from meanfield.parameters import IP
from meanfield.parameters import PP
from meanfield.parameters.MFParameters import MFParameters
from meanfield.populations.MFLinearPopulation import MFLinearPopulation
from meanfield.solvers.MFSolver import MFSolver
from meanfield.utils import reset_brian2

BrianLogger.log_level_debug()
reset_brian2()

# populations
N = 1000
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