当前位置: 首页>>代码示例>>Python>>正文


Python nest.run函数代码示例

本文整理汇总了Python中pyNN.nest.run函数的典型用法代码示例。如果您正苦于以下问题:Python run函数的具体用法?Python run怎么用?Python run使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了run函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

def main():
    # setup timestep of simulation and minimum and maximum synaptic delays
    setup(timestep=simulationTimestep, min_delay=minSynapseDelay, max_delay=maxSynapseDelay)
    
    # create a spike sources
    retinaLeft = createSpikeSource("Retina Left")
    retinaRight = createSpikeSource("Retina Right")
    
    # create network and attach the spike sources 
    network = createCooperativeNetwork(retinaLeft=retinaLeft, retinaRight=retinaRight)
    
    # run simulation for time in milliseconds
    print "Simulation started..."
    run(simulationTime)
    print "Simulation ended."
    # plot results 
    from itertools import repeat
    numberOfLayersToPlot = 4
    layers = zip(repeat(network, numberOfLayersToPlot), range(1, numberOfLayersToPlot+1), repeat(False, numberOfLayersToPlot))
    customLayers = [(network, 20, False),(network, 40, False),(network, 60, False),(network, 80, False)]
    for proc in range(0, numberOfLayersToPlot):
        p = Process(target=plotSimulationResults, args=customLayers[proc])
        p.start()
    
    # finalise program and simulation
    end()
开发者ID:AMFtech,项目名称:StereoMatching,代码行数:26,代码来源:CooperativeNetwork.py

示例2: two_neuron_example

def two_neuron_example(
    current=1000.0,
    time_simulation=2000.0,
    weight=0.4,
    neuron_parameters={"v_rest": -50.0, "cm": 1, "tau_m": 20.0, "tau_refrac": 5.0, "v_thresh": -40.0, "v_reset": -50.0},
):

    sim.setup(timestep=0.1, min_delay=0.1)

    pulse = sim.DCSource(amplitude=current, start=0.0, stop=time_simulation)

    pre = sim.Population(1, sim.IF_curr_exp(**neuron_parameters))

    pre.record("spikes")

    pulse.inject_into(pre)

    sim.run(time_simulation)

    # rates in Hz
    rate_pre = len(pre.get_data("spikes").segments[0].spiketrains[0]) / time_simulation * 1000.0

    sim.end()

    return rate_pre
开发者ID:knly,项目名称:bic-ws1516,代码行数:25,代码来源:exercise2.py

示例3: run

    def run(self, spiketimes):
        assert spiketimes.shape[0] == self.n_spike_source, 'spiketimes length should be equal to input neurons'
        start = time.clock()
        sim.reset()
        end = time.clock()
        print "reset uses %f s." % (end - start)
        for i in range(self.n_spike_source):
            spiketime = np.array(spiketimes[i], dtype=float)
            if spiketimes[i].any():
                self.spike_source[i].spike_times = spiketime

        sim.initialize(self.hidden_neurons, V_m=0)
        sim.initialize(self.output_neurons, V_m=0.)
        sim.run(self.sim_time)

        spiketrains = self.output_neurons.get_data(clear=True).segments[0].spiketrains

        # vtrace = self.hidden_neurons.get_data(clear=True).segments[0].filter(name='V_m')[0]
        # plt.figure()
        # plt.plot(vtrace.times, vtrace)
        # plt.show()

        hidden_spiketrains = self.hidden_neurons.get_data(clear=True).segments[0].spiketrains
        spike_cnts = 0
        for spiketrain in hidden_spiketrains:
            spike_cnts += len(list(np.array(spiketrain)))
        self.hidden_spike_cnts.append(spike_cnts)
        print 'hidden spikes: ', spike_cnts

        spiketimes_out = []
        for spiketrain in spiketrains:
            spiketimes_out.append(list(np.array(spiketrain)))


        return np.array(spiketimes_out)
开发者ID:starlitnext,项目名称:SpikingRNN,代码行数:35,代码来源:rsnn_sim_int.py

