Exemple #1
0
def issue274(sim):
    sim.setup(min_delay=0.5)

    p0 = sim.Population(13, sim.IF_cond_exp())
    p1 = sim.Population(1000, sim.IF_cond_exp())
    p2 = sim.Population(252, sim.IF_cond_exp())

    connector = sim.DistanceDependentProbabilityConnector("exp(-d/100)")

    prj = sim.Projection(p1, p2, connector)

    w_dist = rnd("uniform", [1e-6, 2e-6])
    delay_dist = rnd("uniform", [0.5, 1.0])
    prj.set(weight=w_dist, delay=delay_dist)
Exemple #2
0
def issue274(sim):
    sim.setup(min_delay=0.5)

    p0 = sim.Population(13, sim.IF_cond_exp())
    p1 = sim.Population(1000, sim.IF_cond_exp())
    p2 = sim.Population(252, sim.IF_cond_exp())

    connector = sim.DistanceDependentProbabilityConnector("exp(-d/100)")

    prj = sim.Projection(p1, p2, connector)

    w_dist = rnd("uniform", low=1e-6, high=2e-6)
    delay_dist = rnd("uniform", low=0.5, high=1.0)
    prj.set(weight=w_dist, delay=delay_dist)
Exemple #3
0
def issue274(sim):
    """Issue with offset in GIDs"""
    sim.setup(min_delay=0.5)

    p0 = sim.Population(13, sim.IF_cond_exp())
    p1 = sim.Population(1000, sim.IF_cond_exp())
    p2 = sim.Population(252, sim.IF_cond_exp())

    connector = sim.DistanceDependentProbabilityConnector("exp(-d/100)")

    prj = sim.Projection(p1, p2, connector)

    w_dist = rnd("uniform", low=1e-6, high=2e-6)
    delay_dist = rnd("uniform", low=0.5, high=1.0)
    prj.set(weight=w_dist, delay=delay_dist)
Exemple #4
0
    def __init__(self, sim_params=None, cell_params=None, verbose=True):
        '''
        Parameters : Stimulus, Population, Synapses, Recording, Running 
        '''

        self.verbose = verbose
        self.sim_params = sim_params
        self.cell_params = cell_params

        sim.setup()  #spike_precision='on_grid')#timestep = .1)

        N_inh = int(sim_params['nb_neurons'] *
                    sim_params['p'])  #total pop * proportion of inhib
        self.spike_source = sim.Population(
            N_inh,
            sim.SpikeSourcePoisson(rate=sim_params['input_rate'],
                                   duration=sim_params['simtime'] / 2))

        #orientation stimulus, see bottom section of notebook
        angle = 1. * np.arange(N_inh)
        rates = self.tuning_function(angle,
                                     sim_params['angle_input'] / 180. * N_inh,
                                     sim_params['b_input'], N_inh)
        rates /= rates.mean()
        rates *= sim_params['input_rate']
        for i, cell in enumerate(self.spike_source):
            cell.set_parameters(rate=rates[i])

        #neuron model selection
        if sim_params['neuron_model'] == 'IF_cond_alpha':
            model = sim.IF_cond_alpha  #LIF with nice dynamics
        else:
            model = sim.IF_cond_exp  #LIF with exp dynamics

        #populations
        E_neurons = sim.Population(
            N_inh,
            model(**cell_params),
            initial_values={
                'v':
                rnd('uniform',
                    (sim_params['v_init_min'], sim_params['v_init_max']))
            },
            label="Excitateurs")
        I_neurons = sim.Population(
            int(sim_params['nb_neurons'] - N_inh),
            model(**cell_params),
            initial_values={
                'v':
                rnd('uniform',
                    (sim_params['v_init_min'], sim_params['v_init_max']))
            },
            label="Inhibiteurs")

        #input to excitatories
        input_exc = sim.Projection(
            self.spike_source, E_neurons, sim.OneToOneConnector(),
            sim.StaticSynapse(weight=sim_params['w_input_exc'],
                              delay=sim_params['s_input_exc']))

        #loop through connections type and use associated params, can be a bit slow
        conn_types = ['exc_inh', 'inh_exc', 'exc_exc',
                      'inh_inh']  #connection types
        '''
        self.proj = self.set_synapses(conn_types = conn_types, sim_params =sim_params, 
                                      E_neurons = E_neurons, I_neurons = I_neurons, 
                                      N_inh = N_inh)
        '''
        #Multi threading support NE MARCHE PAS LAISSER LE NJOBS EN 1
        self.proj = Parallel(n_jobs=1, backend='multiprocessing')(
            delayed(self.set_synapses)(conn_type,
                                       sim_params=sim_params,
                                       E_neurons=E_neurons,
                                       I_neurons=I_neurons,
                                       N_inh=N_inh,
                                       conn_types=conn_types,
                                       verbose=verbose)
            for conn_type in range(len(conn_types)))
        if verbose: print('Done building synapses !')

        #record
        self.spike_source.record('spikes')
        E_neurons.record('spikes')
        I_neurons.record('spikes')

        #run
        if verbose: print('Running simulation..')
        sim.run(sim_params['simtime'])
        if verbose: print('Done running !')

        #get the spikes
        self.E_spikes = E_neurons  #.get_data().segments[0]
        self.I_spikes = I_neurons  #.get_data().segments[0]
        self.P_spikes = self.spike_source  #.get_data().segments[0]
    'tau_refrac' : 2.0,    # (ms)
    'v_rest'     : -60.0,  # (mV)
    'v_reset'    : -70.0,  # (mV)
    'v_thresh'   : -50.0,  # (mV)
    'cm'         : 0.5}    # (nF)
