예제 #1
0
def setup(timestep=DEFAULT_TIMESTEP,
          min_delay=DEFAULT_MIN_DELAY,
          **extra_params):
    """
    Should be called at the very beginning of a script.

    `extra_params` contains any keyword arguments that are required by a given
    simulator but not by others.

    NEST-specific extra_params:

    `spike_precision`:
        should be "off_grid" (default) or "on_grid"
    `verbosity`:
        one of: "all", "info", "deprecated", "warning", "error", "fatal"
    `recording_precision`:
        number of decimal places (OR SIGNIFICANT FIGURES?) in recorded data
    `threads`:
        number of threads to use
    `grng_seed`:
        one seed for the global random number generator of NEST
    `rng_seeds`:
        a list of seeds, one for each thread on each MPI process
    `rng_seeds_seed`:
        a single seed that will be used to generate random values for `rng_seeds`
    """
    max_delay = extra_params.get('max_delay', DEFAULT_MAX_DELAY)
    common.setup(timestep, min_delay, **extra_params)
    simulator.state.clear()
    for key in ("threads", "verbosity", "spike_precision",
                "recording_precision"):
        if key in extra_params:
            setattr(simulator.state, key, extra_params[key])
    # set kernel RNG seeds
    simulator.state.num_threads = extra_params.get('threads') or 1
    if 'grng_seed' in extra_params:
        simulator.state.grng_seed = extra_params['grng_seed']
    if 'rng_seeds' in extra_params:
        simulator.state.rng_seeds = extra_params['rng_seeds']
    else:
        rng = NumpyRNG(extra_params.get('rng_seeds_seed', 42))
        n = simulator.state.num_processes * simulator.state.threads
        simulator.state.rng_seeds = rng.next(n, 'uniform_int', {
            'low': 0,
            'high': 100000
        }).tolist()
    # set resolution
    simulator.state.dt = timestep
    # Set min_delay and max_delay
    simulator.state.set_delays(min_delay, max_delay)
    nest.SetDefaults('spike_generator', {'precise_times': True})
    return rank()
예제 #2
0
def setup(timestep=DEFAULT_TIMESTEP, min_delay=DEFAULT_MIN_DELAY,
          **extra_params):
    """
    Should be called at the very beginning of a script.

    `extra_params` contains any keyword arguments that are required by a given
    simulator but not by others.

    NEST-specific extra_params:

    `spike_precision`:
        should be "off_grid" (default) or "on_grid"
    `verbosity`:
        INSERT DESCRIPTION OF POSSIBLE VALUES
    `recording_precision`:
        number of decimal places (OR SIGNIFICANT FIGURES?) in recorded data
    `threads`:
        number of threads to use
    `grng_seed`:
        one seed for the global random number generator of NEST
    `rng_seeds`:
        a list of seeds, one for each thread on each MPI process
    `rng_seeds_seed`:
        a single seed that will be used to generate random values for `rng_seeds`
    """
    max_delay = extra_params.get('max_delay', DEFAULT_MAX_DELAY)
    common.setup(timestep, min_delay, **extra_params)
    simulator.state.clear()
    for key in ("verbosity", "spike_precision", "recording_precision",
                "threads"):
        if key in extra_params:
            setattr(simulator.state, key, extra_params[key])
    # set kernel RNG seeds
    simulator.state.num_threads = extra_params.get('threads') or 1
    if 'grng_seed' in extra_params:
        simulator.state.grng_seed = extra_params['grng_seed']
    if 'rng_seeds' in extra_params:
        simulator.state.rng_seeds = extra_params['rng_seeds']
    else:
        rng = NumpyRNG(extra_params.get('rng_seeds_seed', 42))
        n = simulator.state.num_processes * simulator.state.threads
        simulator.state.rng_seeds = rng.next(n, 'uniform_int', {'low': 0, 'high': 100000}).tolist()
    # set resolution
    simulator.state.dt = timestep
    # Set min_delay and max_delay
    simulator.state.set_delays(min_delay, max_delay)
    nest.SetDefaults('spike_generator', {'precise_times': True})
    return rank()
예제 #3
0
파일: __init__.py 프로젝트: muffgaga/PyNN
def setup(timestep=0.1, min_delay=0.1, max_delay=10.0, **extra_params):
    """
    Should be called at the very beginning of a script.

    `extra_params` contains any keyword arguments that are required by a given
    simulator but not by others.

    NEST-specific extra_params:

    `spike_precision`:
        should be "on_grid" (default) or "off_grid"
    `verbosity`:
        INSERT DESCRIPTION OF POSSIBLE VALUES
    `recording_precision`:
        number of decimal places (OR SIGNIFICANT FIGURES?) in recorded data
    `threads`:
        number of threads to use
    `rng_seeds`:
        a list of seeds, one for each thread on each MPI process
    `rng_seeds_seed`:
        a single seed that will be used to generate random values for `rng_seeds`
    """
    common.setup(timestep, min_delay, max_delay, **extra_params)
    simulator.state.clear()
    for key in ("verbosity", "spike_precision", "recording_precision",
                "threads"):
        if key in extra_params:
            setattr(simulator.state, key, extra_params[key])
    # set kernel RNG seeds
    simulator.state.num_threads = extra_params.get('threads') or 1
    if 'rng_seeds' in extra_params:
        simulator.state.rng_seeds = extra_params['rng_seeds']
    else:
        rng = NumpyRNG(extra_params.get('rng_seeds_seed', 42))
        n = simulator.state.num_processes * simulator.state.threads
        simulator.state.rng_seeds = rng.next(n, 'randint', (100000, )).tolist()
    # set resolution
    simulator.state.dt = timestep
    # Set min_delay and max_delay for all synapse models
    simulator.state.set_delays(min_delay, max_delay)
    nest.SetDefaults('spike_generator', {'precise_times': True})
    return rank()
예제 #4
0
sim.setup(timestep=0.1)

# Create an excitatory population with 80% of the neurons and
# an inhibitory population with 20% of the neurons.
pop_exc = sim.Population(n_exc, sim.IF_curr_exp(), label="Excitatory")
pop_inh = sim.Population(n_inh, sim.IF_curr_exp(), label="Inhibitory")

# Create excitatory poisson stimulation population with 80%
#    of the neurons and
# an inhibitory poisson stimulation population with 20% of the neurons,
#  both with a rate of 1000Hz
# TODO RATE?
if rng is None:
    seed = None
else:
    seed = int(rng.next() * 1000)
stim_exc = sim.Population(n_exc,
                          sim.SpikeSourcePoisson(rate=1000.0, seed=seed),
                          label="Stim_Exc")

if rng is None:
    seed = None
else:
    seed = int(rng.next() * 1000)
stim_inh = sim.Population(n_inh,
                          sim.SpikeSourcePoisson(rate=1000.0,
                                                 seed=int(rng.next() * 1000)),
                          label="Stim_Inh")

# Create a one-to-one excitatory connection
# from the excitatory poisson stimulation population
예제 #5
0
input_rate = 100.0  # Hz
cell_params = {
    "tau_refrac": 2.0,  # ms
    "v_thresh": -50.0,  # mV
    "tau_syn_E": 2.0,  # ms
    "tau_syn_I": 2.0,  # ms
    "tau_m": RandomDistribution("uniform", low=18.0, high=22.0, rng=rng),
}
n_record = 3

node = sim.setup(timestep=0.025, min_delay=1.0, max_delay=1.0, debug=True, quit_on_end=False)
print "Process with rank %d running on %s" % (node, socket.gethostname())

print "[%d] Creating populations" % node
n_spikes = int(2 * tstop * input_rate / 1000.0)
spike_times = numpy.add.accumulate(rng.next(n_spikes, "exponential", {"beta": 1000.0 / input_rate}, mask_local=False))

