• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python core.is_listlike函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pyNN.core.is_listlike函数的典型用法代码示例。如果您正苦于以下问题:Python is_listlike函数的具体用法?Python is_listlike怎么用?Python is_listlike使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了is_listlike函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: set

    def set(self, name, value):
        """
        Set connection attributes for all connections on the local MPI node.

        `name`  -- attribute name
        `value` -- the attribute numeric value, or a list/1D array of such
                   values of the same length as the number of local connections,
                   or a 2D array with the same dimensions as the connectivity
                   matrix (as returned by `get(format='array')`)
        """
        if numpy.isscalar(value):
            for c in self:
                setattr(c, name, value)
        elif isinstance(value, numpy.ndarray) and len(value.shape) == 2:
            for c in self.connections:
                addr = (self.pre.id_to_index(c.source), self.post.id_to_index(c.target))
                try:
                    val = value[addr]
                except IndexError as e:
                    raise IndexError("%s. addr=%s" % (e, addr))
                if numpy.isnan(val):
                    raise Exception("Array contains no value for synapse from %d to %d" % (c.source, c.target))
                else:
                    setattr(c, name, val)
        elif core.is_listlike(value):
            for c,val in zip(self.connections, value):
                setattr(c, name, val)
        else:
            raise TypeError("Argument should be a numeric type (int, float...), a list, or a numpy array.")
开发者ID:Huitzilo,项目名称:PyNN,代码行数:29,代码来源:__init__.py


示例2: __iter__

    def __iter__(self):
        r"""
        Return an array-element-wise iterator over the parameter space.

        Each item in the iterator is a dict, containing the same keys as the
        :class:`ParameterSpace`. For the `i`\th dict returned by the iterator,
        each value is the `i`\th element of the corresponding lazy array in the
        parameter space.

        Example:

        >>> ps = ParameterSpace({'a': [2, 3, 5, 8], 'b': 7, 'c': lambda i: 3*i+2}, shape=(4,))
        >>> ps.evaluate()
        >>> for D in ps:
        ...     print(D)
        ...
        {'a': 2, 'c': 2, 'b': 7}
        {'a': 3, 'c': 5, 'b': 7}
        {'a': 5, 'c': 8, 'b': 7}
        {'a': 8, 'c': 11, 'b': 7}
        """
        if not self._evaluated:
            raise Exception("Must call evaluate() method before iterating over a ParameterSpace")
        for i in range(self._evaluated_shape[0]):
            D = {}
            for name, value in self._parameters.items():
                if is_listlike(value):
                    D[name] = value[i]
                else:
                    D[name] = value
                assert not isinstance(D[name], LazyArray) # should all have been evaluated by now
            yield D
开发者ID:markovg,项目名称:PyNN,代码行数:32,代码来源:parameters.py


示例3: check_weight

def check_weight(weight, synapse_type, is_conductance):
    if weight is None:
        weight = DEFAULT_WEIGHT
    if core.is_listlike(weight):
        weight = numpy.array(weight)
        nan_filter = (1 - numpy.isnan(weight)).astype(bool)  # weight arrays may contain NaN, which should be ignored
        filtered_weight = weight[nan_filter]
        all_negative = (filtered_weight <= 0).all()
        all_positive = (filtered_weight >= 0).all()
        if not (all_negative or all_positive):
            raise errors.InvalidWeightError("Weights must be either all positive or all negative")
    elif numpy.isreal(weight):
        all_positive = weight >= 0
        all_negative = weight < 0
    else:
        raise errors.InvalidWeightError("Weight must be a number or a list/array of numbers.")
    if is_conductance or synapse_type == 'excitatory':
        if not all_positive:
            raise errors.InvalidWeightError("Weights must be positive for conductance-based and/or excitatory synapses")
    elif is_conductance == False and synapse_type == 'inhibitory':
        if not all_negative:
            raise errors.InvalidWeightError("Weights must be negative for current-based, inhibitory synapses")
    else:  # is_conductance is None. This happens if the cell does not exist on the current node.
        logger.debug("Can't check weight, conductance status unknown.")
    return weight
开发者ID:agravier,项目名称:pynn,代码行数:25,代码来源:projections.py