dt         = 0.1           # (ms)
syn_delay  = 1.0           # (ms)
input_rate = 50.0          # (Hz)
simtime    = 1000.0        # (ms)

# === Build the network ========================================================

sim.setup(timestep=dt, max_delay=syn_delay)

cells = sim.Population(n, sim.IF_cond_alpha(**cell_params),
                       initial_values={'v': rnd('uniform', (-60.0, -50.0))},
                       label="cells")

number = int(2 * simtime * input_rate / 1000.0)
numpy.random.seed(26278342)


def generate_spike_times(i):
    gen = lambda: Sequence(numpy.add.accumulate(numpy.random.exponential(1000.0 / input_rate, size=number)))
    if hasattr(i, "__len__"):
        return [gen() for j in i]
    else:
        return gen()
assert generate_spike_times(0).max() > simtime

spike_source = sim.Population(n, sim.SpikeSourceArray(spike_times=generate_spike_times))
cell_params = {
    'tau': 20.0,  # (ms)
    'refrac': 2.0,  # (ms)
}
dt = 0.1  # (ms)
syn_delay = 1.0  # (ms)
input_rate = 50.0  # (Hz)
simtime = 1000.0  # (ms)

# === Build the network ========================================================

sim.setup(timestep=dt, max_delay=syn_delay)

cells = sim.Population(n,
                       sim.IntFire1(**cell_params),
                       initial_values={'m': rnd('uniform', (0.0, 1.0))},
                       label="cells")

number = int(2 * simtime * input_rate / 1000.0)
np.random.seed(26278342)


def generate_spike_times(i):
    gen = lambda: Sequence(
        np.add.accumulate(
            np.random.exponential(1000.0 / input_rate, size=number)))
    if hasattr(i, "__len__"):
        return [gen() for j in i]
    else:
        return gen()