input_population = sim.Population(10, sim.SpikeSourceArray(spike_times=spike_times), label="input")
output_population = sim.Population(20, sim.IF_curr_exp(**cell_params), label="output")
print "[%d] input_population cells: %s" % (node, input_population.local_cells)
print "[%d] output_population cells: %s" % (node, output_population.local_cells)
print "tau_m =", output_population.get("tau_m")

print "[%d] Connecting populations" % node
connector = sim.FixedProbabilityConnector(0.5, rng=rng)
syn = sim.StaticSynapse(weight=1.0)
projection = sim.Projection(input_population, output_population, connector, syn)

filename = normalized_filename("Results", "simpleRandomNetwork", "conn", simulator_name, sim.num_processes())
projection.save("connections", filename)
예제 #6
0
    'tau_syn_I': 2.0,  # ms
    'tau_m': RandomDistribution('uniform', [18.0, 22.0], rng=rng)
}
n_record = 3

node = sim.setup(timestep=0.025,
                 min_delay=1.0,
                 max_delay=1.0,
                 debug=True,
                 quit_on_end=False)
print "Process with rank %d running on %s" % (node, socket.gethostname())

print "[%d] Creating populations" % node
n_spikes = int(2 * tstop * input_rate / 1000.0)
spike_times = numpy.add.accumulate(
    rng.next(n_spikes, 'exponential', [1000.0 / input_rate], mask_local=False))

input_population = sim.Population(
    10, sim.SpikeSourceArray(spike_times=spike_times), label="input")
output_population = sim.Population(20,
                                   sim.IF_curr_exp(**cell_params),
                                   label="output")
print "[%d] input_population cells: %s" % (node, input_population.local_cells)
print "[%d] output_population cells: %s" % (node,
                                            output_population.local_cells)
print "tau_m =", output_population.get('tau_m')

print "[%d] Connecting populations" % node
connector = sim.FixedProbabilityConnector(0.5, rng=rng)
syn = sim.StaticSynapse(weight=1.0)
projection = sim.Projection(input_population, output_population, connector,
예제 #7
0
    'tau_syn_I': 2.0,  # ms
    'tau_m': RandomDistribution('uniform', low=18.0, high=22.0, rng=rng)
}
n_record = 3

node = sim.setup(timestep=0.025,
                 min_delay=1.0,
                 max_delay=1.0,
                 debug=True,
                 quit_on_end=False)
print("Process with rank %d running on %s" % (node, socket.gethostname()))

print("[%d] Creating populations" % node)
n_spikes = int(2 * tstop * input_rate / 1000.0)
spike_times = numpy.add.accumulate(
    rng.next(n_spikes, 'exponential', {'beta': 1000.0 / input_rate}))

input_population = sim.Population(
    10, sim.SpikeSourceArray(spike_times=spike_times), label="input")
output_population = sim.Population(20,
                                   sim.IF_curr_exp(**cell_params),
                                   label="output")
print("[%d] input_population cells: %s" % (node, input_population.local_cells))
print("[%d] output_population cells: %s" %
      (node, output_population.local_cells))
print("tau_m =", output_population.get('tau_m'))

