Esempio n. 1
0
def do_run(plot):

    p.setup(timestep=1.0)

    cell_params_lif = {'cm': 0.25,
                       'i_offset': 0.0,
                       'tau_m': 20.0,
                       'tau_refrac': 2.0,
                       'tau_syn_E': 5.0,
                       'tau_syn_I': 5.0,
                       'v_reset': -70.0,
                       'v_rest': -65.0,
                       'v_thresh': -40.0
                       }

    # Parameters
    n = 256
    weight_to_spike = 5.0
    delay = 5
    runtime = 200

    # Populations
    exc_pop = p.Population(n, p.IF_curr_exp(**cell_params_lif),
                           label='exc_pop')
    inh_pop = p.Population(n, p.IF_curr_exp(**cell_params_lif),
                           label='inh_pop')

    # SpikeInjector
    injectionConnection = [(0, 0)]
    spikeArray = {'spike_times': [[0]]}
    inj_pop = p.Population(1, p.SpikeSourceArray(**spikeArray),
                           label='inputSpikes_1')

    # Projection for injector
    p.Projection(inj_pop, exc_pop, p.FromListConnector(injectionConnection),
                 p.StaticSynapse(weight=weight_to_spike, delay=delay))

    # Set up fromfileconnector
    current_file_path = os.path.dirname(os.path.abspath(__file__))
    file1 = os.path.join(current_file_path, "large.connections")
    file_connector1 = p.FromFileConnector(file1)

    # Projections between populations
    p.Projection(exc_pop, inh_pop, file_connector1,
                 p.StaticSynapse(weight=2.0, delay=5))
    p.Projection(inh_pop, exc_pop, file_connector1,
                 p.StaticSynapse(weight=1.5, delay=10))
    p.Projection(inh_pop, exc_pop, file_connector1,
                 p.StaticSynapse(weight=1.0, delay=1))

    exc_pop.record(['v', 'spikes'])
    inh_pop.record(['v', 'spikes'])
    p.run(runtime)

    v_exc = exc_pop.get_data('v')
    spikes_exc = exc_pop.get_data('spikes')

    if plot:
        # pylint: disable=no-member
        Figure(
            # raster plot of the presynaptic neurons' spike times
            Panel(spikes_exc.segments[0].spiketrains,
                  yticks=True, markersize=1.2, xlim=(0, runtime), xticks=True),
            # membrane potential of the postsynaptic neurons
            Panel(v_exc.segments[0].filter(name='v')[0],
                  ylabel="Membrane potential (mV)",
                  data_labels=[exc_pop.label], yticks=True,
                  xlim=(0, runtime), xticks=True),
            title="Testing FromFileConnector",
            annotations="Simulated with {}".format(p.name())
        )
        plt.show()

    p.end()

    return v_exc, spikes_exc
projections.append(
    p.Projection(populations[0], populations[0],
                 p.FromListConnector(loopConnections)))
projections.append(
    p.Projection(populations[1], populations[0],
                 p.FromListConnector(injectionConnection)))

populations[0].record('spikes')

# Activate live output for the population
p.external_devices.activate_live_output_for(populations[0],
                                            database_notify_host="localhost",
                                            database_notify_port_num=19999)

# Start the simulation
p.run(5000)

spikes = populations[0].get_data("spikes")

Figure(
    # raster plot of the presynaptic neuron spike times
    Panel(spikes.segments[0].spiketrains,
          yticks=True,
          markersize=0.2,
          xlim=(0, 5000)),
    title="Simple synfire chain example with injected spikes",
    annotations="Simulated with {}".format(p.name()))
plt.show()

