コード例 #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
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
コード例 #6
0
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
コード例 #7
0
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
コード例 #8
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
コード例 #9
0
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
コード例 #10
0
    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
コード例 #11
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
コード例 #12
0
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(),
                      sim.StaticSynapse(weight=ones))
コード例 #13
0
]

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(),
            sim.StaticSynapse(weight=np.array(weight).reshape((n_sensors,
コード例 #14
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