print("[%d] Connecting populations" % node)
connector = sim.FixedProbabilityConnector(0.5, rng=rng)
syn = sim.StaticSynapse(weight=1.0)
projection = sim.Projection(input_population, output_population, connector,
예제 #8
0
tstop = 1000.0  # ms
input_rate = 100.0  # Hz
cell_params = {'tau_refrac': 2.0,  # ms
               'v_thresh':  -50.0, # mV
               'tau_syn_E':  2.0,  # ms
               'tau_syn_I':  2.0,  # ms
               'tau_m': RandomDistribution('uniform', low=18.0, high=22.0, rng=rng)
}
n_record = 3

node = sim.setup(timestep=0.025, min_delay=1.0, max_delay=1.0, debug=True, quit_on_end=False)
print("Process with rank %d running on %s" % (node, socket.gethostname()))

print("[%d] Creating populations" % node)
n_spikes = int(2 * tstop * input_rate / 1000.0)
spike_times = np.add.accumulate(rng.next(n_spikes, 'exponential',
                                            {'beta': 1000.0 / input_rate}))

input_population = sim.Population(10, sim.SpikeSourceArray(spike_times=spike_times), label="input")
output_population = sim.Population(20, sim.IF_curr_exp(**cell_params), label="output")
print("[%d] input_population cells: %s" % (node, input_population.local_cells))
print("[%d] output_population cells: %s" % (node, output_population.local_cells))
print("tau_m =", output_population.get('tau_m'))

print("[%d] Connecting populations" % node)
connector = sim.FixedProbabilityConnector(0.5, rng=rng)
syn = sim.StaticSynapse(weight=1.0)
projection = sim.Projection(input_population, output_population, connector, syn)

filename = normalized_filename("Results", "simpleRandomNetwork", "conn",
                               simulator_name, sim.num_processes())
projection.save('connections', filename)
예제 #9
0
n_record = 5

node = setup(timestep=0.025,
             min_delay=1.0,
             max_delay=10.0,
             debug=True,
             quit_on_end=False)
print("Process with rank %d running on %s" % (node, socket.gethostname()))

rng = NumpyRNG(seed=seed, parallel_safe=True)

print("[%d] Creating populations" % node)
n_spikes = int(2 * tstop * input_rate / 1000.0)
spike_times = numpy.add.accumulate(
    rng.next(n_spikes,
             'exponential', {'beta': 1000.0 / input_rate},
             mask_local=False))

input_population = Population(100,
                              SpikeSourceArray(spike_times=spike_times),
                              label="input")
output_population = Population(10, IF_curr_exp(**cell_params), label="output")
print("[%d] input_population cells: %s" % (node, input_population.local_cells))
print("[%d] output_population cells: %s" %
      (node, output_population.local_cells))

print("[%d] Connecting populations" % node)
timer.start()
connector = CSAConnector(csa.random(0.5))
syn = StaticSynapse(weight=0.1)
projection = Projection(input_population, output_population, connector, syn)
cell_params = {'tau_refrac':2.0,'v_thresh':-50.0,'tau_syn_E':2.0, 'tau_syn_I':2.0}

cellsA = Population((cellNumA,), cellType, cell_params, label="Cells_A")
cellsB = Population((cellNumB,), cellType, cell_params, label="Cells_B")


xMin=0
xMax=200
yMin=0
yMax=200
zMin=0
zMax=50


for cell in cellsA:
    cell.position[0] = xMin+(NumpyRNG.next(rng)*(xMax-xMin))
    cell.position[1] = yMin+(NumpyRNG.next(rng)*(yMax-yMin))
    cell.position[2] = zMin+(NumpyRNG.next(rng)*(zMax-zMin))

for cell in cellsB:
    cell.position[0] = xMin+(NumpyRNG.next(rng)*(xMax-xMin))
    cell.position[1] = yMin+(NumpyRNG.next(rng)*(yMax-yMin))
    cell.position[2] = zMin+(NumpyRNG.next(rng)*(zMax-zMin))



indicesA = []
indicesB = []

for idA in cellsA:
    index  = cellsA.id_to_index(idA)
예제 #11
0
    'tau_syn_E': 2.0,
    'tau_syn_I': 2.0
}

cellsA = Population((cellNumA, ), cellType, cell_params, label="Cells_A")
cellsB = Population((cellNumB, ), cellType, cell_params, label="Cells_B")

xMin = 0
xMax = 200
yMin = 0
yMax = 200
zMin = 0
zMax = 50

for cell in cellsA:
    cell.position[0] = xMin + (NumpyRNG.next(rng) * (xMax - xMin))
    cell.position[1] = yMin + (NumpyRNG.next(rng) * (yMax - yMin))
    cell.position[2] = zMin + (NumpyRNG.next(rng) * (zMax - zMin))