p.end()
Esempio n. 3
0
def do_run(plot):

    p.setup(timestep=1.0)

    cell_params_lif = {
        'cm': 0.25,
        'i_offset': 0.0,
        'tau_m': 20.0,
        'tau_refrac': 2.0,
        'tau_syn_E': 5.0,
        'tau_syn_I': 5.0,
        'v_reset': -70.0,
        'v_rest': -65.0,
        'v_thresh': -50.0
    }

    # Parameters
    nNeurons = 200
    weight_to_spike = 2.0
    delay = 17
    runtime = 5000
    p.set_number_of_neurons_per_core(p.IF_curr_exp, nNeurons / 2)

    # Populations
    pop = p.Population(nNeurons,
                       p.IF_curr_exp(**cell_params_lif),
                       label='pop_1')
    pop2 = p.Population(nNeurons,
                        p.IF_curr_exp(**cell_params_lif),
                        label='pop_2')

    # create loopConnections array for first population using numpy linspaces
    loopConnections = numpy.zeros((nNeurons, nNeurons))
    for i in range(nNeurons):
        if i != (nNeurons - 1):
            loopConnections[i, i + 1] = True
        else:
            loopConnections[i, 0] = True

    # do the same for the second population, but just for even numbered neurons
    loopConnections2 = numpy.zeros((nNeurons, nNeurons))
    for i in range(0, nNeurons, 2):
        if i != (nNeurons - 2):
            loopConnections2[i, i + 2] = True
        else:
            loopConnections2[i, 0] = True

    # SpikeInjector
    injectionConnection = numpy.zeros((1, nNeurons))
    injectionConnection[0, 0] = True
    spikeArray = {'spike_times': [[0]]}
    inj_pop = p.Population(1,
                           p.SpikeSourceArray(**spikeArray),
                           label='inputSpikes_1')

    # Projection for injector
    p.Projection(inj_pop, pop, p.ArrayConnector(injectionConnection),
                 p.StaticSynapse(weight=weight_to_spike, delay=1))
    p.Projection(inj_pop, pop2, p.ArrayConnector(injectionConnection),
                 p.StaticSynapse(weight=weight_to_spike, delay=1))

    # Projection within populations
    p.Projection(pop, pop, p.ArrayConnector(loopConnections),
                 p.StaticSynapse(weight=weight_to_spike, delay=delay))
    p.Projection(pop2, pop2, p.ArrayConnector(loopConnections2),
                 p.StaticSynapse(weight=weight_to_spike, delay=delay))

    pop.record(['v', 'spikes'])
    pop2.record(['v', 'spikes'])
    p.run(runtime)

    v = pop.get_data('v')
    spikes = pop.get_data('spikes')
    v2 = pop2.get_data('v')
    spikes2 = pop2.get_data('spikes')

    if plot:
        Figure(
            # raster plot of the presynaptic neurons' spike times
            Panel(spikes.segments[0].spiketrains,
                  yticks=True,
                  markersize=1.2,
                  xlim=(0, runtime),
                  xticks=True),
            # membrane potential of the postsynaptic neurons
            Panel(v.segments[0].filter(name='v')[0],
                  ylabel="Membrane potential (mV)",
                  data_labels=[pop.label],
                  yticks=True,
                  xlim=(0, runtime),
                  xticks=True),
            Panel(spikes2.segments[0].spiketrains,
                  yticks=True,
                  markersize=1.2,
                  xlim=(0, runtime),
                  xticks=True),
            # membrane potential of the postsynaptic neurons
            Panel(v2.segments[0].filter(name='v')[0],
                  ylabel="Membrane potential (mV)",
                  data_labels=[pop2.label],
                  yticks=True,
                  xlim=(0, runtime),
                  xticks=True),
            title="Testing ArrayConnector",
            annotations="Simulated with {}".format(p.name()))
        plt.show()

    p.end()

    return v, spikes, v2, spikes2
Esempio n. 4
0
    # Set up callbacks to occur when spikes are received
    live_spikes_connection_receive.add_receive_callback(
        "pop_forward", receive_spikes)
    live_spikes_connection_receive.add_receive_callback(
        "pop_backward", receive_spikes)

# Run the simulation on spiNNaker
Frontend.run(run_time)

spikes_forward = pop_forward.get_data('spikes')
spikes_backward = pop_backward.get_data('spikes')

Figure(
    # raster plot of the presynaptic neuron spike times
    Panel(spikes_forward.segments[0].spiketrains,
          yticks=True,
          markersize=0.2,
          xlim=(0, run_time)),
    Panel(spikes_backward.segments[0].spiketrains,
          yticks=True,
          markersize=0.2,
          xlim=(0, run_time)),
    title="Simple synfire chain example with injected spikes",
    annotations="Simulated with {}".format(Frontend.name()))
plt.show()

