Changeset 467
- Timestamp:
- 10/02/08 16:58:17 (2 months ago)
- Files:
-
- trunk/src/__init__.py (modified) (1 diff)
- trunk/src/pcsim/__init__.py (modified) (6 diffs)
- trunk/src/pcsim/connectors.py (modified) (2 diffs)
- trunk/test/unittests/pcsimtests_population.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/__init__.py
r466 r467 2 2 __all__ = ["common", "random", "nest1", "nest2", "neuron", "neuron2", "pcsim", 'brian' ] 3 3 4 # trunk/src/pcsim/__init__.py
r465 r467 997 997 998 998 weight = self.getWeight(weight) 999 is_conductance = hasattr(self.post.pcsim_population.object(0),'ErevExc')1000 if isinstance(weight, pyNN.random.RandomDistribution) :999 self.is_conductance = hasattr(self.post.pcsim_population.object(0),'ErevExc') 1000 if isinstance(weight, pyNN.random.RandomDistribution) or hasattr(weight, '__len__'): 1001 1001 w = 1. 1002 1002 else: 1003 w = self.convertWeight(weight, is_conductance)1003 w = self.convertWeight(weight, self.is_conductance) 1004 1004 1005 1005 delay = self.getDelay(delay) 1006 if isinstance(delay, pyNN.random.RandomDistribution) :1006 if isinstance(delay, pyNN.random.RandomDistribution) or hasattr(delay, '__len__'): 1007 1007 d = pcsim_globals.minDelay/1000. 1008 1008 else: … … 1033 1033 if isinstance(weight, pyNN.random.RandomDistribution): 1034 1034 self.randomizeWeights(weight) 1035 elif hasattr(weight, '__len__'): 1036 assert len(weight) == len(self), "Weight array does not have the same number of elements as the Projection %d != %d" % (len(weight),len(self)) 1037 self.setWeights(weight) 1035 1038 1036 1039 if isinstance(delay, pyNN.random.RandomDistribution): 1037 1040 self.randomizeDelays(delay) 1041 elif hasattr(delay, '__len__'): 1042 assert len(delay) == len(self), "Weight array does not have the same number of elements as the Projection %d != %d" % (len(weight),len(self)) 1043 self.setDelays(delay) 1038 1044 1039 1045 if not label: … … 1061 1067 synapses. 1062 1068 """ 1063 is_conductance = hasattr(self.post.pcsim_population.object(0),'ErevExc') 1064 w = self.convertWeight(w, is_conductance) 1069 w = self.convertWeight(w, self.is_conductance) 1065 1070 if isinstance(w, float) or isinstance(w, int): 1066 1071 for i in range(len(self)): … … 1077 1082 # argument type. It could make for easier-to-read simulation code to 1078 1083 # give it a separate name, though. Comments? 1079 is_conductance = hasattr(self.post.pcsim_population.object(0),'ErevExc') 1080 rand_distr = self.convertWeight(rand_distr, is_conductance) 1084 rand_distr = self.convertWeight(rand_distr, self.is_conductance) 1081 1085 weights = rand_distr.next(len(self)) 1082 1086 for i in range(len(self)): … … 1094 1098 pcsim_globals.net.object(self.pcsim_projection[i]).delay = d 1095 1099 else: 1100 assert 1000.0*min(d) >= pcsim_globals.minDelay, "Smallest delay %g ms must be smaller than %g ms" % (min(d), pcsim_globals.minDelay) 1096 1101 for i in range(len(self)): 1097 1102 pcsim_globals.net.object(self.pcsim_projection[i]).delay = d[i] … … 1105 1110 for i in range(len(self)): 1106 1111 pcsim_globals.net.object(self.pcsim_projection[i]).delay = delays[i] 1112 1113 def getWeights(self, format='list', gather=True): 1114 """ 1115 Possible formats are: a list of length equal to the number of connections 1116 in the projection, a 2D weight array (with zero or None for non-existent 1117 connections). 1118 """ 1119 if format == 'list': 1120 if self.is_conductance: 1121 A = 1e6 # S --> uS 1122 else: 1123 A = 1e9 # A --> nA 1124 return [A*self.pcsim_projection.object(i).W for i in xrange(self.pcsim_projection.size())] 1125 elif format == 'array': 1126 raise Exception("Not yet implemented") 1127 else: 1128 raise Exception("Valid formats are 'list' and 'array'") 1129 1130 def getDelays(self, format='list', gather=True): 1131 """ 1132 Possible formats are: a list of length equal to the number of connections 1133 in the projection, a 2D weight array (with zero or None for non-existent 1134 connections). 1135 """ 1136 if format == 'list': 1137 A = 1e3 # s --> ms 1138 return [A*self.pcsim_projection.object(i).delay for i in xrange(self.pcsim_projection.size())] 1139 elif format == 'array': 1140 raise Exception("Not yet implemented") 1141 else: 1142 raise Exception("Valid formats are 'list' and 'array'") 1107 1143 1108 1144 # --- Methods for writing/reading information to/from file. ---------------- trunk/src/pcsim/connectors.py
r466 r467 90 90 # pcsim does not yet deal with having lists of weights, delays, so for now we just return 0 values 91 91 # and will set the weights, delays later 92 return decider, wiring_method, 0.0, 0.092 return decider, wiring_method, self.weights, self.delays 93 93 94 94 class FromFileConnector(common.FromFileConnector): … … 114 114 # pcsim does not yet deal with having lists of weights, delays, so for now we just return 0 values 115 115 # and will set the weights, delays later 116 return decider, wiring_method, 0.0, 0.0116 return decider, wiring_method, self.weights, self.delays trunk/test/unittests/pcsimtests_population.py
r466 r467 16 16 import numpy.random 17 17 18 def arrays_almost_equal(a, b, threshold): 19 return (abs(a-b) < threshold).all() 20 21 def max_array_diff(a, b): 22 return max(abs(a-b)) 18 23 19 24 class PopulationInitTest(unittest.TestCase): … … 341 346 342 347 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 345 # 348 w = numpy.linspace(0.1,0.9,9) 349 prj1 = Projection(self.source33, self.target33, OneToOneConnector(weights=w)) 350 assert len(prj1) == self.source33.size 351 w_out = numpy.array(prj1.getWeights(format='list')) 352 assert arrays_almost_equal(w_out, w, 1e-7), "Max difference is %g" % max_array_diff(w_out,w) 353 354 def testWithDelayArray(self): 355 d = numpy.linspace(1.1,1.9,9) 356 prj1 = Projection(self.source33, self.target33, OneToOneConnector(delays=d)) 357 assert len(prj1) == self.source33.size 358 d_out = numpy.array(prj1.getDelays(format='list')) 359 assert arrays_almost_equal(d_out, d, 1e-7), "Max difference is %g" % max_array_diff(d_out,d) 360 346 361 # def testSaveAndLoad(self): 347 362 # prj1 = neuron.Projection(self.source33, self.target33, 'oneToOne')

