| | 9 | import numpy |
|---|
| | 10 | |
|---|
| | 11 | |
|---|
| | 12 | class 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 | |
|---|
| | 75 | |
|---|
| | 76 | class 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 | |
|---|
| | 94 | class 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 |
|---|