# Clear data structures on spiNNaker to leave the machine in a clean state for
# future executions
Frontend.end()
Esempio n. 5
0
def do_run(plot):

    p.setup(timestep=1.0)

    cell_params_lif = {'cm': 0.25,
                       'i_offset': 0.0,
                       'tau_m': 20.0,
                       'tau_refrac': 2.0,
                       'tau_syn_E': 5.0,
                       'tau_syn_I': 5.0,
                       'v_reset': -70.0,
                       'v_rest': -65.0,
                       'v_thresh': -40.0
                       }

    def create_grid(n, label, dx=1.0, dy=1.0):
        grid_structure = p.Grid2D(dx=dx, dy=dy, x0=0.0, y0=0.0)
        return p.Population(n*n, p.IF_curr_exp(**cell_params_lif),
                            structure=grid_structure, label=label)

    n = 4
    weight_to_spike = 5.0
    delay = 5
    runtime = 200

    # Network
    grid = create_grid(n, 'grid')

    # SpikeInjector
    injectionConnection = [(0, 0)]
    spikeArray = {'spike_times': [[0]]}
    inj_pop = p.Population(1, p.SpikeSourceArray(**spikeArray),
                           label='inputSpikes_1')

    p.Projection(inj_pop, grid, p.FromListConnector(injectionConnection),
                 p.StaticSynapse(weight=weight_to_spike, delay=delay))

    # Connectors
    exc_connector = p.AllToAllConnector()
    inh_connector = p.FixedProbabilityConnector(0.5, rng=NumpyRNG(seed=10101))

    # Wire grid
    exc_proj = p.Projection(grid, grid, exc_connector,
                            p.StaticSynapse(
                                weight="1.0 + (2.0*exp(-d))", delay=5))
    inh_proj = p.Projection(grid, grid, inh_connector,
                            p.StaticSynapse(
                                weight=1.5, delay="2 + 2.0*d"))

    grid.record(['v', 'spikes'])

    p.run(runtime)

    v = grid.get_data('v')
    spikes = grid.get_data('spikes')

    exc_weights_delays = exc_proj.get(['weight', 'delay'], 'list')
    inh_weights_delays = inh_proj.get(['weight', 'delay'], 'list')

    if plot:
        Figure(
            # raster plot of the presynaptic neurons' spike times
            Panel(spikes.segments[0].spiketrains,
                  yticks=True, markersize=0.2, xlim=(0, runtime), xticks=True),
            # membrane potential of the postsynaptic neurons
            Panel(v.segments[0].filter(name='v')[0],
                  ylabel="Membrane potential (mV)",
                  data_labels=[grid.label], yticks=True, xlim=(0, runtime),
                  xticks=True),
            title="Simple 2D grid distance-dependent weights and delays",
            annotations="Simulated with {}".format(p.name())
        )
        plt.show()

    p.end()

    return exc_weights_delays, inh_weights_delays
    def __init__(self):

        # initial call to set up the front end (pynn requirement)
        Frontend.setup(timestep=1.0, min_delay=1.0, max_delay=144.0)

        use_c_visualiser = True
        use_spike_injector = True

        # neurons per population and the length of runtime in ms for the
        # simulation, as well as the expected weight each spike will contain
        self.n_neurons = 100

        # set up gui
        p = None
        if use_spike_injector:
            from multiprocessing import Process
            from multiprocessing import Event
            ready = Event()
            p = Process(target=GUI, args=[self.n_neurons, ready])
            p.start()
            ready.wait()

        # different runtimes for demostration purposes
        run_time = None
        if not use_c_visualiser and not use_spike_injector:
            run_time = 1000
        elif use_c_visualiser and not use_spike_injector:
            run_time = 10000
        elif use_c_visualiser and use_spike_injector:
            run_time = 100000
        elif not use_c_visualiser and use_spike_injector:
            run_time = 10000

        weight_to_spike = 2.0

        # neural parameters of the IF_curr model used to respond to injected
        # spikes.
        # (cell params for a synfire chain)
        cell_params_lif = {'cm': 0.25,
                           'i_offset': 0.0,
                           'tau_m': 20.0,
                           'tau_refrac': 2.0,
                           'tau_syn_E': 5.0,
                           'tau_syn_I': 5.0,
                           'v_reset': -70.0,
                           'v_rest': -65.0,
                           'v_thresh': -50.0
                           }

        ##################################
        # Parameters for the injector population.  This is the minimal set of
        # parameters required, which is for a set of spikes where the key is
        # not important.  Note that a virtual key *will* be assigned to the
        # population, and that spikes sent which do not match this virtual key
        # will be dropped; however, if spikes are sent using 16-bit keys, they
        # will automatically be made to match the virtual key.  The virtual
        # key assigned can be obtained from the database.
        ##################################
        cell_params_spike_injector = {

            # The port on which the spiNNaker machine should listen for
            # packets. Packets to be injected should be sent to this port on
            # the spiNNaker machine
            'port': 12345
        }

        ##################################
        # Parameters for the injector population.  Note that each injector
        # needs to be given a different port.  The virtual key is assigned
        # here, rather than being allocated later.  As with the above, spikes
        # injected need to match this key, and this will be done automatically
        # with 16-bit keys.
        ##################################
        cell_params_spike_injector_with_key = {

            # The port on which the spiNNaker machine should listen for
            # packets. Packets to be injected should be sent to this port on
            # the spiNNaker machine
            'port': 12346,

            # This is the base key to be used for the injection, which is used
            # to allow the keys to be routed around the spiNNaker machine.
            # This assignment means that 32-bit keys must have the high-order
            # 16-bit set to 0x7; This will automatically be prepended to
            # 16-bit keys.
            'virtual_key': 0x70000
        }

        # create synfire populations (if cur exp)
        pop_forward = Frontend.Population(
            self.n_neurons, Frontend.IF_curr_exp(**cell_params_lif),
            label='pop_forward')
        pop_backward = Frontend.Population(
            self.n_neurons, Frontend.IF_curr_exp(**cell_params_lif),
            label='pop_backward')

        # Create injection populations
        injector_forward = None
        injector_backward = None
        if use_spike_injector:
            injector_forward = Frontend.Population(
                self.n_neurons,
                Frontend.external_devices.SpikeInjector(
                    **cell_params_spike_injector_with_key),
                label='spike_injector_forward')
            injector_backward = Frontend.Population(
                self.n_neurons,
                Frontend.external_devices.SpikeInjector(
                    **cell_params_spike_injector),
                label='spike_injector_backward')
        else:
            spike_times = []
            for _ in range(0, self.n_neurons):
                spike_times.append([])
            spike_times[0] = [0]
            spike_times[20] = [(run_time / 100) * 20]
            spike_times[40] = [(run_time / 100) * 40]
            spike_times[60] = [(run_time / 100) * 60]
            spike_times[80] = [(run_time / 100) * 80]
            cell_params_forward = {'spike_times': spike_times}
            spike_times_backwards = []
            for _ in range(0, self.n_neurons):
                spike_times_backwards.append([])
            spike_times_backwards[0] = [(run_time / 100) * 80]
            spike_times_backwards[20] = [(run_time / 100) * 60]
            spike_times_backwards[40] = [(run_time / 100) * 40]
            spike_times_backwards[60] = [(run_time / 100) * 20]
            spike_times_backwards[80] = [0]
            cell_params_backward = {'spike_times': spike_times_backwards}
            injector_forward = Frontend.Population(
                self.n_neurons, Frontend.SpikeSourceArray(
                    **cell_params_forward),
                label='spike_injector_forward')
            injector_backward = Frontend.Population(
                self.n_neurons, Frontend.SpikeSourceArray(
                    **cell_params_backward),
                label='spike_injector_backward')

        # Create a connection from the injector into the populations
        Frontend.Projection(
            injector_forward, pop_forward,
            Frontend.OneToOneConnector(),
            Frontend.StaticSynapse(weight=weight_to_spike))
        Frontend.Projection(
            injector_backward, pop_backward,
            Frontend.OneToOneConnector(),
            Frontend.StaticSynapse(weight=weight_to_spike))

        # Synfire chain connections where each neuron is connected to its next
        # neuron
        # NOTE: there is no recurrent connection so that each chain stops once
        # it reaches the end
        loop_forward = list()
        loop_backward = list()
        for i in range(0, self.n_neurons - 1):
            loop_forward.append((i, (i + 1) %
                                 self.n_neurons, weight_to_spike, 3))
            loop_backward.append(((i + 1) %
                                  self.n_neurons, i, weight_to_spike, 3))
        Frontend.Projection(pop_forward, pop_forward,
                            Frontend.FromListConnector(loop_forward))
        Frontend.Projection(pop_backward, pop_backward,
                            Frontend.FromListConnector(loop_backward))

        # record spikes from the synfire chains so that we can read off valid
        # results in a safe way afterwards, and verify the behavior
        pop_forward.record('spikes')
        pop_backward.record('spikes')

        # Activate the sending of live spikes
        Frontend.external_devices.activate_live_output_for(
            pop_forward, database_notify_host="localhost",
            database_notify_port_num=19996)
        Frontend.external_devices.activate_live_output_for(
            pop_backward, database_notify_host="localhost",
            database_notify_port_num=19996)

        if not use_c_visualiser:
            # if not using the c visualiser, then a new spynnaker live spikes
            # connection is created to define that there are python code which
            # receives the outputted spikes.
            live_spikes_connection_receive = \
                Frontend.external_devices.SpynnakerLiveSpikesConnection(
                    receive_labels=["pop_forward", "pop_backward"],
                    local_port=19999, send_labels=None)

            # Set up callbacks to occur when spikes are received
            live_spikes_connection_receive.add_receive_callback(
                "pop_forward", receive_spikes)
            live_spikes_connection_receive.add_receive_callback(
                "pop_backward", receive_spikes)

        # Run the simulation on spiNNaker
        Frontend.run(run_time)

        # Retrieve spikes from the synfire chain population
        spikes_forward = pop_forward.get_data('spikes')
        spikes_backward = pop_backward.get_data('spikes')

        # Clear data structures on spiNNaker to leave the machine in a clean
        # state for future executions
        Frontend.end()

        if use_spike_injector:
            p.join()

        Figure(
            # raster plot of the presynaptic neuron spike times
            Panel(spikes_forward.segments[0].spiketrains,
                  yticks=True, markersize=0.2, xlim=(0, run_time)),
            Panel(spikes_backward.segments[0].spiketrains,
                  yticks=True, markersize=0.2, xlim=(0, run_time)),
            title="Simple synfire chain example with injected spikes",
            annotations="Simulated with {}".format(Frontend.name())
        )
        plt.show()
