Changeset 404

Show
Ignore:
Timestamp:
06/27/08 04:05:10 (5 months ago)
Author:
pierre
Message:

Continue the enhancement of the distantdependentConnectors. Almost finished, the speed up is amazing. Should think about adding a possibility to give a function for weights and delays

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/nest1/connectors.py

    r399 r404  
    106106            if isinstance(projection.rng, NativeRNG): 
    107107                print "Warning: use of NativeRNG not implemented. Using NumpyRNG" 
    108                 rarr = numpy.random.uniform(0,1,(projection.pre.size*projection.post.size,)) 
     108                rng = numpy.random 
    109109            else: 
    110                 rarr = projection.rng.uniform(0,1,(projection.pre.size*projection.post.size,)) 
     110                rng = projection.rng 
    111111        else: 
    112             rarr = numpy.random.uniform(0,1,(projection.pre.size*projection.post.size,)) 
    113         j = 0 
     112            rng = numpy.random 
    114113        for post in postsynaptic_neurons: 
    115             source_list=[] 
    116             idx_pre  = 0 
    117114            distances = common.distances(projection.pre, post, self.mask, self.scale_factor, self.offset, periodic_boundaries) 
    118115            func = eval("lambda d: %s" %self.d_expression) 
    119116            distances[:,0] = func(distances[:,0]) 
    120              
    121             for pre in presynaptic_neurons: 
    122                 if self.allow_self_connections or pre != post:  
    123                     # calculate the distance between the two cells : 
    124                     p = distances[idx_pre,0] 
    125                     if p >= 1 or (0 < p < 1 and rarr[j] < p): 
    126                         source_list.append(pre) 
    127                 j += 1 
    128                 idx_pre += 1 
     117            rarr = rng.uniform(0, 1, len(distances[:,0]),) 
     118            idx = numpy.where((distances[:,0] >= 1) | ((0 < distances[:,0]) & (distances[:,0] < 1) & (rarr < distances[:,0])))[0] 
     119            source_list = presynaptic_neurons[idx].tolist() 
     120            if self.allow_self_connections: 
     121                try: 
     122                    source_list.remove(post) 
     123                except Exception: 
     124                    pass 
     125            #for pre in presynaptic_neurons: 
     126                #if self.allow_self_connections or pre != post:  
     127                    ## calculate the distance between the two cells : 
     128                    #p = distances[idx_pre,0] 
     129                    #if p >= 1 or (0 < p < 1 and rarr[j] < p): 
     130                        #source_list.append(pre) 
     131                #j += 1 
     132                #idx_pre += 1 
    129133            N = len(source_list) 
    130134            weights = self.getWeights(N) 
  • trunk/src/nest2/connectors.py

    r399 r404  
    130130        else: 
    131131            rng = numpy.random 
    132         rarr = rng.uniform(0, 1, (projection.pre.size*projection.post.size,)) 
    133         j = 0 
    134         idx_post = 0 
    135132        for pre in presynaptic_neurons: 
    136             target_list = [] 
    137             idx_post = 0 
    138133            distances = common.distances(pre, projection.post, self.mask, 
    139134                                         self.scale_factor, self.offset, 
     
    141136            func = eval("lambda d: %s" %self.d_expression) 
    142137            distances[0] = func(distances[0]) 
    143             for post in postsynaptic_neurons: 
    144                 if self.allow_self_connections or pre != post:  
     138            rarr = rng.uniform(0, 1, len(distances[0,:]),) 
     139            idx = numpy.where((distances[0,:] >= 1) | ((0 < distances[0,:]) & (distances[0,:] < 1) & (rarr < distances[0,:])))[0] 
     140            target_list = postsynaptic_neurons[idx].tolist() 
     141            if self.allow_self_connections: 
     142                try: 
     143                    target_list.remove(pre) 
     144                except Exception: 
     145                    pass 
     146            #for post in postsynaptic_neurons: 
     147            #    if self.allow_self_connections or pre != post:  
    145148                    # calculate the distance between the two cells : 
    146                     p = distances[0,idx_post] 
    147                     if p >= 1 or (0 < p < 1 and rarr[j] < p): 
    148                         target_list.append(post) 
    149                 j += 1 
    150                 idx_post += 1 
     149            #        p = distances[0,idx_post] 
     150            #        if p >= 1 or (0 < p < 1 and rarr[j] < p): 
     151            #            target_list.append(post) 
     152            #    j += 1 
     153            #    idx_post += 1 
    151154            N = len(target_list) 
    152155            weights = self.getWeights(N)