示例4: _probabilistic_connect

    def _probabilistic_connect(self, tgt, p):
        """
        Connect-up a Projection with connection probability p, where p may be either
        a float 0<=p<=1, or a dict containing a float array for each pre-synaptic
        cell, the array containing the connection probabilities for all the local
        targets of that pre-synaptic cell.
        """
        if numpy.isscalar(p) and p == 1:
            create = numpy.arange(self.local.sum())
        else:
            rarr   = self.probas_generator.get(self.N)
            if not core.is_listlike(rarr) and numpy.isscalar(rarr): # if N=1, rarr will be a single number
                rarr = numpy.array([rarr])
            create = numpy.where(rarr < p)[0]  
        self.distance_matrix.set_source(tgt.position)
        #create  = self.projection.pre.id_to_index(create).astype(int)
        sources = self.projection.pre.all_cells.flatten()[create]
        if not self.allow_self_connections and self.projection.pre == self.projection.post and tgt in sources:
            i       = numpy.where(sources == tgt)[0]
            sources = numpy.delete(sources, i)
            create  = numpy.delete(create, i)

        weights = self.weights_generator.get(self.N, self.distance_matrix, create)
        delays  = self.delays_generator.get(self.N, self.distance_matrix, create)        
        
        if len(sources) > 0:
            self.projection._convergent_connect(sources.tolist(), tgt, weights, delays)
开发者ID:agravier,项目名称:pynn,代码行数:27,代码来源:connectors2.py


示例5: _smallworld_connect

 def _smallworld_connect(self, src, p):
     """
     Connect-up a Projection with connection probability p, where p may be either
     a float 0<=p<=1, or a dict containing a float array for each pre-synaptic
     cell, the array containing the connection probabilities for all the local
     targets of that pre-synaptic cell.
     """
     rarr   = self.probas_generator.get(self.N)
     if not core.is_listlike(rarr) and numpy.isscalar(rarr): # if N=1, rarr will be a single number
         rarr = numpy.array([rarr])
     create = numpy.where(rarr < p)[0]  
     self.distance_matrix.set_source(src.position)        
     
     targets    = self.candidates[create]        
     candidates = self.projection.post.all_cells.flatten()          
     if not self.allow_self_connections and projection.pre == projection.post:
         i          = numpy.where(candidates == src)[0]
         candidates = numpy.delete(candidates, i)
     
     rarr            = self.probas_generator.get(len(create))
     rewired         = rarr < self.rewiring
     if sum(rewired) > 0:
         idx              = numpy.random.random_integers(0, len(candidates)-1, sum(rewired))
         targets[rewired] = candidates[idx]
     create          = self.projection.post.id_to_index(targets).astype(int)
     weights         = self.weights_generator.get(self.N, self.distance_matrix, create)
     delays          = self.delays_generator.get(self.N, self.distance_matrix, create)      
                 
     if len(targets) > 0:
         self.projection._divergent_connect(src, targets.tolist(), weights, delays)
开发者ID:agravier,项目名称:pynn,代码行数:30,代码来源:connectors2.py


示例6: _divergent_connect

    def _divergent_connect(self, source, targets, weights, delays):
        """
        Connect a neuron to one or more other neurons with a static connection.

        `source`  -- the ID of the pre-synaptic cell.
        `targets` -- a list/1D array of post-synaptic cell IDs, or a single ID.
        `weight`  -- a list/1D array of connection weights, or a single weight.
                     Must have the same length as `targets`.
        `delays`  -- a list/1D array of connection delays, or a single delay.
                     Must have the same length as `targets`.
        """
        #print("connecting", source, "to", targets, "with weights", weights, "and delays", delays)
        if not core.is_listlike(targets):
            targets = [targets]
        if isinstance(weights, float):
            weights = [weights]
        if isinstance(delays, float):
            delays = [delays]
        assert len(targets) > 0
        if not isinstance(source, common.IDMixin):
            raise errors.ConnectionError("source should be an ID object, actually %s" % type(source))
        for target in targets:
            if not isinstance(target, common.IDMixin):
                raise errors.ConnectionError("Invalid target ID: %s" % target)
        assert len(targets) == len(weights) == len(delays), "%s %s %s" % (len(targets), len(weights), len(delays))
        synapse_type = self.synapse_type or "excitatory"
        delays = numpy.array(delays).astype(numpy.int).tolist()
        if self.synapse_type == 'inhibitory' and common.is_conductance(targets[0]):
            weights *= -1  # NEMO wants negative values for inhibitory weights, even if these are conductances
        if isinstance(weights, numpy.ndarray):
            weights = weights.tolist()
        source = int(source)
        synapses = simulator.state.net.add_synapse(source, targets, delays, weights, self._is_plastic)
        self._sources.append(source)
        self._connections += [(synapses[0], synapses[-1])]