def do_run(plot):

    p.setup(timestep=1.0)

    cell_params_lif = {'cm': 0.25,
                       'i_offset': 0.0,
                       'tau_m': 20.0,
                       'tau_refrac': 2.0,
                       'tau_syn_E': 5.0,
                       'tau_syn_I': 5.0,
                       'v_reset': -70.0,
                       'v_rest': -65.0,
                       'v_thresh': -40.0
                       }

    # Parameters
    n = 6
    weight_to_spike = 3.0
    delay = 2
    runtime = 200

    # Network population
    pop_1 = p.Population(n, p.IF_curr_exp(**cell_params_lif), label='pop_1')
    pop_2 = p.Population(n/2, p.IF_curr_exp(**cell_params_lif), label='pop_2')

    # SpikeInjector
    injectionConnection = [(0, n/2)]
    spikeArray = {'spike_times': [[0]]}
    inj_pop = p.Population(1, p.SpikeSourceArray(**spikeArray),
                           label='inputSpikes_1')

    # Projection for injector
    p.Projection(inj_pop, pop_1, p.FromListConnector(injectionConnection),
                 p.StaticSynapse(weight=weight_to_spike, delay=delay))

    # Index-based connectors
    index_based_exc = "(i+j)/"+str(n*(n-n/2.0))
    index_based_exc2 = "2.0*(i+j)/"+str(n*(n-n/2.0))
    index_based_inh = "(i+j)/"+str(n*(n+n/2.0))
    print('index_based_exc: ', index_based_exc)
    print('index_based_exc2: ', index_based_exc2)

    exc_connector = p.IndexBasedProbabilityConnector(
        index_based_exc, allow_self_connections=True)
    inh_connector = p.IndexBasedProbabilityConnector(
        index_based_inh, allow_self_connections=False)
    exc_connector2 = p.IndexBasedProbabilityConnector(
        index_based_exc2, allow_self_connections=True)

    # Projections within populations
    p.Projection(pop_1, pop_1, exc_connector,
                 p.StaticSynapse(weight=2.0, delay=5))
    p.Projection(pop_1, pop_1, inh_connector,
                 p.StaticSynapse(weight=1.5, delay=5))

    p.Projection(pop_1, pop_2, exc_connector2,
                 p.StaticSynapse(weight=1.5, delay=2))

    pop_1.record(['v', 'spikes'])
    pop_2.record(['v', 'spikes'])

    p.run(runtime)

    v = pop_1.get_data('v')
    spikes = pop_1.get_data('spikes')
    v2 = pop_2.get_data('v')
    spikes2 = pop_2.get_data('spikes')

    if plot:
        Figure(
            # raster plot of the presynaptic neurons' spike times
            Panel(spikes.segments[0].spiketrains,
                  yticks=True, markersize=2.0, xlim=(0, runtime), xticks=True),
            # membrane potential of the postsynaptic neurons
            Panel(v.segments[0].filter(name='v')[0],
                  ylabel="Membrane potential pop 1 (mV)",
                  data_labels=[pop_1.label], yticks=True,
                  xlim=(0, runtime), xticks=True),
            # raster plot of the presynaptic neurons' spike times
            Panel(spikes2.segments[0].spiketrains,
                  yticks=True, markersize=2.0, xlim=(0, runtime), xticks=True),
            # membrane potential of the postsynaptic neurons
            Panel(v2.segments[0].filter(name='v')[0],
                  ylabel="Membrane potential pop 2 (mV)",
                  data_labels=[pop_2.label], yticks=True,
                  xlim=(0, runtime), xticks=True),
            title="Simple index-based probability connector",
            annotations="Simulated with {}".format(p.name())
        )
        plt.show()

    p.end()

    return v, spikes, v2, spikes2