for cell in cellsB:
    cell.position[0] = xMin + (NumpyRNG.next(rng) * (xMax - xMin))
    cell.position[1] = yMin + (NumpyRNG.next(rng) * (yMax - yMin))
    cell.position[2] = zMin + (NumpyRNG.next(rng) * (zMax - zMin))

indicesA = []
indicesB = []

for idA in cellsA:
    index = cellsA.id_to_index(idA)
    print " - Cell id %s in cellsA (index = %d) is at %s" % (idA, index,
                                                             idA.position)
예제 #12
0
import numpy
from pyNN.utility import get_script_args
simulator_name = get_script_args(1)[0]
exec("from pyNN.%s import *" % simulator_name)
from pyNN.random import NumpyRNG

setup(timestep=0.01, min_delay=2.0, max_delay=4.0)

ifcell = create(IF_curr_exp,{'i_offset' :   0.1, 'tau_refrac' : 3.0,
                             'v_thresh' : -51.0, 'tau_syn_E'  : 2.0,
                             'tau_syn_I':  5.0,  'v_reset'    : -70.0})
input_rate = 200.0
simtime = 1000.0
seed = 240965239

rng = NumpyRNG(seed=seed)
n_spikes = input_rate*simtime/1000.0
spike_times = numpy.add.accumulate(rng.next(n_spikes, 'exponential', [1000.0/input_rate]))

spike_source = create(SpikeSourceArray(spike_times=spike_times))


conn = connect(spike_source, ifcell, weight=1.5, receptor_type='excitatory', delay=2.0)

record(('spikes', 'v'), ifcell, "Results/IF_curr_exp2_%s.pkl" % simulator_name)
initialize(ifcell, v=-53.2)

run(simtime)

end()
예제 #13
0
#import numpy
from pyNN.random import RandomDistribution, NumpyRNG, GSLRNG, NativeRNG
rng = NumpyRNG(seed=824756)
print(rng.next(5, 'normal', {'mu': 1.0, 'sigma': 0.2}))
'''
rng = GSLRNG(seed=824756, type='ranlxd2')  # RANLUX algorithm of Luescher
rng.next(5, 'normal', {'mu': 1.0, 'sigma': 0.2})
#fail to import 
#error: Cannot import pygsl
#need pygsl package, cannot be installed with pip
'''

gamma = RandomDistribution('gamma', (2.0, 0.3), rng=NumpyRNG(seed=72386))
print(gamma.next(5))
#by name
gamma = RandomDistribution('gamma', k=2.0, theta=0.3, rng=NumpyRNG(seed=72386))
#differece
print(gamma.next())
print(gamma.next(1))

norm = NativeRNG(seed=72386)
print(norm.next(5))
예제 #14
0
input_rate = 100.0  # Hz
cell_params = {'tau_refrac': 2.0,  # ms
               'v_thresh':  -50.0, # mV
               'tau_syn_E':  2.0,  # ms
               'tau_syn_I':  2.0}  # ms
n_record = 5

node = setup(timestep=0.025, min_delay=1.0, max_delay=10.0, debug=True, quit_on_end=False)
print("Process with rank %d running on %s" % (node, socket.gethostname()))


rng = NumpyRNG(seed=seed, parallel_safe=True)

print("[%d] Creating populations" % node)
n_spikes = int(2 * tstop * input_rate / 1000.0)
spike_times = numpy.add.accumulate(rng.next(n_spikes, 'exponential',
                                            {'beta': 1000.0 / input_rate}, mask_local=False))

input_population = Population(100, SpikeSourceArray(spike_times=spike_times), label="input")
output_population = Population(10, IF_curr_exp(**cell_params), label="output")
print("[%d] input_population cells: %s" % (node, input_population.local_cells))
print("[%d] output_population cells: %s" % (node, output_population.local_cells))

print("[%d] Connecting populations" % node)
timer.start()
connector = CSAConnector(csa.random(0.5))
syn = StaticSynapse(weight=0.1)
projection = Projection(input_population, output_population, connector, syn)
print(connector.describe(), timer.elapsedTime())