开发者ID:NeuralEnsemble,项目名称:PyNN,代码行数:35,代码来源:__init__.py


示例7: _convergent_connect

 def _convergent_connect(self, presynaptic_indices, postsynaptic_index,
                         **connection_parameters):
     connection_parameters.pop("dendritic_delay_fraction", None)  # TODO: need to to handle this
     presynaptic_index_partitions = self._partition(presynaptic_indices)
     j_group, j = self._localize_index(postsynaptic_index)
     # specify which connections exist
     for i_group, i in enumerate(presynaptic_index_partitions):
         if i.size > 0:
             self._brian_synapses[i_group][j_group][i, j] = True
             self._n_connections += i.size
     # set connection parameters
     for name, value in chain(connection_parameters.items(),
                              self.synapse_type.initial_conditions.items()):
         if name == 'delay':
             scale = self._simulator.state.dt * ms
             value /= scale                         # ensure delays are rounded to the
             value = numpy.round(value) * scale     # nearest time step, rather than truncated
         for i_group, i in enumerate(presynaptic_index_partitions):
             if i.size > 0:
                 brian_var = getattr(self._brian_synapses[i_group][j_group], name)
                 if is_listlike(value):
                     for ii, v in zip(i, value):
                         brian_var[ii, j] = v
                 else:
                     for ii in i:
                         brian_var[ii, j] = value
开发者ID:costypetrisor,项目名称:PyNN,代码行数:26,代码来源:projections.py


示例8: _divergent_connect

    def _divergent_connect(self, source, targets, weights, delays, homogeneous=False):
        """
        Connect a neuron to one or more other neurons with a static connection.

        `source`  -- the ID of the pre-synaptic cell.
        `targets` -- a list/1D array of post-synaptic cell IDs, or a single ID.
        `weight`  -- a list/1D array of connection weights, or a single weight.
                     Must have the same length as `targets`.
        `delays`  -- a list/1D array of connection delays, or a single delay.
                     Must have the same length as `targets`.
        """
        #print "connecting", source, "to", targets, "with weights", weights, "and delays", delays
        if not core.is_listlike(targets):
            targets = [targets]
        if isinstance(weights, float):
            weights = [weights]
        if isinstance(delays, float):
            delays = [delays]
        assert len(targets) > 0
        if not isinstance(source, common.IDMixin):
            raise errors.ConnectionError("source should be an ID object, actually %s" % type(source))
        for target in targets:
            if not isinstance(target, common.IDMixin):
                raise errors.ConnectionError("Invalid target ID: %s" % target)
        assert len(targets) == len(weights) == len(delays), "%s %s %s" % (len(targets),len(weights),len(delays))
        if common.is_conductance(targets[0]):
            units = uS
        else:
            units = nA
        synapse_type = self.synapse_type or "excitatory"
        try:
            source_group = source.parent_group
        except AttributeError, errmsg:
            raise errors.ConnectionError("%s. Maybe trying to connect from non-existing cell (ID=%s)." % (errmsg, source))
开发者ID:bernhardkaplan,项目名称:PyNN,代码行数:34,代码来源:__init__.py


示例9: _get_spiketimes

 def _get_spiketimes(self, id):
     if is_listlike(id):
         all_spiketimes = {}
         for cell_id in id:
             i = cell_id - self.population.first_id
             all_spiketimes[cell_id] = self._devices['spikes'].spiketimes[i] / ms
         return all_spiketimes
     else:
         i = id - self.population.first_id
         return self._devices['spikes'].spiketimes[i] / ms
开发者ID:NeuralEnsemble,项目名称:PyNN,代码行数:10,代码来源:recording.py


