Changeset 466

Show
Ignore:
Timestamp:
10/02/08 13:25:24 (2 months ago)
Author:
apdavison
Message:

Partial implementation of FromListConnector and FromFileConnector for pcsim (see ticket:30). They do not properly handle weights/delays, but then none of the other pcsim Connectors do either (see ticket:116).

Files:

Legend:

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

    r465 r466  
    22__all__ = ["common", "random", "nest1", "nest2", "neuron", "neuron2", "pcsim", 'brian' ] 
    33 
    4 # 
  • trunk/src/pcsim/connectors.py

    r281 r466  
    77from pypcsim import * 
    88from pyNN.pcsim.pcsim_globals import pcsim_globals 
     9import numpy 
     10 
     11 
     12class ListConnectionPredicate(PyConnectionDecisionPredicate): 
     13    """Used by FromListConnector and FromFileConnector.""" 
     14     
     15    def __init__(self, conn_array): 
     16        PyConnectionDecisionPredicate.__init__(self) 
     17        # now need to turn conn_list into a form suitable for use by decide() 
     18        # a sparse array would be one possibility, but for now we use a dict of dicts 
     19        self._connections = {} 
     20        for i in xrange(len(conn_array)): 
     21            src, tgt = conn_array[i][:] 
     22            if src not in self._connections: 
     23                self._connections[src] = [] 
     24            self._connections[src].append(tgt)  
     25     
     26    def decide(self, src, tgt, rng): 
     27        if src in self._connections and tgt in self._connections[src]: 
     28            return True 
     29        else: 
     30            return False 
     31 
    932 
    1033class AllToAllConnector(common.AllToAllConnector):     
     
    5073        wiring_method = SimpleAllToAllWiringMethod(pcsim_globals.net) 
    5174        return decider, wiring_method, self.weights, self.delays 
     75     
     76class FromListConnector(common.FromListConnector): 
     77     
     78    def connect(self, projection): 
     79        conn_array = numpy.zeros((len(self.conn_list),4)) 
     80        for i in xrange(len(self.conn_list)): 
     81            src, tgt, weight, delay = self.conn_list[i][:] 
     82            src = projection.pre[tuple(src)] 
     83            tgt = projection.post[tuple(tgt)] 
     84            conn_array[i,:] = (src, tgt, weight, delay) 
     85        self.weights = conn_array[:,2] 
     86        self.delays = conn_array[:,3] 
     87        lcp = ListConnectionPredicate(conn_array[:,0:2]) 
     88        decider = PredicateBasedConnections(lcp) 
     89        wiring_method = SimpleAllToAllWiringMethod(pcsim_globals.net) 
     90        # pcsim does not yet deal with having lists of weights, delays, so for now we just return 0 values 
     91        # and will set the weights, delays later 
     92        return decider, wiring_method, 0.0, 0.0 
     93 
     94class FromFileConnector(common.FromFileConnector): 
     95     
     96    def connect(self, projection): 
     97        f = open(self.filename, 'r', 10000) 
     98        lines = f.readlines() 
     99        f.close() 
     100        conn_array = numpy.zeros((len(lines),4)) 
     101        for i,line in enumerate(lines): 
     102            single_line = line.rstrip() 
     103            src, tgt, w, d = single_line.split("\t", 4) 
     104            src = "[%s" % src.split("[",1)[1] 
     105            tgt = "[%s" % tgt.split("[",1)[1] 
     106            src = projection.pre[tuple(eval(src))] 
     107            tgt = projection.post[tuple(eval(tgt))] 
     108            conn_array[i,:] = (src, tgt, w, d) 
     109        self.weights = conn_array[:,2] 
     110        self.delays = conn_array[:,3] 
     111        lcp = ListConnectionPredicate(conn_array[:,0:2]) 
     112        decider = PredicateBasedConnections(lcp) 
     113        wiring_method = SimpleAllToAllWiringMethod(pcsim_globals.net) 
     114        # pcsim does not yet deal with having lists of weights, delays, so for now we just return 0 values 
     115        # and will set the weights, delays later 
     116        return decider, wiring_method, 0.0, 0.0 
  • trunk/test/unittests/pcsimtests_population.py

    r393 r466  
    333333        assert (0 < len(prj1) < len(self.source33)*len(self.target33)) and (0 < len(prj2) < len(self.source33)*len(self.target33)) 
    334334 
     335    def testFromList(self): 
     336        list_22_33 = [([0,0], [0,2], 0.2, 0.3), 
     337                      ([1,0], [2,2], 0.3, 0.4), 
     338                      ([1,0], [1,0], 0.4, 0.5)] 
     339        prj1 = Projection(self.source22, self.target33, FromListConnector(list_22_33)) 
     340        assert len(prj1) == len(list_22_33) 
     341         
     342    def testWithWeightArray(self): 
     343        prj2 = Projection(self.source33, self.target33, OneToOneConnector(weights=numpy.linspace(0.1,0.9,9))) 
     344        assert len(prj1) == self.source33.size # just check there are no Exceptions raised for now. Need also to check weights are properly set 
    335345#          
    336346#     def testSaveAndLoad(self):