示例4: sim_neuron

def sim_neuron(rate):
	neuron_parameters={
            'v_rest'     : -50.0,
            'cm'         : 1,
            'tau_m'      : 20.0,
            'tau_syn_E'  : 5.0,
            'tau_syn_I'  : 5.0,
            'v_reset'    : -50.0,
            'v_thresh'   : 10000000000000000000000000000000000000000000000000000000000000000000000.0,
            'e_rev_E'	 : 0.0,
            'e_rev_I'	 : -100,
	}
	time_simulation = 100000 # don't choose to small number in order to get good statistics
	weight = 0.1 # is this value allreight
	sim.setup(timestep=0.1, min_delay=0.1)
	
	pois_exc = sim.SpikeSourcePoisson(duration=time_simulation,start=0.0,rate=rate) # generate poisson rate stimulus
	pois_inh = sim.SpikeSourcePoisson(duration=time_simulation,start=0.0,rate=rate) # generate poisson rate stimulus
	exc = sim.Population(1, cellclass=pois_exc) # simulate excitatory cell
	inh = sim.Population(1, cellclass=pois_inh) # simulate inhibitory cell
	
	rec = sim.Population(1, sim.IF_cond_exp(**neuron_parameters)) # simulate receiving neuron

	sim.Projection(exc, rec, connector=sim.OneToOneConnector(),synapse_type=sim.StaticSynapse(weight=weight),receptor_type='excitatory') # connect excitatory neuron to receiver
	sim.Projection(inh, rec, connector=sim.OneToOneConnector(),synapse_type=sim.StaticSynapse(weight=weight),receptor_type='inhibitory') # connect inhibitory neuron to receiver

	rec.record('v') # record membrane potential
	rec.record('gsyn_exc') # record excitatory conductance
	rec.record('gsyn_inh') # record inhibitory conductance
	sim.run(time_simulation) # start simulation

	return rec.get_data('v').segments[0].analogsignalarrays[0], rec.get_data('gsyn_exc').segments[0].analogsignalarrays[0], rec.get_data('gsyn_inh').segments[0].analogsignalarrays[0] # return membrane potential, excitatory conductance, inhibitory conductance
开发者ID:knly,项目名称:bic-ws1516,代码行数:32,代码来源:exercise1.py

示例5: main

def main(args):

    setup(timestep=0.1)

    random_image = np.random.rand(2,2)
    size = random_image.size


    input_population_arr = Population(random_image.size, SpikeSourceArray, {'spike_times': [0 for i in range(0, random_image.size)]})

    cell_params = {'tau_refrac': 2.0, 'v_thresh': -50.0, 'tau_syn_E': 2.0, 'tau_syn_I': 2.0}
    output_population = Population(1, IF_curr_alpha, cell_params, label="output")

    projection = Projection(input_population_arr, output_population, AllToAllConnector())
    projection.setWeights(1.0)

    input_population_arr.record('spikes')
    output_population.record('spikes')

    tstop = 1000.0

    run(tstop)

    output_population.write_data("simpleNetwork_output.pkl",'spikes')
    input_population_arr.write_data("simpleNetwork_input.pkl",'spikes')
    #output_population.print_v("simpleNetwork.v")
    end()
开发者ID:danielgeier,项目名称:ml2-spiking,代码行数:27,代码来源:population_example.py

示例6: run_test

def run_test(w_list, cell_para, spike_source_data):
    pop_list = []
    p.setup(timestep=1.0, min_delay=1.0, max_delay=3.0)
    #input poisson layer
    input_size = w_list[0].shape[0]
    pop_in = p.Population(input_size, p.SpikeSourceArray, {'spike_times' : []})
    for j in range(input_size):
        pop_in[j].spike_times = spike_source_data[j]
    pop_list.append(pop_in)
    
    for w in w_list:        
        pos_w = np.copy(w)
        pos_w[pos_w < 0] = 0
        neg_w = np.copy(w)
        neg_w[neg_w > 0] = 0
        
        output_size = w.shape[1]
        pop_out = p.Population(output_size, p.IF_curr_exp, cell_para)
        p.Projection(pop_in, pop_out, p.AllToAllConnector(weights = pos_w), target='excitatory')
        p.Projection(pop_in, pop_out, p.AllToAllConnector(weights = neg_w), target='inhibitory')
        pop_list.append(pop_out)
        pop_in = pop_out

    pop_out.record()
    run_time = np.ceil(np.max(spike_source_data)[0]/1000.)*1000
    p.run(run_time)
    spikes = pop_out.getSpikes(compatible_output=True)
    return spikes
开发者ID:qian-liu,项目名称:iconip2016,代码行数:28,代码来源:spiking_relu.py

示例7: compute

    def compute(self, proximal, distal=None):
        if distal is not None:
            for i, times in enumerate(distal):
                self.distal_input[i].spike_times = times

        active = []
        predictive = []

        if not (isinstance(proximal[0], list) or isinstance(proximal[0], np.ndarray)):
            proximal = [proximal]

        timestep = self.parameters.config.timestep

        for p in proximal:
            t = pynn.get_current_time()
            for c in p:
                self.proximal_input[int(c)].spike_times = np.array([t + 0.01])
            pynn.run(self.parameters.config.timestep)

            spikes_soma = self.soma.getSpikes()
            mask = (spikes_soma[:,1] >= t) & (spikes_soma[:,1] < t + timestep)
            active.append(np.unique(spikes_soma[mask,0]))

            spikes_distal = self.distal.getSpikes()
            mask = (spikes_distal[:,1] >= t) & (spikes_distal[:,1] < t + timestep)
            predictive.append(np.unique(spikes_distal[mask,0].astype(np.int16)/2))

        return (active, predictive)
开发者ID:subutai,项目名称:htm-hardware,代码行数:28,代码来源:temporal_memory.py

示例8: test_ticket244

def test_ticket244():
    nest = pyNN.nest
    nest.setup(threads=4)
    p1 = nest.Population(4, nest.IF_curr_exp())
    p1.record('spikes')
    poisson_generator = nest.Population(3, nest.SpikeSourcePoisson(rate=1000.0))
    conn = nest.OneToOneConnector()
    syn = nest.StaticSynapse(weight=1.0)
    nest.Projection(poisson_generator, p1.sample(3), conn, syn, receptor_type="excitatory")
    nest.run(15)
    p1.get_data()
开发者ID:mfraezz,项目名称:PyNN,代码行数:11,代码来源:test_nest.py

示例9: two_neuron_example

def two_neuron_example(
        current=1000.0,
        time_simulation=2000.,
        weight=0.4,
        neuron_parameters={
            'v_rest'     : -65.0,
            'cm'         : 0.1,
            'tau_m'      : 1.0,
            'tau_refrac' : 2.0,
            'tau_syn_E'  : 10.0,
            'tau_syn_I'  : 10.0,
            'i_offset'   : 0.0,
            'v_reset'    : -65.0,
            'v_thresh'   : -50.0,
        },
    ):
    """
        Connects to neurons with corresponding parameters.

        The first is stimulated via current injection while the second receives
        the other one's spikes.
    """

    sim.setup(timestep=0.1, min_delay=0.1)

    pulse = sim.DCSource(amplitude=current, start=0.0, stop=time_simulation)

    pre = sim.Population(1, sim.IF_curr_exp(**neuron_parameters))
    post = sim.Population(1, sim.IF_curr_exp(**neuron_parameters))

    pre.record('spikes')
    post.record('spikes')

    sim.Projection(pre, post, connector=sim.OneToOneConnector(),
            synapse_type=sim.StaticSynapse(weight=weight),
            receptor_type='excitatory')

    pulse.inject_into(pre)

    sim.run(time_simulation)

    # rates in Hz
    rate_pre = len(pre.get_data('spikes').segments[0].spiketrains[0])\
            / time_simulation * 1000.

    rate_post = len(post.get_data('spikes').segments[0].spiketrains[0])\
            / time_simulation * 1000.

    sim.end()

    return rate_pre, rate_post
