示例#1
0
def createNetwork():
    
    # the dimesion is X x Y x maxDisparity+1 because disparity 0 means no shift in pixel location
    # however the network should still exist and contain only one disparity map. 
    assert dimensionRetinaX > maxDisparity >= 0, "Maximum Disparity Constant is illegal!"
    print "Creating Cooperative Network..."
    
    print "\t Creating Populations..."
    from SimulationAndNetworkSettings import t_synE, t_synI, t_memb, vResetInh, vResetCO
    from pyNN.nest import record
    
    network = []
    for x in range(0, dimensionRetinaX):
        for disp in range(0, maxDisparity+1):
            inhLeftPop = Population(dimensionRetinaY, IF_curr_exp, {'tau_syn_E':t_synE, 'tau_syn_I':t_synI, 'tau_m':t_memb, 'v_reset':vResetInh},
                label="Blocker Left {0}".format(x*dimensionRetinaX + disp))
            inhRightPop = Population(dimensionRetinaY, IF_curr_exp, {'tau_syn_E':t_synE, 'tau_syn_I':t_synI, 'tau_m':t_memb, 'v_reset':vResetInh},
                label="Blocker Right {0}".format(x*dimensionRetinaX + disp))
            cellOutputPop = Population(dimensionRetinaY, IF_curr_exp, {'tau_syn_E':t_synE, 'tau_syn_I':t_synI, 'tau_m':t_memb, 'v_reset':vResetCO},
                label="Cell Output {0}".format(x*dimensionRetinaX + disp))
            
            # reocrd data for plotting purposes
            cellOutputPop.record('v')
            
            network.append((inhLeftPop, inhRightPop, cellOutputPop))
    
    interconnectNetworkNeurons(network)
    
    return network
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()
image = cv2.imread('/fzi/ids/mlprak2/Bilder/impuls.tif')

image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
frame = np.zeros(image.size) + 255

rates_init = np.zeros(frame.size)

pop_in = Population(frame.shape, SpikeSourcePoisson, {'rate': rates_init})
pop_out = Population(1, IF_curr_alpha, {'tau_refrac': 5 })

projection = Projection(pop_in, pop_out, AllToAllConnector())
projection.setWeights(1.0)

pop_in.set(rate=image.astype(float).flatten())

pop_in.record('spikes')
pop_out.record('spikes')


tstop = 100.0
run(tstop)

spikes_in = pop_in.get_data()
data_out = pop_out.get_data()

for seg in data_out.segments:
    print seg    
    for st in seg.spiketrains:
        print st
        
for seg in spikes_in.segments: