Пример #1
0
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
Пример #3
0
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
Пример #4
0
def add_lateral_connections_topology(layer, distance_to_weight):
    proj = sim.Projection(layer.population, layer.population,
                          sim.AllToAllConnector(), sim.StaticSynapse())

    weights = np.zeros((layer.size(), layer.size()))

    # for all combinations of neurons
    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)
Пример #5
0
# -*- 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 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
Пример #7
0
# -*- 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
    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())
# center nine =  nine center squares
center_nine = sim.PopulationView(
    sensors, indices[(resolution // 2) - 1:(resolution // 2) + 2,
                     (resolution // 2) - 1:(resolution // 2) + 2].flatten())

pro_down = sim.Projection(lower_half, down, sim.AllToAllConnector(),
                          sim.StaticSynapse(weight=ones))
pro_up = sim.Projection(upper_half, up, sim.AllToAllConnector(),
                        sim.StaticSynapse(weight=ones))
pro_left = sim.Projection(left_half, left, sim.AllToAllConnector(),
                          sim.StaticSynapse(weight=ones))
pro_right = sim.Projection(right_half, right, sim.AllToAllConnector(),
                           sim.StaticSynapse(weight=ones))

circuit = sensors + down + up
Пример #9
0
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)
bottom_left_bucket = input_layer.get_neuron_box(low_range, high_range)
bottom_right_bucket = input_layer.get_neuron_box(high_range, high_range)

# connect each bucket to respective output neuron
for idx, bucket in enumerate([
        top_left_bucket, top_right_bucket, bottom_left_bucket,
        bottom_right_bucket
]):
    sim.Projection(bucket, sim.PopulationView(motors, [idx]),
                   sim.AllToAllConnector(),
                   sim.StaticSynapse(weight=excitatory_weight))

inhibition_weight = -10
# lateral inhibition in the output layer
add_lateral_connections_topology(output_layer, lambda d: inhibition_weight
                                 if d != 0 else 0)

print('There are {}x{}={} neurons in the input layer'.format(
    input_shape[0], input_shape[1], np.prod(input_shape)))

print('There are {} motor neurons'.format(len(motors)))

circuit = sensors + motors
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))
pro_right_stage_one = sim.Projection(right_half, right_stage_one, sim.AllToAllConnector(),
                      sim.StaticSynapse(weight=ones))

pro_down_stage_two = sim.Projection(lower_half, down_stage_two, sim.AllToAllConnector(),
                      sim.StaticSynapse(weight=ones))
pro_up_stage_two = sim.Projection(upper_half, up_stage_two, sim.AllToAllConnector(),
                      sim.StaticSynapse(weight=ones))
pro_left_stage_two = sim.Projection(left_half, left_stage_two, sim.AllToAllConnector(),
                      sim.StaticSynapse(weight=ones))
pro_right_stage_two = sim.Projection(right_half, right_stage_two, sim.AllToAllConnector(),
]

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(
        sim.Projection(
            sensors, outputs_swing[i], sim.AllToAllConnector(),
            sim.StaticSynapse(weight=np.array(weight).reshape((n_sensors,
                                                               1)))))

    # Lift
    if i in [0, 3, 4]:
        weight = [0.0 for k in range(n_sensors // 3)]  # cos
        weight.extend([0.5 for k in range(n_sensors // 3)])  # sin
        weight.extend([0.0 for k in range(n_sensors // 3)])  # 1
    else:
        weight = [0.0 for k in range(n_sensors // 3)]  # cos
        weight.extend([-0.5 for k in range(n_sensors // 3)])  # sin
        weight.extend([0.5 for k in range(n_sensors // 3)])  # 1
    projs.append(
        sim.Projection(
            sensors, outputs_lift[i], sim.AllToAllConnector(),
Пример #12
0
# 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