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, 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): if min(delays) < min_delay: raise errors.ConnectionError( "smallest delay (%g) is smaller than minimum delay (%g)" % (min(delays), min_delay)) elif not (isinstance(delays, basestring) or isinstance(delays, RandomDistribution)): if delays < min_delay: raise errors.ConnectionError( "delay (%g) is smaller than minimum delay (%g)" % (delays, min_delay)) self.delays = delays
def __init__(self, weights=0.0, delays=None): self.w_index = 0 # should probably use a generator self.d_index = 0 # rather than storing these values self.weights = weights self.delays = delays if delays is None: self.delays = common.get_min_delay()
def check(self, delay): all_negative = (delay <= self.max_delay).all() all_positive = (delay >= self.min_delay).all( ) # If the delay is too small , we have to throw an error if not (all_negative and all_positive): raise errors.ConnectionError( "delay (%s) is out of range [%s,%s]" % (delay, common.get_min_delay(), common.get_max_delay())) return delay
def __init__(self, filename, distributed=False, safe=True, verbose=False): """ Create a new connector. `filename` -- name of a text file containing a list of connections, in the format required by `FromListConnector`. `distributed` -- if this is True, then each node will read connections from a file called `filename.x`, where `x` is the MPI rank. This speeds up loading connections for distributed simulations. """ Connector.__init__(self, 0., common.get_min_delay(), safe=safe, verbose=verbose) self.filename = filename self.distributed = distributed
def __init__(self, conn_list, safe=True, verbose=False): """ Create a new connector. `conn_list` -- a list of tuples, one tuple for each connection. Each tuple should contain: (pre_addr, post_addr, weight, delay) where pre_addr is the address (a tuple) of the presynaptic neuron, and post_addr is the address of the postsynaptic neuron. """ # needs extending for dynamic synapses. Connector.__init__(self, 0., common.get_min_delay(), safe=safe, verbose=verbose) self.conn_list = conn_list
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
def __init__(self, conn_list, safe=True, verbose=False): """ Create a new connector. `conn_list` -- a list of tuples, one tuple for each connection. Each tuple should contain: (pre_idx, post_idx, weight, delay) where pre_idx is the index (i.e. order in the Population, not the ID) of the presynaptic neuron, and post_idx is the index of the postsynaptic neuron. """ # needs extending for dynamic synapses. Connector.__init__(self, 0., common.get_min_delay(), safe=safe, verbose=verbose) self.conn_list = numpy.array(conn_list)
def __init__(self, file, distributed=False, safe=True, verbose=False): """ Create a new connector. `file` -- file object containing a list of connections, in the format required by `FromListConnector`. `distributed` -- if this is True, then each node will read connections from a file called `filename.x`, where `x` is the MPI rank. This speeds up loading connections for distributed simulations. """ Connector.__init__(self, 0., common.get_min_delay(), safe=safe, verbose=verbose) if isinstance(file, basestring): file = files.StandardTextFile(file, mode='r') self.file = file self.distributed = distributed
def test_create_with_delays_None(self): connector = AllToAllConnector(weights=0.1, delays=None) self.assertEqual(connector.weights, 0.1) self.assertEqual(connector.delays, common.get_min_delay()) self.assert_(connector.safe) self.assert_(connector.allow_self_connections)
def connect(self, projection): """Connect-up a Projection.""" # Timers global rank timer0 = 0.0 timer1 = 0.0 timer2 = 0.0 timer3 = 0.0 timer4 = 0.0 # Recuperate variables # n = self.n dist_factor = self.dist_factor noise_factor = self.noise_factor # Do some checking # assert dist_factor >= 0 assert noise_factor >= 0 if isinstance(n, int): assert n >= 0 else: raise Exception("n must be an integer.") # Get posts and pres # listPostIDs = projection.post.local_cells listPreIDs = projection.pre.all_cells countPost = len(listPostIDs) countPre = len(listPreIDs) listPreIndexes = numpy.arange(countPre) listPostIndexes = map(projection.post.id_to_index, listPostIDs) # Prepare all distances # allDistances = self.space.distances(projection.post.positions, projection.pre.positions) # Get weights # weights = numpy.empty(n) weights[:] = self.weights is_conductance = common.is_conductance(projection.post[listPostIndexes[0]]) weights = common.check_weight(weights, projection.synapse_type, is_conductance) for i in xrange(len(listPostIDs)): currentPostIndex = listPostIndexes[i] currentPostID = listPostIDs[i] #currentPostIDAsList = [currentPostID] # Pick n neurons at random in pre population myTimer = time.time() chosenPresIndexes = list(numpy.random.permutation(numpy.arange(countPre))[0:n]) chosenPresIDs = list(projection.pre[chosenPresIndexes].all_cells) #if rank==0: # print(chosenPresIDs) #chosenPresIDs = chosenPresIDs.tolist() timer0 += time.time() - myTimer # Get distances myTimer = time.time() #distances = allDistances[currentPostIndex,chosenPresIndexes] distances = allDistances[currentPostIndex, chosenPresIndexes] timer1 += time.time() - myTimer # Generate gamme noise noise = numpy.random.gamma(1.0, noise_factor, n) # Create delays with distance and noise myTimer = time.time() delays = dist_factor * distances * (1.0 + noise) timer2 += time.time() - myTimer #delays[:] = 1.0 # Check for small and big delays myTimer = time.time() delaysClipped = numpy.clip(delays, common.get_min_delay(), common.get_max_delay()) howManyClipped = len((delays != delaysClipped).nonzero()[0]) if (howManyClipped > 1): print("Warning: %d of %d delays were cliped because they were either bigger than the max delay or lower than the min delay." % (howManyClipped, n)) delaysClipped = delaysClipped.tolist() timer3 += time.time() - myTimer # Connect everything up yTimer = time.time() projection._convergent_connect(chosenPresIDs, currentPostID, weights, delaysClipped) timer4 += time.time() - myTimer # Print timings if rank == 0: print("\033[2;46m" + ("Timer 0: %5.4f seconds" % timer0).ljust(60) + "\033[m") print("\033[2;46m" + ("Timer 1: %5.4f seconds" % timer1).ljust(60) + "\033[m") print("\033[2;46m" + ("Timer 2: %5.4f seconds" % timer2).ljust(60) + "\033[m") print("\033[2;46m" + ("Timer 3: %5.4f seconds" % timer3).ljust(60) + "\033[m") print("\033[2;46m" + ("Timer 4: %5.4f seconds" % timer4).ljust(60) + "\033[m")
def __init__(self, source, local_mask, safe=True): ConnectionAttributeGenerator.__init__(self, source, local_mask, safe) self.min_delay = common.get_min_delay() self.max_delay = common.get_max_delay()
def check(self, delay): all_negative = (delay<=self.max_delay).all() all_positive = (delay>=self.min_delay).all()# If the delay is too small , we have to throw an error if not (all_negative and all_positive): raise errors.ConnectionError("delay (%s) is out of range [%s,%s]" % (delay, common.get_min_delay(), common.get_max_delay())) return delay