file_stem = "Results/simpleRandomNetwork_csa_np%d_%s" % (num_processes(), simulator_name)
예제 #15
0
        'i_offset': 0.1,
        'tau_refrac': 3.0,
        'v_thresh': -51.0,
        'tau_syn_E': 2.0,
        'tau_syn_I': 5.0,
        'v_reset': -70.0,
        'v_init': -53.2
    })
input_rate = 200.0
simtime = 1000.0
seed = 240965239

rng = NumpyRNG(seed=seed)
n_spikes = input_rate * simtime / 1000.0
spike_times = numpy.add.accumulate(
    rng.next(n_spikes, 'exponential', [1000.0 / input_rate]))

spike_source = create(SpikeSourceArray, {'spike_times': spike_times})

conn = connect(spike_source,
               ifcell,
               weight=1.5,
               synapse_type='excitatory',
               delay=2.0)

record(ifcell, "Results/IF_curr_exp2_%s.ras" % simulator_name)
record_v(ifcell, "Results/IF_curr_exp2_%s.v" % simulator_name)
run(simtime)

end()
예제 #16
0
tstop = 1000.0 # ms
input_rate = 100.0 # Hz
cell_params = {'tau_refrac': 2.0,  # ms
               'v_thresh':  -50.0, # mV
               'tau_syn_E':  2.0,  # ms
               'tau_syn_I':  2.0,  # ms
               'tau_m': RandomDistribution('uniform', low=18.0, high=22.0, rng=rng)
}
n_record = 3

node = sim.setup(timestep=0.025, min_delay=1.0, max_delay=1.0, debug=True, quit_on_end=False)
print("Process with rank %d running on %s" % (node, socket.gethostname()))

print("[%d] Creating populations" % node)
n_spikes = int(2*tstop*input_rate/1000.0)
spike_times = numpy.add.accumulate(rng.next(n_spikes, 'exponential',
                                            {'beta': 1000.0/input_rate}, mask_local=False))

input_population  = sim.Population(10, sim.SpikeSourceArray(spike_times=spike_times), label="input")
output_population = sim.Population(20, sim.IF_curr_exp(**cell_params), label="output")
print("[%d] input_population cells: %s" % (node, input_population.local_cells))
print("[%d] output_population cells: %s" % (node, output_population.local_cells))
print("tau_m =", output_population.get('tau_m'))

print("[%d] Connecting populations" % node)
connector = sim.FixedProbabilityConnector(0.5, rng=rng)
syn = sim.StaticSynapse(weight=1.0)
projection = sim.Projection(input_population, output_population, connector, syn)

filename = normalized_filename("Results", "simpleRandomNetwork", "conn",
                               simulator_name, sim.num_processes())
projection.save('connections', filename)
예제 #17
0
import numpy
from pyNN.utility import get_script_args
simulator_name = get_script_args(1)[0]
exec("from pyNN.%s import *" % simulator_name)
from pyNN.random import NumpyRNG

setup(timestep=0.01, min_delay=2.0, max_delay=4.0)

ifcell = create(IF_curr_exp,{'i_offset' :   0.1, 'tau_refrac' : 3.0,
                             'v_thresh' : -51.0, 'tau_syn_E'  : 2.0,
                             'tau_syn_I':  5.0,  'v_reset'    : -70.0})
input_rate = 200.0
simtime = 1000.0
seed = 240965239

rng = NumpyRNG(seed=seed)
n_spikes = input_rate*simtime/1000.0
spike_times = numpy.add.accumulate(rng.next(n_spikes, 'exponential', [1000.0/input_rate]))

spike_source = create(SpikeSourceArray(spike_times=spike_times))


conn = connect(spike_source, ifcell, weight=1.5, receptor_type='excitatory', delay=2.0)

record(('spikes', 'v'), ifcell, "Results/IF_curr_exp2_%s.pkl" % simulator_name)
initialize(ifcell, v=-53.2)

run(simtime)

end()