示例10: reverse_translate

 def reverse_translate(cls, native_parameters):
     """Translate simulator-specific model parameters to standardized parameters."""
     standard_parameters = {}
     for name,D  in cls.translations.items():
         if is_listlike(cls.default_parameters[name]):
             tname = D['translated_name']
             native_parameters[tname] = numpy.array(native_parameters[tname])
         try:
             standard_parameters[name] = eval(D['reverse_transform'], {}, native_parameters)
         except NameError, errmsg:
             raise NameError("Problem translating '%s' in %s. Transform: '%s'. Parameters: %s. %s" \
                             % (name, cls.__name__, D['reverse_transform'], native_parameters, errmsg))
开发者ID:agravier,项目名称:pynn,代码行数:12,代码来源:__init__.py


示例11: _set_spiketimes

 def _set_spiketimes(self, spiketimes):
     if core.is_listlike(spiketimes):
         assert len(spiketimes) == len(self), (
             "spiketimes (length %d) must contain as many iterables as there are cells in the group (%d)."
             % (len(spiketimes), len(self))
         )
         assert isinstance(spiketimes[0], Sequence)
         self._threshold.set_spike_times([st.value for st in spiketimes])
     elif isinstance(spiketimes, Sequence):
         self._threshold.set_spike_times([spiketimes.value for i in range(len(self))])
     else:
         raise Exception()
开发者ID:bernhardkaplan,项目名称:PyNN,代码行数:12,代码来源:cells.py


示例12: _probabilistic_connect

    def _probabilistic_connect(self, tgt, p, n_connections=None, rewiring=None):
        """
        Connect-up a Projection with connection probability p, where p may be either
        a float 0<=p<=1, or a dict containing a float array for each pre-synaptic
        cell, the array containing the connection probabilities for all the local
        targets of that pre-synaptic cell.
        """
        if numpy.isscalar(p) and p == 1:
            precreate = numpy.arange(self.N, dtype=numpy.int)
        else:
            rarr   = self.probas_generator.get(self.M)
            if not core.is_listlike(rarr) and numpy.isscalar(rarr): # if N=1, rarr will be a single number
                rarr = numpy.array([rarr])
            precreate = numpy.where(rarr < p)[0]  
        self.distance_matrix.set_source(tgt.position)
        
        if not self.allow_self_connections and self.projection.pre == self.projection.post:
            idx_tgt   = numpy.where(self.candidates == tgt)
            if len(idx_tgt) > 0:
                i     = numpy.where(precreate == idx_tgt[0])
                if len(i) > 0:
                    precreate = numpy.delete(precreate, i[0])
                
        if (rewiring is not None) and (rewiring > 0):
            idx = numpy.arange(self.N, dtype=numpy.int)          
            if not self.allow_self_connections and self.projection.pre == self.projection.post:
                i   = numpy.where(self.candidates == tgt)[0]
                idx = numpy.delete(idx, i)
            
            rarr    = self.probas_generator.get(self.M)[precreate]
            rewired = numpy.where(rarr < rewiring)[0]
            N       = len(rewired)
            if N > 0:
                new_idx            = (len(idx)-1) * self.probas_generator.get(self.M)[precreate]
                precreate[rewired] = idx[new_idx.astype(int)]    
        
        if (n_connections is not None) and (len(precreate) > 0):
            create = numpy.array([], dtype=numpy.int)
            while len(create) < n_connections: # if the number of requested cells is larger than the size of the
                                               # presynaptic population, we allow multiple connections for a given cell
                create = numpy.concatenate((create, self.projection.rng.permutation(precreate)))
            create = create[:n_connections]
        else:
            create = precreate   

        sources = self.candidates[create]        
        weights = self.weights_generator.get(self.M, self.distance_matrix, create)
        delays  = self.delays_generator.get(self.M, self.distance_matrix, create)        
        
        if len(sources) > 0:
            self.projection._convergent_connect(sources.tolist(), tgt, weights, delays)
开发者ID:agravier,项目名称:pynn,代码行数:51,代码来源:connectors.py


