Changeset 725
- Timestamp:
- 03/10/10 11:16:33 (2 years ago)
- Location:
- trunk
- Files:
-
- 3 modified
-
src/connectors.py (modified) (9 diffs)
-
src/nest/simulator.py (modified) (1 diff)
-
test/unittests/generictests.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/connectors.py
r722 r725 19 19 from numpy import arccos, arcsin, arctan, arctan2, ceil, cos, cosh, e, exp, \ 20 20 fabs, floor, fmod, hypot, ldexp, log, log10, modf, pi, power, \ 21 sin, sinh, sqrt, tan, tanh 21 sin, sinh, sqrt, tan, tanh, maximum, minimum 22 22 from pyNN import random, common, errors, core 23 23 from pyNN.space import Space … … 58 58 """Base class for Connector classes.""" 59 59 60 def __init__(self, weights=0.0, delays=None ):60 def __init__(self, weights=0.0, delays=None, space=None): 61 61 self.w_index = 0 # should probably use a generator 62 62 self.d_index = 0 # rather than storing these values … … 71 71 else: 72 72 self.delays = delays 73 74 73 if delays is None: 75 74 self.delays = common.get_min_delay() 75 if space is not None: 76 assert isinstance(space, Space) 77 self.space = space 76 78 77 79 def connect(self, projection): … … 95 97 return delays 96 98 99 def reset(self): 100 """ 101 After running connect(), this should be called to reset attributes that 102 have been modified to their initial values. 103 """ 104 if hasattr(self, "w_expr"): 105 self.weights = numpy.empty((1,0)) 106 if hasattr(self, "d_expr"): 107 self.delays = numpy.empty((1,0)) 108 self.w_index = 0 # should probably use a generator 109 self.d_index = 0 # rather than storing these values 110 97 111 98 112 class ProbabilisticConnector(Connector): … … 147 161 if len(targets) > 0: 148 162 projection.connection_manager.connect(src, targets, weights, delays) 149 163 self.reset() 150 164 151 165 class AllToAllConnector(ProbabilisticConnector): … … 169 183 to the global minimum delay. 170 184 """ 171 Connector.__init__(self, weights, delays )185 Connector.__init__(self, weights, delays, space) 172 186 assert isinstance(allow_self_connections, bool) 173 187 self.allow_self_connections = allow_self_connections … … 479 493 to the global minimum delay. 480 494 """ 481 Connector.__init__(self, weights, delays )495 Connector.__init__(self, weights, delays, space) 482 496 assert isinstance(allow_self_connections, bool) 483 497 self.allow_self_connections = allow_self_connections … … 521 535 to the global minimum delay. 522 536 """ 523 Connector.__init__(self, weights, delays )537 Connector.__init__(self, weights, delays, space) 524 538 assert isinstance(d_expression, str) 525 539 try: … … 529 543 raise ZeroDivisionError("Error in the distance expression %s. %s" % (d_expression, err)) 530 544 self.d_expression = d_expression 531 self.space = space532 545 assert isinstance(allow_self_connections, bool) 533 546 self.allow_self_connections = allow_self_connections 534 assert isinstance(space, Space)535 self.space = space536 547 537 548 -
trunk/src/nest/simulator.py
r718 r725 219 219 """The ID of the post-synaptic neuron.""" 220 220 tgt = ID(nest.GetStatus([self.id()], 'target')[0]) 221 tgt.parent = self.parent.parent.p re221 tgt.parent = self.parent.parent.post 222 222 tgt.local = nest.GetStatus([tgt], 'local')[0] 223 223 return tgt -
trunk/test/unittests/generictests.py
r720 r725 9 9 import os 10 10 import cPickle as pickle 11 from pyNN import common, random, utility, recording, errors 11 from pyNN import common, random, utility, recording, errors, space 12 12 import glob 13 13 … … 873 873 self.assertAlmostEqual(prj1.connections[0].delay, 0.4, 6) # nest rounds delays to the timestep 874 874 875 def testDistanceDependentWeights(self): 876 connectors = ( 877 sim.AllToAllConnector(weights="exp(-d/10.0)", space=space.Space(scale_factor=0.9)), 878 sim.FixedProbabilityConnector(0.8, weights="maximum(3-d, 0)", space=space.Space(offset=0.1)), 879 sim.DistanceDependentProbabilityConnector("abs(d<3)", weights="sin(d)", space=space.Space(offset=0.1, 880 scale_factor=0.9)), 881 ) 882 exp = numpy.exp 883 maximum = numpy.maximum 884 sin = numpy.sin 885 for srcP in [self.source5, self.source22]: 886 for tgtP in [self.target6, self.target33]: 887 for conn in connectors: 888 print conn.w_expr 889 prj = sim.Projection(srcP, tgtP, conn) 890 first_connection = prj.connections[0] 891 last_connection = prj.connections[-1] 892 for c in first_connection, last_connection: 893 d = space.distance(c.source, c.target) 894 self.assertAlmostEqual(c.weight, eval(conn.w_expr), 10) 875 895 876 896 class ProjectionSetTest(unittest.TestCase):
