def create_brain(): # neuron parameters that provide smooth and symmetric # wheel movement WHEEL_NEURON_PARAMS = { 'v_rest': -60.5, 'cm': 0.025, 'tau_m': 10., 'tau_refrac': 10.0, 'tau_syn_E': 2.5, 'tau_syn_I': 2.5, 'e_rev_E': 0.0, 'e_rev_I': -75.0, 'v_thresh': -60.0, 'v_reset': -60.5 } # stimulus-to-wheels synaptic parameters WEIGHT_STIMULUS_TO_WHEELS = 1.5e-4 DELAY = 0.1 # PushBot wheel velocity is controlled by neuron membrane potentials # both left-side wheels are controlled by the same neuron left_wheels_neuron = sim.Population(1, sim.IF_cond_exp(**WHEEL_NEURON_PARAMS), label="left_wheels_neuron") # both right-side wheels are controlled by the same neuron right_wheels_neuron = sim.Population( 1, sim.IF_cond_exp(**WHEEL_NEURON_PARAMS), label="right_wheels_neuron") # setup a source of spikes that will make the PushBot turn stimulus = sim.Population( 1, sim.SpikeSourceArray(spike_times=[i * 100 for i in range(100)]), label="stimulus") # setup a synaptic connection from the stimulus to the neurons stim_to_wheels = sim.StaticSynapse(weight=abs(WEIGHT_STIMULUS_TO_WHEELS), delay=DELAY) # on left side use inhibitory receptor type to make the PushBot turn CCW sim.Projection(stimulus, left_wheels_neuron, connector=sim.AllToAllConnector(), synapse_type=stim_to_wheels, receptor_type='inhibitory') # on right side use excitatory receptor type to make the PushBot turn CCW sim.Projection(stimulus, right_wheels_neuron, connector=sim.AllToAllConnector(), synapse_type=stim_to_wheels, receptor_type='excitatory') return { "left_wheels_neuron": left_wheels_neuron, "right_wheels_neuron": right_wheels_neuron, "stimulus": stimulus }
def create_brain(): # Brain simulation set-up sim.setup(timestep=0.1, min_delay=0.1, max_delay=20.0, threads=1, rng_seeds=[1234]) ## NEURONS ## # Neuronal parameters NEURONPARAMS = { 'cm': 0.025, 'v_rest': -60.5, 'tau_m': 10., 'e_rev_E': 0.0, 'e_rev_I': -75.0, 'v_reset': -60.5, 'v_thresh': -60.0, 'tau_refrac': 10.0, 'tau_syn_E': 2.5, 'tau_syn_I': 2.5 } # Build the neuronal model cell_class = sim.IF_cond_alpha(**NEURONPARAMS) # Define the neuronal population population = sim.Population(size=4, cellclass=cell_class) ## SYNAPSES ## # Build the weights matrix weights = np.zeros((2, 2)) weights[0, 1] = 1. weights[1, 0] = 1. weights *= 5e-5 # Synaptic parameters SYNAPSE_PARAMS = { "weight": weights, "delay": 1.0, 'U': 1.0, 'tau_rec': 1.0, 'tau_facil': 1.0 } # Build synaptic model synapse_type = sim.TsodyksMarkramSynapse(**SYNAPSE_PARAMS) ## NETWORK ## # Connect neurons connector = sim.AllToAllConnector() sim.Projection(presynaptic_population=population[0:2], postsynaptic_population=population[2:4], connector=connector, synapse_type=synapse_type, receptor_type='excitatory') # Initialize the network sim.initialize(population, v=population.get('v_rest')) return population
def create_brain(): """ Initializes PyNN with the minimal neuronal network """ sim.setup(timestep=0.1, min_delay=0.1, max_delay=20.0, threads=1, rng_seeds=[1234]) # Following parameters were taken from the husky braitenberg brain experiment (braitenberg.py) SENSORPARAMS = { 'cm': 0.025, 'v_rest': -60.5, 'tau_m': 10., 'e_rev_E': 0.0, 'e_rev_I': -75.0, 'v_reset': -60.5, 'v_thresh': -60.0, 'tau_refrac': 10.0, 'tau_syn_E': 2.5, 'tau_syn_I': 2.5 } SYNAPSE_PARAMS = { "weight": 0.5e-4, "delay": 20.0, 'U': 1.0, 'tau_rec': 1.0, 'tau_facil': 1.0 } cell_class = sim.IF_cond_alpha(**SENSORPARAMS) # Define the network structure: 2 neurons (1 sensor and 1 actors) population = sim.Population(size=2, cellclass=cell_class) synapse_type = sim.TsodyksMarkramSynapse(**SYNAPSE_PARAMS) connector = sim.AllToAllConnector() # Connect neurons sim.Projection(presynaptic_population=population[0:1], postsynaptic_population=population[1:2], connector=connector, synapse_type=synapse_type, receptor_type='excitatory') sim.initialize(population, v=population.get('v_rest')) return population
def create_brain(dna=l): """ Initializes PyNN with the neuronal network that has to be simulated """ NEURONPARAMS = { 'v_rest': -60.5, 'tau_m': 4.0, 'tau_refrac': 2.0, 'tau_syn_E': 10.0, 'tau_syn_I': 10.0, 'v_thresh': -60.4, 'v_reset': -60.5 } SYNAPSE_PARAMS = {"weight": 1.0, "delay": 2.0} population = sim.Population(10, sim.IF_cond_alpha()) population[0:10].set(**NEURONPARAMS) # Connect neurons CIRCUIT = population SYN = sim.StaticSynapse(**SYNAPSE_PARAMS) row_counter = 0 for row in dna: logger.info(row) n = np.array(row) for i in range(1, 11): if n[i] == 1: r_type = 'excitatory' if dna[i - 1][0] else 'inhibitory' logger.info('Synapse from Neuron: ' + str(i) + ' to ' + str(row_counter + 1) + ' ' + r_type) sim.Projection( presynaptic_population=CIRCUIT[row_counter:row_counter + 1], postsynaptic_population=CIRCUIT[i - 1:i], connector=sim.OneToOneConnector(), synapse_type=SYN, receptor_type=r_type) row_counter += 1 sim.initialize(population, v=population.get('v_rest')) logger.debug("Circuit description: " + str(population.describe())) return population
def create_brain(): """ Initializes PyNN with the minimal neuronal network """ #sim.setup(timestep=0.1, min_delay=0.1, max_delay=20., threads=1, rng_seeds=[1234]) ## PARAMETER # neuron setup n_refl = 100 # amount of reflex neurons n_raphe = 100 # amount of Raphe neuros per pool n_total = n_refl + 2 * n_raphe w = 1.0 # neuron weight # neuron and synapse parameter SENSORPARAMS = { 'v_rest': -70.0, 'tau_m': 10.0, 'v_thresh': -50.0, 'tau_refrac': 5.0 } REFL_PARAMS = { 'cm': 0.025, 'tau_m': 10.0, 'v_reset': -60.0, 'v_thresh': -55.0 } RAPHENUCLEI_PARAMS = {'cm': 0.025, 'v_reset': -60.0, 'v_thresh': -55.0} SYNAPSE_PARAMS = { 'weight': w, 'delay': 0.0, 'U': 1.0, 'tau_rec': 1.0, 'tau_facil': 1.0 } refl_class = sim.IF_cond_alpha(**SENSORPARAMS) neurons = sim.Population(size=n_total, cellclass=refl_class, label='neurons') sim.initialize(neurons) return neurons
def create_brain(): NEURONPARAMS = {'v_rest': -60.5, 'tau_m': 4.0, 'tau_refrac': 2.0, 'tau_syn_E': 10.0, 'tau_syn_I': 10.0, 'e_rev_E': 0.0, 'e_rev_I': -75.0, 'v_thresh': -60.4, 'v_reset': -60.5} SYNAPSE_PARAMS = {"weight": 1.0, "delay": 2.0} population = sim.Population(10, sim.IF_cond_alpha()) population[0:10].set(**NEURONPARAMS) # Connect neurons CIRCUIT = population SYN = sim.StaticSynapse(**SYNAPSE_PARAMS) row_counter = 0 for row in dna: logger.info(row) n = np.array(row) r_type = 'excitatory' if n[0] == 0: r_type = 'inhibitory' for i in range(19, 29): if n[i] == 1: sim.Projection(presynaptic_population=CIRCUIT[row_counter:1 + row_counter], postsynaptic_population=CIRCUIT[i - 19:i - 18], connector=sim.OneToOneConnector(), synapse_type=SYN, receptor_type=r_type) row_counter += 1 sim.initialize(population, v=population.get('v_rest')) logger.debug("Circuit description: " + str(population.describe())) return population
def create_brain (): NEURON_PARAMS = { 'v_rest' : -60.5, 'cm' : 0.025, 'tau_m' : 10.0, 'tau_refrac': 10.0, 'tau_syn_E' : 2.5, 'tau_syn_I' : 2.5, 'e_rev_E' : 0.0, 'e_rev_I' : -75.0, 'v_thresh' : -60.0, 'v_reset' : -60.5 } neuron_pop = sim.Population ( 1, sim.IF_cond_alpha (**NEURON_PARAMS), label="neuron_pop" ) return {"neuron_pop" : neuron_pop}
def create_brain(): """ Initializes PyNN with the neuronal network that has to be simulated """ import os h5_file_path = os.path.join(os.getcwd(), 'CDP1_brain_model_700_neurons.h5') h5file = h5py.File(h5_file_path, "r") #sim.setup(timestep=0.1, min_delay=0.1, max_delay=20.0, threads=1, debug=True) N = (h5file["x"].value).shape[0] cells = sim.Population(N, sim.IF_cond_alpha, {}) for i, gid_ in enumerate(range(1, N + 1)): hasSyns = True try: r_syns = h5file["syn_" + str(gid_)].value r_synsT = h5file["synT_" + str(gid_)].value except: hasSyns = False if hasSyns and i < 10: params = { 'U': 1.0, 'tau_rec': 0.0, 'tau_facil': 0.0 } syndynamics = sim.SynapseDynamics(fast=sim.TsodyksMarkramMechanism( **params)) sim.Projection(cells[i:i + 1], cells[r_synsT - 1], sim.FixedNumberPostConnector(n=r_synsT.shape[0]), synapse_dynamics=syndynamics) population = cells h5file.close() logger.info("Circuit description: " + str(population.describe())) return population
def create_brain(): """ Initializes PyNN with the neuronal network that has to be simulated """ SENSORPARAMS = {'v_rest': -60.5, 'cm': 0.025, 'tau_m': 10., 'tau_refrac': 10.0, 'tau_syn_E': 2.5, 'tau_syn_I': 2.5, 'e_rev_E': 0.0, 'e_rev_I': -75.0, 'v_thresh': -60.0, 'v_reset': -60.5} GO_ON_PARAMS = {'v_rest': -60.5, 'cm': 0.025, 'tau_m': 10.0, 'e_rev_E': 0.0, 'e_rev_I': -75.0, 'v_reset': -61.6, 'v_thresh': -60.51, 'tau_refrac': 10.0, 'tau_syn_E': 2.5, 'tau_syn_I': 2.5} # POPULATION_PARAMS = SENSORPARAMS * 5 + GO_ON_PARAMS + SENSORPARAMS * 2 population = sim.Population(8, sim.IF_cond_alpha()) population[0:5].set(**SENSORPARAMS) population[5:6].set(**GO_ON_PARAMS) population[6:8].set(**SENSORPARAMS) # Shared Synapse Parameters syn_params = {'U': 1.0, 'tau_rec': 1.0, 'tau_facil': 1.0} # Synaptic weights WEIGHT_RED_TO_ACTOR = 1.5e-4 WEIGHT_RED_TO_GO_ON = 1.2e-3 # or -1.2e-3? WEIGHT_GREEN_BLUE_TO_ACTOR = 1.05e-4 WEIGHT_GO_ON_TO_RIGHT_ACTOR = 1.4e-4 DELAY = 0.1 # Connect neurons CIRCUIT = population SYN = sim.TsodyksMarkramSynapse(weight=abs(WEIGHT_RED_TO_ACTOR), delay=DELAY, **syn_params) sim.Projection(presynaptic_population=CIRCUIT[2:3], postsynaptic_population=CIRCUIT[7:8], connector=sim.AllToAllConnector(), synapse_type=SYN, receptor_type='excitatory') sim.Projection(presynaptic_population=CIRCUIT[3:4], postsynaptic_population=CIRCUIT[6:7], connector=sim.AllToAllConnector(), synapse_type=SYN, receptor_type='excitatory') SYN = sim.TsodyksMarkramSynapse(weight=abs(WEIGHT_RED_TO_GO_ON), delay=DELAY, **syn_params) sim.Projection(presynaptic_population=CIRCUIT[0:2], postsynaptic_population=CIRCUIT[5:6], connector=sim.AllToAllConnector(), synapse_type=SYN, receptor_type='inhibitory') SYN = sim.TsodyksMarkramSynapse(weight=abs(WEIGHT_GREEN_BLUE_TO_ACTOR), delay=DELAY, **syn_params) sim.Projection(presynaptic_population=CIRCUIT[4:5], postsynaptic_population=CIRCUIT[7:8], connector=sim.AllToAllConnector(), synapse_type=SYN, receptor_type='excitatory') SYN = sim.TsodyksMarkramSynapse(weight=abs(WEIGHT_GO_ON_TO_RIGHT_ACTOR), delay=DELAY, **syn_params) sim.Projection(presynaptic_population=CIRCUIT[5:6], postsynaptic_population=CIRCUIT[7:8], connector=sim.AllToAllConnector(), synapse_type=SYN, receptor_type='excitatory') sim.initialize(population, v=population.get('v_rest')) logger.info("Circuit description: " + str(population.describe())) return population
# -*- coding: utf-8 -*- """ This is a minimal brain with 2 neurons connected together. """ # pragma: no cover __author__ = 'Felix Schneider' from hbp_nrp_cle.brainsim import simulator as sim import numpy as np sensors = sim.Population(3, cellclass=sim.IF_curr_exp()) actors = sim.Population(6, cellclass=sim.IF_curr_exp()) # best weights so far: weights = np.array([ 1.2687, 0.9408, 4.0275, 0.4076, 4.9567, 0.6792, 4.9276, 3.8688, 2.1914, 4.1219, 0.9874, 0.3526, 3.5533, 3.8544, 0.0482, 1.7837, 0.5833, 4.221 ]) weights = weights.reshape(3, 6) # weights = np.random.rand(3, 6) * 5 projection = sim.Projection(sensors, actors, sim.AllToAllConnector(), sim.StaticSynapse(weight=weights)) circuit = sensors + actors
# -*- coding: utf-8 -*- # pragma: no cover __author__ = 'Benjamin Alt, Felix Schneider and Jacqueline Rutschke' #https://github.com/Scaatis/hbpprak_perception/ # not exactly what Benjamin and Felix did but very close to it from hbp_nrp_cle.brainsim import simulator as sim import numpy as np resolution = 17 n_motors = 4 # down, up, left, right sensors = sim.Population(resolution * resolution, cellclass=sim.IF_curr_exp()) down, up, left, right = [ sim.Population(1, cellclass=sim.IF_curr_exp()) for _ in range(n_motors) ] indices = np.arange(resolution * resolution).reshape((resolution, resolution)) ones = np.ones(shape=((resolution // 2) * resolution, 1)) # upper half = eight rows from the top upper_half = sim.PopulationView(sensors, indices[:resolution // 2].flatten()) # lower half = eight rows from bottom lower_half = sim.PopulationView( sensors, indices[resolution - resolution // 2:].flatten()) # left half = eight columns from left left_half = sim.PopulationView(sensors, indices[:, :resolution // 2].flatten()) # right half = eight colums from right right_half = sim.PopulationView( sensors, indices[:, resolution - resolution // 2:].flatten())
for x1, y1, x2, y2 in itertools.product(np.arange(layer.shape[0]), np.arange(layer.shape[1]), repeat=2): w = distance_to_weight(distance.cityblock([x1, y1], [x2, y2])) weights[layer.get_idx(x1, y1)][layer.get_idx(x2, y2)] = w proj.set(weight=weights) scaling_factor = 0.1 DVS_SHAPE = np.array((128, 128)) # scale down DVS input to speed up the network input_shape = (DVS_SHAPE * scaling_factor + 1).astype(int) # + 1 for ceiling # the two neuron populations: sensors and motors sensors = sim.Population(size=np.prod(input_shape), cellclass=sim.IF_curr_exp()) motors = sim.Population(size=4, cellclass=sim.IF_curr_exp()) output_layer = Layer(motors, (2, 2)) input_layer = Layer(sensors, input_shape) n_rows = input_shape[0] low_range = (0, n_rows / 2) high_range = (n_rows / 2, n_rows) inhibition_weight = -10 excitatory_weight = 0.5 # slice pixel neurons in 4 corners top_left_bucket = input_layer.get_neuron_box(low_range, low_range) top_right_bucket = input_layer.get_neuron_box(high_range, low_range)
# -*- coding: utf-8 -*- # pragma: no cover __author__ = 'Benjamin Alt, Felix Schneider' from hbp_nrp_cle.brainsim import simulator as sim import numpy as np resolution = 17 n_motors = 4 # down, up, left, right sensors = sim.Population(resolution * resolution, cellclass=sim.IF_curr_exp()) down_stage_one, up_stage_one, left_stage_one, right_stage_one = [sim.Population(1, cellclass=sim.IF_curr_exp()) for _ in range(n_motors)] down_stage_two, up_stage_two, left_stage_two, right_stage_two = [sim.Population(1, cellclass=sim.IF_curr_exp()) for _ in range(n_motors)] indices = np.arange(resolution * resolution).reshape((resolution, resolution)) ones = np.ones(shape=((resolution // 2) * resolution,1)) upper_half = sim.PopulationView(sensors, indices[:resolution // 2].flatten()) lower_half = sim.PopulationView(sensors, indices[resolution - resolution//2:].flatten()) left_half = sim.PopulationView(sensors, indices[:, :resolution // 2].flatten()) right_half = sim.PopulationView(sensors, indices[:, resolution - resolution//2:].flatten()) center_nine = sim.PopulationView(sensors, indices[(resolution//2) - 1 : (resolution//2) + 2, (resolution//2) - 1 : (resolution//2) + 2].flatten()) pro_down_stage_one = sim.Projection(lower_half, down_stage_one, sim.AllToAllConnector(), sim.StaticSynapse(weight=ones)) pro_up_stage_one = sim.Projection(upper_half, up_stage_one, sim.AllToAllConnector(), sim.StaticSynapse(weight=ones)) pro_left_stage_one = sim.Projection(left_half, left_stage_one, sim.AllToAllConnector(), sim.StaticSynapse(weight=ones))
# -*- coding: utf-8 -*- # pragma: no cover __author__ = 'Benjamin Alt, Felix Schneider' from hbp_nrp_cle.brainsim import simulator as sim import numpy as np n_sensors = 120 n_legs = 6 sensors = sim.Population(n_sensors, cellclass=sim.IF_curr_exp()) outputs_swing = [ sim.Population(1, cellclass=sim.IF_curr_exp()) for i in range(n_legs) ] outputs_lift = [ sim.Population(1, cellclass=sim.IF_curr_exp()) for i in range(n_legs) ] projs = [] for i in range(n_legs): # Swing if i in [0, 3, 4]: weight = [1.0 for k in range(n_sensors // 3)] # cos weight.extend([0.0 for k in range(n_sensors // 3)]) # sin weight.extend([0.0 for k in range(n_sensors // 3)]) # 1 else: weight = [-1.0 for k in range(n_sensors // 3)] # cos weight.extend([0.0 for k in range(n_sensors // 3)]) # sin weight.extend([1.0 for k in range(n_sensors // 3)]) # 1 projs.append(
# -*- coding: utf-8 -*- """ Tutorial brain for the baseball experiment """ # pragma: no cover __author__ = 'Jacques Kaiser' from hbp_nrp_cle.brainsim import simulator as sim import numpy as np n_sensors = 3 n_motors = 7 np.random.seed(42) weights = np.random.rand(3, 7) * 5 sensors = sim.Population(n_sensors, cellclass=sim.IF_curr_exp()) motors = sim.Population(n_motors, cellclass=sim.IF_curr_exp()) sim.Projection(sensors, motors, sim.AllToAllConnector(), sim.StaticSynapse(weight=weights)) circuit = sensors + motors
def create_brain(): """ Initializes PyNN with the minimal neuronal network """ #sim.setup(timestep=0.1, min_delay=0.1, max_delay=20.0, threads=1, rng_seeds=[1234]) ## PARAMETER # neuron setup #n_sens = 10 # amount of sensory neurons (per joint) n_refl = 100 # amount of reflex neurons n_raphe = 100 n_test = 100 n_total = n_refl + 2 * n_raphe w = 1.0 # neuron weight # neuron and synapse parameter SENSORPARAMS = { 'cm': 0.025, 'v_rest': -60.5, 'tau_m': 10., 'e_rev_E': 0.0, 'e_rev_I': -75.0, 'v_reset': -60.5, 'v_thresh': -60.0 } REFL_PARAMS = { 'cm': 0.025, 'tau_m': 10.0, 'v_reset': -60.0, 'v_thresh': -55.0 } RAPHENUCLEI_PARAMS = {'cm': 0.025, 'v_reset': -60.0, 'v_thresh': -55.0} SYNAPSE_PARAMS = { 'weight': w, 'delay': 0.0, 'U': 1.0, 'tau_rec': 1.0, 'tau_facil': 1.0 } # ask PHILIPP which kind of neurons from PyNN refl_class = sim.IF_cond_alpha(**SENSORPARAMS) neurons = sim.Population(size=n_total, cellclass=refl_class, label='neurons') #neurons[0:n_refl].set(**REFL_PARAMS) #neurons[n_refl:n_total].set(**RAPHENUCLEI_PARAMS) #sim.Projection(presynaptic_population=pop_j1, # postsynaptic_population=pop_refl, # connector=connector, # synapse_type=synapse_type, # receptor_type='excitatory') #poisson_class = sim.SpikeSourcePoisson() #test_pop = sim.Population(size=n_test, cellclass=poisson_class, label='test_pop') #test_pop2= sim.Population(size=1, cellclass=refl_class, label='test_pop2') #test_pop.rate = 1000000.0 #sim.Projection(test_pop, test_pop2, connector = sim.AllToAllConnector()) #population = sim.Assembly(neurons, test_pop, test_pop2) #sim.initialize(population) #return population sim.initialize(neurons) return neurons
# pragma: no cover __author__ = 'Adrian Hein' from hbp_nrp_cle.brainsim import simulator as sim import numpy as np import nest # one input neuron that fires if the ball is near enough n_input = 2 # nine output neurons which are: # 0: /robot/hollie_real_left_arm_0_joint/cmd_pos # 1: /robot/hollie_real_left_arm_1_joint/cmd_pos # 2: /robot/hollie_real_left_arm_2_joint/cmd_pos # 3: /robot/hollie_real_left_arm_3_joint/cmd_pos # 4: /robot/hollie_real_left_arm_4_joint/cmd_pos # 5: /robot/hollie_real_left_arm_5_joint/cmd_pos # 6: /robot/hollie_real_left_arm_6_joint/cmd_pos # 7: /robot/hollie_real_left_hand_base_joint/cmd_pos # 8: /robot/hollie_tennis_racket_joint/cmd_pos # we have to try out which of them are important if we want to hit the ball in such way that it flies as far as possible n_output = 7 input_neurons = sim.Population(n_input, cellclass=sim.IF_curr_exp()) output_neurons = sim.Population(n_output, cellclass=sim.IF_curr_exp()) #w = sim.RandomDistribution('gamma', [1, 0.004], rng=NumpyRNG(seed=4242)) connections = sim.Projection(input_neurons, output_neurons, sim.AllToAllConnector(allow_self_connections=False), sim.StaticSynapse(weight=1.)) circuit = input_neurons + output_neurons