示例13: _convergent_connect

    def _convergent_connect(self, sources, target, weights, delays):
        """
        Connect a neuron to one or more other neurons with a static connection.
        
        `sources`  -- a list/1D array of pre-synaptic cell IDs, or a single ID.
        `target` -- the ID of the post-synaptic cell.
        `weight`  -- a list/1D array of connection weights, or a single weight.
                     Must have the same length as `targets`.
        `delays`  -- a list/1D array of connection delays, or a single delay.
                     Must have the same length as `targets`.
        """
        if not isinstance(target, (int, long)) or target < 0:
            errmsg = "Invalid target ID: %s" % target
            raise errors.ConnectionError(errmsg)
        if not core.is_listlike(sources):
            sources = [sources]
        if isinstance(weights, float):
            weights = [weights]
        if isinstance(delays, float):
            delays = [delays]
        assert len(sources) > 0
        for source in sources:
            if not isinstance(source, common.IDMixin):
                raise errors.ConnectionError("Invalid source ID: %s" % source)
        assert len(sources) == len(weights) == len(delays), "%s %s %s" % (len(sources), len(weights), len(delays))
        if common.is_conductance(target):
            weight_scale_factor = 1e-6  # Convert from µS to S
        else:
            weight_scale_factor = 1e-9  # Convert from nA to A

        synapse_type = self.syn_factory or "excitatory"
        if isinstance(synapse_type, basestring):
            syn_target_id = Projection.synapse_target_ids[synapse_type]
            syn_factory = pypcsim.SimpleScalingSpikingSynapse(syn_target_id, weights[0], delays[0])
        elif isinstance(synapse_type, pypcsim.SimObject):
            syn_factory = synapse_type
        else:
            raise errors.ConnectionError(
                "synapse_type must be a string or a PCSIM synapse factory. Actual type is %s" % type(synapse_type)
            )
        for source, weight, delay in zip(sources, weights, delays):
            syn_factory.W = weight * weight_scale_factor
            syn_factory.delay = delay * 0.001  # ms --> s
            try:
                c = simulator.net.connect(source, target, syn_factory)
            except RuntimeError, e:
                raise errors.ConnectionError(e)
            if target.local:
                self.connections.append(
                    simulator.Connection(source, target, simulator.net.object(c), 1.0 / weight_scale_factor)
                )
开发者ID:bernhardkaplan,项目名称:PyNN,代码行数:51,代码来源:__init__.py


示例14: __init__

 def __init__(self, weights=0.0, delays=None, space=Space(), safe=True, verbose=False):
     self.weights = weights
     self.space   = space
     self.safe    = safe
     self.verbose = verbose
     min_delay    = common.get_min_delay()
     if delays is None:
         self.delays = min_delay
     else:
         if core.is_listlike(delays):
             assert min(delays) >= min_delay
         elif not (isinstance(delays, basestring) or isinstance(delays, RandomDistribution)):
             assert delays >= min_delay
         self.delays = delays        
开发者ID:agravier,项目名称:pynn,代码行数:14,代码来源:connectors2.py


示例15: columns

 def columns(self):
     """
     For a 2D space, return a column-wise iterator over the parameter space.
     """
     if not self._evaluated:
         raise Exception("Must call evaluate() method before iterating over a ParameterSpace")
     for j in range(self._evaluated_shape[1]):
         D = {}
         for name, value in self._parameters.items():
             if is_listlike(value):
                 D[name] = value[:, j]
             else:
                 D[name] = value
             assert not isinstance(D[name], LazyArray) # should all have been evaluated by now
         yield D
开发者ID:jakobj,项目名称:PyNN,代码行数:15,代码来源:parameters.py


示例16: translate

 def translate(cls, parameters):
     """Translate standardized model parameters to simulator-specific parameters."""
     parameters = cls.check_parameters(parameters, with_defaults=False)
     native_parameters = {}
     for name in parameters:
         D = cls.translations[name]
         pname = D['translated_name']
         if is_listlike(cls.default_parameters[name]):
             parameters[name] = numpy.array(parameters[name])
         try:
             pval = eval(D['forward_transform'], globals(), parameters)
         except NameError, errmsg:
             raise NameError("Problem translating '%s' in %s. Transform: '%s'. Parameters: %s. %s" \
                             % (pname, cls.__name__, D['forward_transform'], parameters, errmsg))
         except ZeroDivisionError:
             raise
开发者ID:agravier,项目名称:pynn,代码行数:16,代码来源:__init__.py