开发者ID:knly,项目名称:bic-ws1516,代码行数:51,代码来源:bic_sh01_ex03_code.py

示例10: loop

def loop():
    for device_instance in Interfaces.DeviceMeta._instances:
        device_instance._create_device()
    print "Entered loop"
    i = 0
    
    while(True):
        sim.run(20.0)
        Observers.Observer.notify()
        Setters.Setter.notify()
        SimulatorPorts.RPCPort.execute()
        for pop_view in population_register.values():
            pass
            #print pop_view.meanSpikeCount()
            #print 'amplitude', pop_view.get_data().segments[0].filter(name='v')
            #print nest.GetStatus(map(int, [pop_view.all_cells[0]]), 'V_m')

        i += 1
    sim.end()
开发者ID:uahic,项目名称:music_wizard,代码行数:19,代码来源:simulator_node.py

示例11: test_record_native_model

def test_record_native_model():
    if not have_nest:
        raise SkipTest
    nest = pyNN.nest
    from pyNN.random import RandomDistribution

    init_logging(logfile=None, debug=True)

    nest.setup()

    parameters = {'tau_m': 17.0}
    n_cells = 10
    p1 = nest.Population(n_cells, nest.native_cell_type("ht_neuron")(**parameters))
    p1.initialize(V_m=-70.0, Theta=-50.0)
    p1.set(theta_eq=-51.5)
    #assert_arrays_equal(p1.get('theta_eq'), -51.5*numpy.ones((10,)))
    assert_equal(p1.get('theta_eq'), -51.5)
    print(p1.get('tau_m'))
    p1.set(tau_m=RandomDistribution('uniform', low=15.0, high=20.0))
    print(p1.get('tau_m'))

    current_source = nest.StepCurrentSource(times=[50.0, 110.0, 150.0, 210.0],
                                            amplitudes=[0.01, 0.02, -0.02, 0.01])
    p1.inject(current_source)

    p2 = nest.Population(1, nest.native_cell_type("poisson_generator")(rate=200.0))

    print("Setting up recording")
    p2.record('spikes')
    p1.record('V_m')

    connector = nest.AllToAllConnector()
    syn = nest.StaticSynapse(weight=0.001)

    prj_ampa = nest.Projection(p2, p1, connector, syn, receptor_type='AMPA')

    tstop = 250.0
    nest.run(tstop)

    vm = p1.get_data().segments[0].analogsignals[0]
    n_points = int(tstop / nest.get_time_step()) + 1
    assert_equal(vm.shape, (n_points, n_cells))
    assert vm.max() > 0.0  # should have some spikes
开发者ID:antolikjan,项目名称:PyNN,代码行数:43,代码来源:test_nest.py

示例12: scnn_test

def scnn_test(l_cnn, w_cnn, num_test, test, max_rate, dur_test, silence):
    p.setup(timestep=1.0, min_delay=1.0, max_delay=3.0)
    L = l_cnn
    random.seed(0)
    input_size = L[0][1]
    pops_list = []
    pops_list.append(init_inputlayer(input_size, test[:num_test, :], max_rate, dur_test, silence))
    for l in range(len(w_cnn)):
        pops_list.append(construct_layer(pops_list[l], L[l+1][0], L[l+1][1], w_cnn[l]))
    result = pops_list[-1][0]
    result.record()
    
    p.run((dur_test+silence)*num_test)
    spike_result = result.getSpikes(compatible_output=True)
    p.end()
    
    spike_result_count = count_spikes(spike_result, 10, num_test, dur_test, silence)
    predict = np.argmax(spike_result_count, axis=0)
#     prob = np.exp(spike_result_count)/np.sum(np.exp(spike_result_count), axis=0)
    return predict
开发者ID:qian-liu,项目名称:iconip2016,代码行数:20,代码来源:scnn_sim.py

示例13: test_record_native_model