# Synapse value as weight = 5.0 nA, delay = 2 ms
static_synapse = sim.StaticSynapse( weight = 5.0, delay = 2 )

sim.Projection( pop_input,
                pop_output,
                sim.OneToOneConnector(),
                synapse_type = static_synapse,
                label = "LIF - alpha function Projection"
              )

# == Instrument the network ====================================================

# Record all to observe.
pop_output.record( "all" )

# === Run the simulation =======================================================

sim.run( sim_time )

# === Plot the results =========================================================

from util.basic_visualizer import *
plot( [pop_output],
      "IF_curr_alpha Neuron Model Examination",
      "Simulated with {}".format( sim.name() ) )

# === Clean up and quit ========================================================

sim.end()
def do_run(plot):

    p.setup(timestep=1.0)

    cell_params_lif = {
        'cm': 0.25,
        'i_offset': 0.0,
        'tau_m': 20.0,
        'tau_refrac': 2.0,
        'tau_syn_E': 5.0,
        'tau_syn_I': 5.0,
        'v_reset': -70.0,
        'v_rest': -65.0,
        'v_thresh': -50.0
    }

    def create_grid(n, label, dx=1.0, dy=1.0):
        grid_structure = p.Grid2D(dx=dx, dy=dy, x0=0.0, y0=0.0)
        return p.Population(n * n,
                            p.IF_curr_exp(**cell_params_lif),
                            structure=grid_structure,
                            label=label)

    # Parameters
    n = 5
    weight_to_spike = 2.0
    delay = 2
    runtime = 1000
    p.set_number_of_neurons_per_core(p.IF_curr_exp, 100)

    # Network population
    small_world = create_grid(n, 'small_world')

    # SpikeInjector
    injectionConnection = [(0, 0)]
    spikeArray = {'spike_times': [[0]]}
    inj_pop = p.Population(1,
                           p.SpikeSourceArray(**spikeArray),
                           label='inputSpikes_1')

    # Injector projection
    p.Projection(inj_pop, small_world,
                 p.FromListConnector(injectionConnection),
                 p.StaticSynapse(weight=weight_to_spike, delay=delay))

    # Connectors
    degree = 2.0
    rewiring = 0.4
    small_world_connector = p.SmallWorldConnector(degree, rewiring)

    # Projection for small world grid
    sw_pro = p.Projection(small_world, small_world, small_world_connector,
                          p.StaticSynapse(weight=2.0, delay=5))

    small_world.record(['v', 'spikes'])

    p.run(runtime)

    v = small_world.get_data('v')
    spikes = small_world.get_data('spikes')
    weights = sw_pro.get('weight', 'list')
    if plot:
        Figure(
            # raster plot of the presynaptic neuron spike times
            Panel(spikes.segments[0].spiketrains,
                  yticks=True,
                  markersize=0.2,
                  xlim=(0, runtime),
                  xticks=True),
            # membrane potential of the postsynaptic neuron
            Panel(v.segments[0].filter(name='v')[0],
                  ylabel="Membrane potential (mV)",
                  data_labels=[small_world.label],
                  yticks=True,
                  xlim=(0, runtime),
                  xticks=True),
            title="Simple small world connector",
            annotations="Simulated with {}".format(p.name()))
        plt.show()

    p.end()

    return v, spikes, weights
