Exemple #1
0
    def __init__(self, port_name, width, accLatency=10.0, **kwargs):
        assert width > 0
        self.width = width
        self.ports = nest.Create('music_event_in_proxy', width)
        self.port_name = port_name
        self.parrots = None

        for i in xrange(self.width):
            nest.SetStatus([self.ports[i]], {
                'port_name': self.port_name,
                'music_channel': i
            })
        nest.SetAcceptableLatency(port_name, accLatency)
Exemple #2
0
def create_proxy_with_native_cell_types(pynn_sim, width, cell_type, port_name,
                                        proxy_type, acc_latency, is_output):
    import nest
    kwargs = {'port_name': port_name}
    proxy = pynn_sim.Population(width, cell_type, {})
    ids = map(int, proxy.all_cells)
    nest.SetStatus(ids, kwargs)
    # Acc. latency actually only matters for input ports
    if not is_output:
        nest.SetAcceptableLatency(port_name, acc_latency)
    if proxy_type == "Event" and not is_output:
        for i, proxy_id in enumerate(ids):
            nest.SetStatus([proxy_id], 'music_channel', i)
    return proxy
Exemple #3
0
 def _map_event_in_proxy(self,
                         proxy_population,
                         port_name,
                         maxBuffered=None,
                         accLatency=None):
     nest.SetStatus(proxy_population, {'port_name': port_name})
     if maxBuffered is not None:
         if 'SetMaxBuffered' in dir(nest):
             nest.SetMaxBuffered(port_name, maxBuffered)
         else:
             logger.warning(
                 "Omitting max buffer size for proxy {},"
                 "as this NEST version does not support SetMaxBuffered".
                 format(port_name))
     if accLatency is not None:
         nest.SetAcceptableLatency(port_name, float(accLatency))
     for i, n in enumerate(proxy_population):
         nest.SetStatus([n], 'music_channel', i)
Exemple #4
0
 def __init__(self, port_name, accLatency=10.0, **kwargs):
     self.port = nest.Create('music_cont_in_proxy')
     self.port_name = port_name
     nest.SetStatus(self.port, {'port_name': self.port_name})
     nest.SetAcceptableLatency(port_name, accLatency)
for i in range(p.num_neurons_per_channel):
    nest.Connect(
        [left_hemisphere['channels'][3 * p.grid_size[0][1] + 4]['d2'][i]],
        proxy_out, 'one_to_one', {
            'music_channel': 3 * p.num_neurons_per_channel + i,
            'delay': 1.0
        })

#####################################
##### JUST FOR TECHNICAL RESONS #####
#####################################

proxy_in = nest.Create('music_event_in_proxy', 1)
nest.SetStatus(proxy_in, [{
    'port_name': 'in',
    'music_channel': c
} for c in range(1)])
nest.SetAcceptableLatency('in', 1.0)  # useless?

#####################################
#####################################
#####################################

comm.Barrier()

t0 = time.time()
nest.Simulate(p.runtime * scale)

print "TIME ELAPSED: ", time.time() - t0, "rtf", p.runtime * scale / (
    1000 * (time.time() - t0))
Exemple #6
0
import yaml

from mpi4py import MPI

comm = MPI.COMM_WORLD

nest.ResetKernel()
startbuild = time.time()


nest.SetKernelStatus({"resolution": 1., "print_time": True, "overwrite_files": True})
nest.set_verbosity("M_FATAL")

proxy_sensory = nest.Create('music_event_in_proxy', 100)
nest.SetStatus(proxy_sensory, [{'port_name': 'sensory', 'music_channel': c} for c in range(100)])
nest.SetAcceptableLatency('sensory', 2.0)

print("Create devices")

sd_sensory = nest.Create("spike_detector", 1)


print("Connect")

# proxy to sd
nest.Connect(proxy_sensory, sd_sensory)


print("Simulate")

comm.Barrier()
Exemple #7
0
    'print_time': False,
    'use_wfr': False,
    'overwrite_files': True,
    'grng_seed': params['kernel_params']['seed'],
    'rng_seeds': [params['kernel_params']['seed'] + 1]
})

#######################################
# Create MUSIC devices

reward_in = nest.Create('music_rate_in_proxy', 1)
nest.SetStatus(reward_in, [{
    'port_name': 'reward_in',
    'music_channel': c
} for c in range(1)])
nest.SetAcceptableLatency('reward_in',
                          params['kernel_params']['delay'])  # useless?

proxy_in = nest.Create('music_rate_in_proxy',
                       params['input_params']['num_neurons'])
nest.SetStatus(proxy_in, [{
    'port_name': 'in',
    'music_channel': c
} for c in range(params['input_params']['num_neurons'])])
nest.SetAcceptableLatency('in', params['kernel_params']['delay'])  # useless?

proxy_actor = nest.Create('music_rate_out_proxy')
nest.SetStatus(proxy_actor, {'port_name': 'out'})

#######################################
# Create neurons
to_ms = lambda t: t * 1000.

nest.ResetKernel()
nest.set_verbosity("M_FATAL")
nest.SetKernelStatus({'resolution': 1.0})
#nest.SetKernelStatus({'print_time': True})

NUM_ENC_NEURONS = 2

proxy_in = nest.Create('music_event_in_proxy', NUM_ENC_NEURONS)
nest.SetStatus(proxy_in, [{
    'port_name': 'in',
    'music_channel': c
} for c in range(NUM_ENC_NEURONS)])
nest.SetAcceptableLatency('in', 1.0)

proxy_out = nest.Create('music_event_out_proxy')
nest.SetStatus(proxy_out, {'port_name': 'out'})

parrot = nest.Create("parrot_neuron", NUM_ENC_NEURONS)

nest.Connect(proxy_in, parrot, 'one_to_one')
for i in range(NUM_ENC_NEURONS):
    nest.Connect([parrot[i]], proxy_out, 'all_to_all', {'music_channel': i})

comm.Barrier()
start = datetime.now()

nest.Simulate(1000000)
opt_parser.add_option("-t", "--simtime", dest="simtime", type="float", help="Simulation time in s")
opt_parser.add_option("-s", "--timestep", dest="music_timestep", type="float", help="MUSIC timestep")
opt_parser.add_option("-n", "--num_neurons", dest="num_neurons", type="int", help="Number of encoding neurons")

(options, args) = opt_parser.parse_args()

nest.ResetKernel()
nest.set_verbosity("M_FATAL")
nest.SetKernelStatus({'resolution': 1.0})
#nest.SetKernelStatus({'print_time': True})

NUM_ENC_NEURONS = options.num_neurons 

proxy_in = nest.Create('music_event_in_proxy', NUM_ENC_NEURONS)
nest.SetStatus(proxy_in, [{'port_name': 'in', 'music_channel': c} for c in range(NUM_ENC_NEURONS)])
nest.SetAcceptableLatency('in', to_ms(options.music_timestep))

proxy_out = nest.Create('music_event_out_proxy')
nest.SetStatus(proxy_out, {'port_name': 'out'})

parrot = nest.Create("parrot_neuron", NUM_ENC_NEURONS)

nest.Connect(proxy_in, parrot, 'one_to_one', {'delay': to_ms(options.music_timestep)})
for i in range(NUM_ENC_NEURONS):
    nest.Connect([parrot[i]], proxy_out, 'all_to_all', {'music_channel': i, 'delay': to_ms(options.music_timestep)})

comm.Barrier()
start = datetime.now()