def test_record_native_model():
    nest = pyNN.nest
    from pyNN.random import RandomDistribution
    from pyNN.utility import init_logging

    init_logging(logfile=None, debug=True)
    
    nest.setup()
    
    parameters = {'Tau_m': 17.0}
    n_cells = 10
    p1 = nest.Population(n_cells, nest.native_cell_type("ht_neuron"), parameters)
    p1.initialize('V_m', -70.0)
    p1.initialize('Theta', -50.0)
    p1.set('Theta_eq', -51.5)
    assert_equal(p1.get('Theta_eq'), [-51.5]*10)
    print p1.get('Tau_m')
    p1.rset('Tau_m', RandomDistribution('uniform', [15.0, 20.0]))
    print p1.get('Tau_m')
    
    current_source = nest.StepCurrentSource({'times' : [50.0, 110.0, 150.0, 210.0],
                                            'amplitudes' : [0.01, 0.02, -0.02, 0.01]})
    p1.inject(current_source)
    
    p2 = nest.Population(1, nest.native_cell_type("poisson_generator"), {'rate': 200.0})
    
    print "Setting up recording"
    p2.record()
    p1._record('V_m')
    
    connector = nest.AllToAllConnector(weights=0.001)
    
    prj_ampa = nest.Projection(p2, p1, connector, target='AMPA')
    
    tstop = 250.0
    nest.run(tstop)
    
    n_points = int(tstop/nest.get_time_step()) + 1
    assert_equal(p1.recorders['V_m'].get().shape, (n_points*n_cells, 3))
    id, t, v = p1.recorders['V_m'].get().T
    assert v.max() > 0.0 # should have some spikes
开发者ID:agravier,项目名称:pynn,代码行数:41,代码来源:test_nest.py

示例14: compute

    def compute(self, data, learn=True):
        """Perform the actual computation"""

        timestep = self.parameters.config.timestep

        # run simulation
        for i, d in enumerate(data):
            t = pynn.get_current_time()
            d = d.astype(np.int32)
            activity = np.array(self.calculate_activity([d]))
            train = np.ndarray((np.sum(activity), 2))
            pos = 0
            for j in range(len(self.stimulus)):
                spikes = np.sort(np.random.normal(1.0 + t, 0.01, activity[0][j]))
                train[pos:pos+activity[0][j],:] = np.vstack([np.ones(spikes.size)*j, spikes]).T
                pos += activity[0][j]
            for j, s in enumerate(self.stimulus):
                s.spike_times = train[train[:,0] == j,1]

            pynn.run(timestep)

            # extract spikes and calculate activity
            spikes = self.columns.getSpikes()
            mask = (spikes[:,1] > t) & (spikes[:,1] < t + timestep)
            active_columns = np.unique(spikes[mask,0]).astype(np.int32)
            yield active_columns

            if learn > 0:
                # wake up, school's starting in five minutes!
                c = np.zeros(self.permanences.shape[0], dtype=np.bool)
                c[active_columns] = 1
                d = d.astype(np.bool)
                self.permanences[np.outer(c, d)] += 0.01
                self.permanences[np.outer(c, np.invert(d))] -= 0.01
                self.permanences = np.minimum(np.maximum(self.permanences, 0), 1)

                if type(learn) == int:
                    learn -= 1
开发者ID:subutai,项目名称:htm-hardware,代码行数:38,代码来源:spatial_pooler.py

示例15: test_column_input

def test_column_input():
    """
    Tests whether all neurons receive the same feedforward input from
    common proximal dendrite.
    """
    
    LOG.info('Testing column input...')
    
    # reset the simulator
    sim.reset()
    
    column = Column.Column()
    sim.run(1000)
    spikes = column.FetchSpikes()
    print('Spikes before: {}'.format(spikes))
    
    # now stream some input into the column
    column.SetFeedforwardDendrite(1000.0)
    sim.run(1000)
    spikes = column.FetchSpikes().segments[0]
    print('Spikes after: {}'.format(spikes))
    
    LOG.info('Test complete.')
开发者ID:codeteam17,项目名称:spiked,代码行数:23,代码来源:test_column.py


注:本文中的pyNN.nest.run函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。