Esempio n. 10
0
def do_run(plot):

    p.setup(timestep=1.0)

    cell_params_lif = {
        'cm': 0.25,
        'i_offset': 0.0,
        'tau_m': 20.0,
        'tau_refrac': 2.0,
        'tau_syn_E': 5.0,
        'tau_syn_I': 5.0,
        'v_reset': -70.0,
        'v_rest': -65.0,
        'v_thresh': -40.0
    }

    def create_grid(n, label, dx=1.0, dy=1.0):
        grid_structure = p.Grid2D(dx=dx, dy=dy, x0=0.0, y0=0.0)
        return p.Population(n * n,
                            p.IF_curr_exp(**cell_params_lif),
                            structure=grid_structure,
                            label=label)

    # Parameters
    n = 10
    weight_to_spike = 5.0
    delay = 5
    runtime = 200

    # Network population
    grid = create_grid(n, 'grid')

    # SpikeInjector
    injectionConnection = [(0, n * n // 2)]
    spikeArray = {'spike_times': [[5]]}
    inj_pop = p.Population(1,
                           p.SpikeSourceArray(**spikeArray),
                           label='inputSpikes_1')

    projections = list()

    # Projection for injector
    projections.append(
        p.Projection(inj_pop, grid, p.FromListConnector(injectionConnection),
                     p.StaticSynapse(weight=weight_to_spike, delay=delay)))

    # Simple connectors
    dist_dep_exc = "d<2.1"
    dist_dep_inh = "d<1.1"

    exc_connector = p.DistanceDependentProbabilityConnector(
        dist_dep_exc, allow_self_connections=True)
    inh_connector = p.DistanceDependentProbabilityConnector(
        dist_dep_inh, allow_self_connections=True)

    # Projections within grid
    projections.append(
        p.Projection(grid,
                     grid,
                     exc_connector,
                     p.StaticSynapse(weight=5.0, delay=10),
                     receptor_type='excitatory'))
    projections.append(
        p.Projection(grid,
                     grid,
                     inh_connector,
                     p.StaticSynapse(weight=2.0, delay=10),
                     receptor_type='inhibitory'))

    pre_weights = list()
    for projection in projections:
        pre_weights.append(projection.get('weight', 'list'))

    grid.record(['v', 'spikes'])
    inj_pop.record(['spikes'])
    p.run(runtime)

    v = grid.get_data('v')
    spikes = grid.get_data('spikes')
    stim_spikes = inj_pop.get_data('spikes')

    if plot:
        Figure(
            # raster plot of the stimulus spike times
            Panel(stim_spikes.segments[0].spiketrains,
                  yticks=True,
                  markersize=1.5,
                  xlim=(0, runtime),
                  xticks=True),
            # raster plot of the presynaptic neurons' spike times
            Panel(spikes.segments[0].spiketrains,
                  yticks=True,
                  markersize=0.2,
                  xlim=(0, runtime),
                  xticks=True),
            # membrane potential of the postsynaptic neurons
            Panel(v.segments[0].filter(name='v')[0],
                  ylabel="Membrane potential (mV)",
                  data_labels=[grid.label],
                  yticks=True,
                  xlim=(0, runtime),
                  xticks=True),
            title="Simple grid distance-dependent prob connector",
            annotations="Simulated with {}".format(p.name()))
        plt.show()

    post_weights = list()
    for projection in projections:
        post_weights.append(projection.get('weight', 'list'))

    p.end()

    return v, spikes, pre_weights, post_weights