示例17: set

    def set(self, name, value):
        """
        Set connection attributes for all connections in this Projection.

        `name`  -- attribute name
        `value` -- the attribute numeric value, or a list/1D array of such
                   values of the same length as the number of local connections,
                   or a 2D array with the same dimensions as the connectivity
                   matrix (as returned by `get(format='array')`).
        """
        for key in self._brian_connections.keys():
            bc = self._brian_connections[key]
            padding = 0
            if name == 'weight':
                M = bc.W
                units = bc.weight_units
            elif name == 'delay':
                M = bc.delay
                units = ms
            else:
                raise Exception("Setting parameters other than weight and delay not yet supported.")
            value = value*units
            if numpy.isscalar(value):
                if (name == 'weight') or (name == 'delay' and isinstance(bc, brian.DelayConnection)):
                    for row in xrange(M.shape[0]):
                        M.set_row(row, value)
                elif (name == 'delay' and isinstance(bc, brian.Connection)):
                    bc.delay = int(value / bc.source.clock.dt)
                else:
                    raise Exception("Setting a non appropriate parameter")
            elif isinstance(value, numpy.ndarray) and len(value.shape) == 2:
                if (name == 'delay') and not isinstance(bc, brian.DelayConnection):
                    raise Exception("FastConnector have been used, and only fixed homogeneous delays are allowed")
                address_gen = ((i, j) for i,row in enumerate(bc.W.rows) for j in row)
                for (i,j) in address_gen:
                    M[i,j] = value[i,j]
            elif core.is_listlike(value):
                N = M.getnnz()
                assert len(value[padding:padding+N]) == N
                if (name == 'delay') and not isinstance(bc, brian.DelayConnection):
                    raise Exception("FastConnector have been used: only fixed homogeneous delays are allowed")
                M.alldata[:] = value
            else:
                raise Exception("Values must be scalars or lists/arrays")
            padding += M.getnnz()
开发者ID:bernhardkaplan,项目名称:PyNN,代码行数:45,代码来源:__init__.py


示例18: _divergent_connect

 def _divergent_connect(self, source, targets, weights, delays):
     """
     Connect a neuron to one or more other neurons with a static connection.
     
     `source`  -- the ID of the pre-synaptic cell.
     `targets` -- a list/1D array of post-synaptic cell IDs, or a single ID.
     `weight`  -- a list/1D array of connection weights, or a single weight.
                  Must have the same length as `targets`.
     `delays`  -- a list/1D array of connection delays, or a single delay.
                  Must have the same length as `targets`.
     """
     if not isinstance(source, int) or source > simulator.state.gid_counter or source < 0:
         errmsg = "Invalid source ID: %s (gid_counter=%d)" % (source, simulator.state.gid_counter)
         raise errors.ConnectionError(errmsg)
     if not core.is_listlike(targets):
         targets = [targets]
     if isinstance(weights, float):
         weights = [weights]
     if isinstance(delays, float):
         delays = [delays]
     assert len(targets) > 0
     for target in targets:
         if not isinstance(target, common.IDMixin):
             raise errors.ConnectionError("Invalid target ID: %s" % target)
           
     assert len(targets) == len(weights) == len(delays), "%s %s %s" % (len(targets), len(weights), len(delays))
     self._resolve_synapse_type()
     for target, weight, delay in zip(targets, weights, delays):
         if target.local:
             if "." in self.synapse_type: 
                 section, synapse_type = self.synapse_type.split(".") 
                 synapse_object = getattr(getattr(target._cell, section), synapse_type) 
             else: 
                 synapse_object = getattr(target._cell, self.synapse_type) 
             nc = simulator.state.parallel_context.gid_connect(int(source), synapse_object)
             nc.weight[0] = weight
             
             # if we have a mechanism (e.g. from 9ML) that includes multiple
             # synaptic channels, need to set nc.weight[1] here
             if nc.wcnt() > 1 and hasattr(target._cell, "type"):
                 nc.weight[1] = target._cell.type.synapse_types.index(self.synapse_type)
             nc.delay  = delay
             # nc.threshold is supposed to be set by ParallelContext.threshold, called in _build_cell(), above, but this hasn't been tested
             self.connections.append(simulator.Connection(source, target, nc))