nest.Simulate(to_ms(options.simtime))
Exemple #10
0
    def build(self, box):
        """
    Create all nodes, used in the model.
    """

        if self.built == True: return

        self.calibrate()

        #===========================#
        # PLACE CELLS INPUT PROXIES #
        #===========================#
        """
    Create the input proxies to transmit the state to the cortex populations
    """
        params = box.input_sensor()

        self.in_cortex = tp.CreateLayer({
            'columns': box.n_CellsState[0],
            'rows': box.n_CellsState[1],
            'center': params['center'],
            'extent': params['extent'],
            'elements': 'music_event_in_proxy'
        })
        for i in range(box.n_pCells):
            nest.SetStatus([nest.GetNodes(self.in_cortex)[0][i]], {
                'music_channel': i,
                'port_name': params['p_name']
            })

        nest.SetAcceptableLatency(params['p_name'], params['AccLatency'])

        #=============#
        # PLACE CELLS #
        #=============#
        """
    Create three different populations encoding the three angular velocities.
    """
        params = box.cortex()
        nest.CopyModel(params['copymodel'], params['model'],
                       params['settings'])
        self.cortex = {}

        x = [
            params['center'][0] - params['extent'][0] / 2 + 0.25,
            params['center'][0] + params['extent'][0] / 2 - 0.25
        ]
        y = [
            params['center'][1] - params['extent'][1] / 2 + 0.25,
            params['center'][1] + params['extent'][1] / 2 - 0.25
        ]
        pos = [[np.random.uniform(x[0], x[1]),
                np.random.uniform(y[0], y[1])]
               for j in range(params['number'])]
        self.cortex = tp.CreateLayer({
            'center': params['center'],
            'extent': params['extent'],
            'positions': pos,
            'elements': 'parrot_neuron'
        })

        #========#
        # CRITIC #
        #========#
        """
    Create the three motors to generate the control laws
    """
        params = box.critic()
        nest.CopyModel(params['copymodel'], params['model'],
                       params['settings'])

        x = [
            params['center'][0] - params['extent'][0] / 2 + 0.25,
            params['center'][0] + params['extent'][0] / 2 - 0.25
        ]
        y = [
            params['center'][1] - params['extent'][1] / 2 + 0.25,
            params['center'][1] + params['extent'][1] / 2 - 0.25
        ]
        pos = [[np.random.uniform(x[0], x[1]),
                np.random.uniform(y[0], y[1])]
               for j in range(params['number'])]
        self.critic = tp.CreateLayer({
            'center': params['center'],
            'extent': params['extent'],
            'positions': pos,
            'elements': params['model']
        })
        # self.randomize(nest.GetNodes(self.critic)[0], box.rand_param(), 'normal')

        self.rec_nodes = self.rec_nodes + list(nest.GetNodes(self.critic)[0])

        # self.initial_inh = nest.Create('poisson_generator', 1, params={'rate': 1000.0}) # , 'stop':  600.0}
        # nest.Connect(self.initial_inh, nest.GetNodes(self.critic)[0], syn_spec={'weight': 30.0, 'delay': 0.1})

        #=======#
        # ACTOR #
        #=======#
        """
    Create the three motors to generate the control laws
    """
        params = box.actor()
        nest.CopyModel(params['copymodel'], params['model'],
                       params['settings'])

        x = [
            params['center'][0] - params['extent'][0] / 2 + 0.25,
            params['center'][0] + params['extent'][0] / 2 - 0.25
        ]
        y = [
            params['center'][1] - params['extent'][1] / 2 + 0.25,
            params['center'][1] + params['extent'][1] / 2 - 0.25
        ]
        pos = [[np.random.uniform(x[0], x[1]),
                np.random.uniform(y[0], y[1])]
               for j in range(params['number'])]
        self.actor = tp.CreateLayer({
            'center': params['center'],
            'extent': params['extent'],
            'positions': pos,
            'elements': params['model']
        })
        # self.randomize(nest.GetNodes(self.actor)[0], box.rand_param(), 'normal')

        self.rec_nodes = self.rec_nodes + list(nest.GetNodes(self.actor)[0])

        #======================#
        # REWARD INPUT PROXIES #
        #======================#
        """
    Input Proxies for Dopaminergic Neurons
    """

        params = box.input_dopa()

        self.input_dopa = tp.CreateLayer({
            'columns': 1,
            'rows': 2,
            'center': params['center'],
            'elements': params['model']
        })
        nest.SetStatus([nest.GetNodes(self.input_dopa)[0][0]], {
            'music_channel': params['channel_exc'],
            'port_name': params['p_name']
        })
        nest.SetStatus([nest.GetNodes(self.input_dopa)[0][1]], {
            'music_channel': params['channel_inh'],
            'port_name': params['p_name']
        })

        #=========#
        # SNc/VTA #
        #=========#
        """
    Create the dopaminergic neurorns population and the poisson generator to make them firing in rest
    condition at cerating firing rate. The plasitcity law will take into account this baseline.
    The capacitance, initial and reset membrane potential, threshold of the dopaminergic neurons are normally distributed.
    """

        params = box.dopa_neur()
        nest.CopyModel(params['copymodel'], params['model'], {
            'V_reset': params['V_reset'],
            'tau_minus': params['tau_ltd']
        })

        x = [
            params['center'][0] - params['extent'][0] / 2 + 0.25,
            params['center'][0] + params['extent'][0] / 2 - 0.25
        ]
        y = [
            params['center'][1] - params['extent'][1] / 2 + 0.25,
            params['center'][1] + params['extent'][1] / 2 - 0.25
        ]
        pos = [[np.random.uniform(x[0], x[1]),
                np.random.uniform(y[0], y[1])]
               for j in range(params['number'])]
        self.dopa = tp.CreateLayer({
            'center': params['center'],
            'extent': params['extent'],
            'positions': pos,
            'elements': params['model']
        })
        self.randomize(
            nest.GetNodes(self.dopa)[0], box.rand_param(), 'uniform')

        self.rec_nodes = self.rec_nodes + list(nest.GetNodes(self.dopa)[0])

        #====================#
        # VOLUME TRANSMITTER #
        #====================#
        """
    Volume Transmitter
    """
        params = box.vt_dopa()

        self.vt_dopa = tp.CreateLayer({
            'columns': 1,
            'rows': 1,
            'center': params['center'],
            'elements': params['model']
        })

        #==============#
        # OUTPUT PROXY #
        #==============#
        """
    Create the outpot proxies to transmit the control to the environment
    """

        params = box.output()

        self.output = tp.CreateLayer({
            'columns': 1,
            'rows': 1,
            'center': params['center'],
            'elements': params['model']
        })

        # Set port name for MUSIC Output Proxies
        nest.SetStatus(
            nest.GetNodes(self.output)[0], {'port_name': params['p_name']})

        #==============================#
        # DOPA BASENOISE AND DETECTORS #
        #==============================#
        """
    Create poisson spikes generator to excite dopaminergic neurons and spikes
    detectors for all populations
    """

        self.wr = nest.Create('weight_recorder')

        if self.basenoise:
            self.baseline = nest.Create('poisson_generator',
                                        1,
                                        params={'rate': 2500.0})

        if self.detectpops:
            self.sdetector = nest.Create('spike_detector', 4)
#==============================#

        self.built = True
        del params