def __init__(self, cset, weights=None, delays=None, safe=True, verbose=False): """ """ min_delay = common.get_min_delay() Connector.__init__(self, None, None, safe=safe, verbose=verbose) self.cset = cset if csa.arity(cset) == 0: #assert weights is not None and delays is not None, \ # 'must specify weights and delays in addition to a CSA mask' self.weights = weights if weights is None: self.weights = common.DEFAULT_WEIGHT self.delays = delays if delays is None: self.delays = common.get_min_delay() else: assert csa.arity( cset ) == 2, 'must specify mask or connection-set with arity 2' assert weights is None and delays is None, \ "weights or delays specified both in connection-set and as CSAConnector argument"
def __init__(self, cset, safe=True, callback=None): """ """ Connector.__init__(self, safe=safe, callback=callback) self.cset = cset if csa.arity(cset) == 0: pass else: assert csa.arity(cset) == 2, 'must specify mask or connection-set with arity 2'
def __init__(self, cset, safe=True, callback=None): """ """ Connector.__init__(self, safe=safe, callback=callback) self.cset = cset arity = csa.arity(cset) assert arity in (0, 2), 'must specify mask or connection-set with arity 0 or 2'
def connect(self, projection): """Connect-up a Projection.""" # Cut out finite part c = csa.cross((0, projection.pre.size - 1), (0, projection.post.size - 1)) * self.cset if csa.arity(self.cset) == 2: # Connection-set with arity 2 for (i, j, weight, delay) in c: projection.connection_manager.connect(projection.pre[i], [projection.post[j]], weight, delay) elif CSAConnector.isConstant (self.weights) \ and CSAConnector.isConstant (self.delays): # Mask with constant weights and delays for (i, j) in c: projection.connection_manager.connect(projection.pre[i], [projection.post[j]], self.weights, self.delays) else: # Mask with weights and/or delays iterable weights = self.weights if CSAConnector.isConstant(weights): weights = CSAConnector.constantIterator(weights) delays = self.delays if CSAConnector.isConstant(delays): delays = CSAConnector.constantIterator(delays) for (i, j), weight, delay in zip(c, weights, delays): projection.connection_manager.connect(projection.pre[i], [projection.post[j]], weight, delay)
def connect(self, projection): """Connect-up a Projection.""" if self.delays is None: self.delays = projection._simulator.state.min_delay # Cut out finite part c = csa.cross( (0, projection.pre.size - 1), (0, projection.post.size - 1)) * self.cset # can't we cut out just the columns we want? if csa.arity(self.cset) == 2: # Connection-set with arity 2 for (i, j, weight, delay) in c: projection._convergent_connect([projection.pre[i]], projection.post[j], weight, delay) elif CSAConnector.isConstant (self.weights) \ and CSAConnector.isConstant (self.delays): # Mask with constant weights and delays for (i, j) in c: projection._convergent_connect([projection.pre[i]], projection.post[j], self.weights, self.delays) else: # Mask with weights and/or delays iterable weights = self.weights if CSAConnector.isConstant(weights): weights = repeat(weights) delays = self.delays if CSAConnector.isConstant(delays): delays = repeat(delays) for (i, j), weight, delay in zip(c, weights, delays): projection._convergent_connect([projection.pre[i]], projection.post[j], weight, delay)
def connect(self, projection): """Connect-up a Projection.""" if self.delays is None: self.delays = projection._simulator.state.min_delay # Cut out finite part c = csa.cross((0, projection.pre.size-1), (0, projection.post.size-1)) * self.cset # can't we cut out just the columns we want? if csa.arity(self.cset) == 2: # Connection-set with arity 2 for (i, j, weight, delay) in c: projection._convergent_connect([projection.pre[i]], projection.post[j], weight, delay) elif CSAConnector.isConstant (self.weights) \ and CSAConnector.isConstant (self.delays): # Mask with constant weights and delays for (i, j) in c: projection._convergent_connect([projection.pre[i]], projection.post[j], self.weights, self.delays) else: # Mask with weights and/or delays iterable weights = self.weights if CSAConnector.isConstant(weights): weights = repeat(weights) delays = self.delays if CSAConnector.isConstant(delays): delays = repeat(delays) for (i, j), weight, delay in zip (c, weights, delays): projection._convergent_connect([projection.pre[i]], projection.post[j], weight, delay)
def __init__ (self, cset, weights=None, delays=None, safe=True, verbose=False): """ """ Connector.__init__(self, None, None, safe=safe, verbose=verbose) self.cset = cset if csa.arity(cset) == 0: #assert weights is not None and delays is not None, \ # 'must specify weights and delays in addition to a CSA mask' self.weights = weights if weights is None: self.weights = DEFAULT_WEIGHT self.delays = delays else: assert csa.arity(cset) == 2, 'must specify mask or connection-set with arity 2' assert weights is None and delays is None, \ "weights or delays specified both in connection-set and as CSAConnector argument"
def connect(self, projection): """Connect-up a Projection.""" # Cut out finite part c = csa.cross((0, projection.pre.size - 1), (0, projection.post.size - 1)) * self.cset # can't we cut out just the columns we want? if csa.arity(self.cset) == 2: # Connection-set with arity 2 for (i, j, weight, delay) in c: projection._convergent_connect([projection.pre[i]], projection.post[j], weight, delay) elif csa.arity(self.cset) == 0: # inefficient implementation as a starting point connection_map = numpy.zeros((projection.pre.size, projection.post.size), dtype=bool) for addr in c: connection_map[addr] = True self._connect_with_map(projection, LazyArray(connection_map)) else: raise NotImplementedError
def connect(self, projection): """Connect-up a Projection.""" if self.delays is None: self.delays = projection._simulator.state.min_delay def connect_csa(cset, pre, post, syn_type): print "connecting using cset" if isinstance(pre, Population) and isinstance(post, Population): # contiguous IDs, so just pass first_id and size nest.sli_func("Connect_cg_i_i_i_i_D_l", self.cset, pre.first_id, pre.size, post.first_id, post.size, {'weight': 0, 'delay': 1}, # ignored if arity==0 syn_type) else: # PopulationViews or Assemblies # IDs may be non-contiguous, so need to pass entire arrays nest.sli_func("Connect_cg_a_a_D_l", self.cset, pre.all_cells, post.all_cells, {'weight': 0, 'delay': 1}, # ignored if arity==0 syn_type) # TODO: fix weights units if csa.arity(self.cset) == 2: # Connection-set with arity 2 connect_csa(self.cset, projection.pre, projection.post, projection.synapse_model) elif CSAConnector.isConstant(self.weights) \ and CSAConnector.isConstant(self.delays): # Mask with constant weights and delays assert csa.arity(self.cset) == 0 nest.SetDefaults(projection.synapse_model, {'weight': self.weights, 'delay': self.delays}) connect_csa(self.cset, projection.pre, projection.post, projection.synapse_model) projection._sources = projection.pre.all_cells
def connect(self, projection): """Connect-up a Projection.""" presynaptic_cells = projection.pre.all_cells.astype('int64') postsynaptic_cells = projection.post.all_cells.astype('int64') if csa.arity(self.cset) == 2: param_map = {'weight': 0, 'delay': 1} nest.CGConnect(presynaptic_cells, postsynaptic_cells, self.cset, param_map, projection.nest_synapse_model) else: nest.CGConnect(presynaptic_cells, postsynaptic_cells, self.cset, model=projection.nest_synapse_model) projection._connections = None # reset the caching of the connection list, since this will have to be recalculated projection._sources.extend(presynaptic_cells)