开发者ID:agravier,项目名称:pynn,代码行数:44,代码来源:__init__.py


示例19: connect

    def connect(self, source, targets, weights, delays):
        """
        Connect a neuron to one or more other neurons with a static connection.

        `source`  -- the ID of the pre-synaptic cell.
        `targets` -- a list/1D array of post-synaptic cell IDs, or a single ID.
        `weight`  -- a list/1D array of connection weights, or a single weight.
                     Must have the same length as `targets`.
        `delays`  -- a list/1D array of connection delays, or a single delay.
                     Must have the same length as `targets`.
        """
        if not isinstance(source, int) or source < 0:
            errmsg = "Invalid source ID: %s" % (source)
            raise errors.ConnectionError(errmsg)
        if not core.is_listlike(targets):
            targets = [targets]

        ##############weights = weights*1000.0 # scale units
        if isinstance(weights, float):
            weights = [weights]
        if isinstance(delays, float):
            delays = [delays]
        assert len(targets) > 0
        # need to scale weights for appropriate units
        for target, weight, delay in zip(targets, weights, delays):
            if target.local:
                if not isinstance(target, common.IDMixin):
                    raise errors.ConnectionError("Invalid target ID: %s" % target)
                #TODO record weights
                '''
                if self.synapse_type == "excitatory":
                    synapse_object = target._cell.esyn
                elif self.synapse_type == "inhibitory":
                    synapse_object = target._cell.isyn
                else:
                    synapse_object = getattr(target._cell, self.synapse_type)
                ###############source._cell.source.connect('event', synapse_object, 'synapse')
                synapse_object.n_incoming_connections += 1
                index = synapse_object.n_incoming_connections - 1
                synapse_object.setWeight(index, weight)
                synapse_object.setDelay(index, delay)'''
                index=0
                self.connections.append((source, target, index, weights, delays))
开发者ID:ChristophMetzner,项目名称:ROB-SS14-BachProj,代码行数:43,代码来源:neuroml2.py


示例20: _convergent_connect

 def _convergent_connect(self, sources, target, weights, delays):
     """
     Connect a neuron to one or more other neurons with a static connection.
     
     `sources`  -- a list/1D array of pre-synaptic cell IDs, or a single ID.
     `target` -- the ID of the post-synaptic cell.
     `weight`  -- a list/1D array of connection weights, or a single weight.
                  Must have the same length as `targets`.
     `delays`  -- a list/1D array of connection delays, or a single delay.
                  Must have the same length as `targets`.
     """
     if not isinstance(target, int) or target > simulator.state.gid_counter or target < 0:
         errmsg = "Invalid target ID: %s (gid_counter=%d)" % (target, simulator.state.gid_counter)
         raise errors.ConnectionError(errmsg)
     if not core.is_listlike(sources):
         sources = [sources]
     if isinstance(weights, float):
         weights = [weights]
     if isinstance(delays, float):
         delays = [delays]
     assert len(sources) > 0
     for source in sources:
         if not isinstance(source, common.IDMixin):
             raise errors.ConnectionError("Invalid source ID: %s" % source)
           
     assert len(sources) == len(weights) == len(delays), "%s %s %s" % (len(sources),len(weights),len(delays))
             
     if target.local:
         for source, weight, delay in zip(sources, weights, delays):
             if self.synapse_type is None:
                 self.synapse_type = weight >= 0 and 'excitatory' or 'inhibitory'
             if self.synapse_model == 'Tsodyks-Markram' and 'TM' not in self.synapse_type:
                 self.synapse_type += '_TM'
             synapse_object = getattr(target._cell, self.synapse_type)  
             nc = simulator.state.parallel_context.gid_connect(int(source), synapse_object)
             nc.weight[0] = weight
             nc.delay  = delay
             # nc.threshold is supposed to be set by ParallelContext.threshold, called in _build_cell(), above, but this hasn't been tested
             self.connections.append(simulator.Connection(source, target, nc))
开发者ID:agravier,项目名称:pynn,代码行数:39,代码来源:__init__.py



注:本文中的pyNN.core.is_listlike函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python brainscales.run函数代码示例发布时间:2022-05-25
下一篇:
Python dates.Date类代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap