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
Exemple #2
0
    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")
Exemple #3
0
 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, 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()
Exemple #5
0
 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()