Пример #1
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
Пример #2
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
# -*- 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())
Пример #4
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(
Пример #7
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