Exemple #7
0
    def model(self, sim_index=0, sim_params=None, cell_params=None):
        if sim_params is None :
            sim_params = self.sim_params

        if cell_params is None:
            cell_params = self.cell_params

        # === Build the network =========================================================

        sim.setup(timestep=0.1)#, threads=4)#dt=sim_params['dt'])

        python_rng = rng(seed=self.seed)

        #--setting up nodes and neurons--

        #tuning_function = lambda i, j, B, N : np.exp((np.cos(2.*((i-j)/N*np.pi))-1)/(B*np.pi/180)**2)
        N_in = int(sim_params['nb_neurons']*sim_params['p'])
        self.spike_source = sim.Population(N_in, sim.SpikeSourcePoisson(rate=sim_params['input_rate'], duration=sim_params['simtime']))

        if True: #not sim_params['b_input'] == np.inf:
            angle = 1. * np.arange(N_in)
            rates = self.tuning_function(angle, sim_params['angle_input']/180.*N_in, sim_params['b_input'], N_in)
            rates /= rates.mean()
            rates *= sim_params['input_rate']
            # print(rates)
            for i, cell in enumerate(self.spike_source):
                cell.set_parameters(rate=rates[i])


        if sim_params['neuron_model'] == 'cond_exp':
            model = sim.IF_cond_exp
        elif sim_params['neuron_model'] == 'cond_alpha':
            model = sim.IF_cond_alpha

        E_neurons = sim.Population(N_in,
                                   model(**cell_params),
                                   initial_values={'v': rnd('uniform', (sim_params['v_init_min'], sim_params['v_init_max']))},
                                   label="NE")

        I_neurons = sim.Population(sim_params['nb_neurons'] - N_in,
                                   model(**cell_params),
                                   initial_values={'v': rnd('uniform', (sim_params['v_init_min'], sim_params['v_init_max']))},
                                   label="NI")
        #
        # if sim_params['neuron_model'] == 'cond_alpha':
        #     E_neurons = sim.Population(int(sim_params['nb_neurons'] * sim_params['p']),
        #                                sim.IF_cond_alpha(**cell_params),
        #                                initial_values={'v': rnd('uniform', (sim_params['v_init_min'], sim_params['v_init_max']))},
        #                                label="NE")
        #
        #     I_neurons = sim.Population(sim_params['nb_neurons'] - int(sim_params['nb_neurons'] * sim_params['p']),
        #                                sim.IF_cond_alpha(**cell_params),
        #                                initial_values={'v': rnd('uniform', (sim_params['v_init_min'], sim_params['v_init_max']))},
        #                                label="NI")

         #--Setting up connections and optional injections--
        if self.source == 'sweep':
            sweep = sim.DCSource(amplitude=0.1, start=250.0, stop=500.0)
            sweep.inject_into(E_neurons)

        input_exc = sim.Projection(self.spike_source, E_neurons,
                                #connector=sim.FixedProbabilityConnector(sim_params['c_input_exc'], rng=python_rng),
                                #synapse_type=syn['input_exc'],
                                #receptor_type='excitatory')
                                sim.OneToOneConnector(),
                                sim.StaticSynapse(weight=sim_params['w_input_exc'], delay=sim_params['s_input_exc'])
                                )
                                # syn['input_exc'])

        conn_types = ['exc_inh', 'inh_exc', 'exc_exc', 'inh_inh']   #connection types

        syn = {}
        proj = {}

        for conn_type in conn_types :

            weight = sim_params['w_{}'.format(conn_type)]
            delay=sim_params['s_{}'.format(conn_type)]
            syn[conn_type] = sim.StaticSynapse(delay=delay)#weight=weight,
            if conn_type[:3]=='exc':
                pre_neurons = E_neurons
                receptor_type='excitatory'
            else:
                pre_neurons = I_neurons
                receptor_type='inhibitory'
            if conn_type[-3:]=='exc':
                post_neurons = E_neurons
            else:
                post_neurons = I_neurons

            sparseness = sim_params['c_{}'.format(conn_type)]
            proj[conn_type]  = sim.Projection(pre_neurons, post_neurons,
                                            connector=sim.FixedProbabilityConnector(sparseness, rng=python_rng),
                                            synapse_type=syn[conn_type],
                                            receptor_type=receptor_type)

            bw = sim_params['b_{}'.format(conn_type)]
            angle_pre = 1. * np.arange(proj[conn_type].pre.size)
            angle_post = 1. * np.arange(proj[conn_type].post.size)
            w_ij = self.tuning_function(angle_pre[:, np.newaxis], angle_post[np.newaxis, :], bw, N_in)*weight
            proj[conn_type].set(weight=w_ij)

        # exc_inh = sim.Projection(E_neurons, I_neurons,
        #                         connector=sim.FixedProbabilityConnector(sim_params['c_exc_inh'], rng=python_rng),
        #                         synapse_type=syn['exc_inh'],
        #                         receptor_type='excitatory')
        #
        # inh_exc = sim.Projection(I_neurons, E_neurons,
        #                         connector=sim.FixedProbabilityConnector(sim_params['c_inh_exc'], rng=python_rng),
        #                         synapse_type=syn['inh_exc'],
        #                         receptor_type='inhibitory')
        #
        # exc_exc = sim.Projection(E_neurons, E_neurons,
        #                         connector=sim.FixedProbabilityConnector(sim_params['c_exc_exc'], rng=python_rng),
        #                         synapse_type=syn['exc_exc'],
        #                         receptor_type='excitatory')
        #
        # inh_inh = sim.Projection(I_neurons, I_neurons,
        #                         connector=sim.FixedProbabilityConnector(sim_params['c_inh_inh'], rng=python_rng),
        #                         synapse_type=syn['inh_inh'],
        #                         receptor_type='inhibitory')
        #
        # v = locals()
        # for conn_type in conn_types :
        #     proj = v['{}'.format(conn_type)]
        #     if not bw == np.inf:
        #         angle_pre = 1. * np.arange(proj.pre.size)
        #         angle_post = 1. * np.arange(proj.post.size)
        #         w = tuning_function(angle_pre[:, np.newaxis], angle_post[np.newaxis, :], bw, N_in)*w
        #         proj.set(weight=w)
        #

        #--setting up recording--
        self.spike_source.record('spikes')
        E_neurons.record('spikes')
        I_neurons.record('spikes')

        # === Run simulation ============================================================
        sim.run(sim_params['simtime'])

        # === Save ROI data and CV computing ============================================
        spikesE = E_neurons.get_data().segments[0]
        spikesI = I_neurons.get_data().segments[0]
        self.spikesP = self.spike_source.get_data().segments[0]

        self.spikesE = spikesE
        self.spikesI = spikesI

        #------- computing cv -------
        all_CVs = np.array([])
        for st in spikesE.spiketrains :
            all_CVs = np.append(all_CVs, SpikeTrain(np.array(st)).cv_isi())
        for st in spikesI.spiketrains :
            all_CVs = np.append(all_CVs, SpikeTrain(np.array(st)).cv_isi())
        #-----------------------------

        megadico = sim_params.copy()
        megadico.update(cell_params.copy())
        megadico.update({'m_f_rateE': E_neurons.mean_spike_count()})
        megadico.update({'m_f_rateI': I_neurons.mean_spike_count()})
        megadico.update({'m_f_rate' : (E_neurons.mean_spike_count()*sim_params['p'] + I_neurons.mean_spike_count()*(1-sim_params['p']))*1000.0/sim_params['simtime']})
        megadico.update({'cv' : np.nanmean(all_CVs)})

        # === Clearing and return data ==================================================
        sim.end()
        df = ps.DataFrame(data = megadico, index = [sim_index])
        return df, spikesE, spikesI
Exemple #8
0
    "v_rest": -60.0,  # (mV)
    "v_reset": -70.0,  # (mV)
    "v_thresh": -50.0,  # (mV)
    "cm": 0.5,
}  # (nF)
dt = 0.1  # (ms)
syn_delay = 1.0  # (ms)
input_rate = 50.0  # (Hz)
simtime = 1000.0  # (ms)

# === Build the network ========================================================

sim.setup(timestep=dt, max_delay=syn_delay)

cells = sim.Population(
    n, sim.IF_cond_alpha(**cell_params), initial_values={"v": rnd("uniform", (-60.0, -50.0))}, label="cells"
)

number = int(2 * simtime * input_rate / 1000.0)
numpy.random.seed(26278342)


def generate_spike_times(i):
    gen = lambda: Sequence(numpy.add.accumulate(numpy.random.exponential(1000.0 / input_rate, size=number)))
    if hasattr(i, "__len__"):
        return [gen() for j in i]
    else:
        return gen()


assert generate_spike_times(0).max() > simtime
w = 0.1  # synaptic weight (dimensionless)
cell_params = {
    'tau'    : 20.0,   # (ms)
    'refrac' : 2.0,    # (ms)
}
dt         = 0.1           # (ms)
syn_delay  = 1.0           # (ms)
input_rate = 50.0          # (Hz)
simtime    = 1000.0        # (ms)

# === Build the network ========================================================

sim.setup(timestep=dt, max_delay=syn_delay)

cells = sim.Population(n, sim.IntFire1(**cell_params),
                       initial_values={'m': rnd('uniform', (0.0, 1.0))},
                       label="cells")

number = int(2 * simtime * input_rate / 1000.0)
numpy.random.seed(26278342)


def generate_spike_times(i):
    gen = lambda: Sequence(numpy.add.accumulate(numpy.random.exponential(1000.0 / input_rate, size=number)))
    if hasattr(i, "__len__"):
        return [gen() for j in i]
    else:
        return gen()
assert generate_spike_times(0).max() > simtime

spike_source = sim.Population(n, sim.SpikeSourceArray(spike_times=generate_spike_times))