Changeset 99
- Timestamp:
- 06/07/07 15:31:43 (1 year ago)
- Files:
-
- branches/improved-ID/common.py (modified) (1 diff)
- branches/improved-ID/nest.py (modified) (1 diff)
- branches/improved-ID/neuron.py (modified) (1 diff)
- branches/improved-ID/pcsim.py (modified) (7 diffs)
- branches/improved-ID/test/pcsimtests_population.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/improved-ID/common.py
r96 r99 37 37 class ID(int): 38 38 """ 39 This class is experimental. The idea is that instead of storing ids as40 integers, we store them as ID objects,which allows a syntax like:41 p[3,4].set('tau_m',20.0)39 Instead of storing ids as integers, we store them as ID objects, 40 which allows a syntax like: 41 p[3,4].tau_m = 20.0 42 42 where p is a Population object. The question is, how big a memory/performance 43 43 hit is it to replace integers with ID objects? branches/improved-ID/nest.py
r96 r99 27 27 class ID(common.ID): 28 28 """ 29 This class is experimental. The idea is that instead of storing ids as30 integers, we store them as ID objects,which allows a syntax like:31 p[3,4].set('tau_m',20.0)29 Instead of storing ids as integers, we store them as ID objects, 30 which allows a syntax like: 31 p[3,4].tau_m = 20.0 32 32 where p is a Population object. The question is, how big a memory/performance 33 33 hit is it to replace integers with ID objects? branches/improved-ID/neuron.py
r96 r99 33 33 class ID(common.ID): 34 34 """ 35 This class is experimental. The idea is that instead of storing ids as36 integers, we store them as ID objects,which allows a syntax like:37 p[3,4].set('tau_m',20.0)35 Instead of storing ids as integers, we store them as ID objects, 36 which allows a syntax like: 37 p[3,4].tau_m = 20.0 38 38 where p is a Population object. The question is, how big a memory/performance 39 39 hit is it to replace integers with ID objects? branches/improved-ID/pcsim.py
r86 r99 227 227 f.close() 228 228 229 class ID( common.ID):229 class ID(long): 230 230 """ 231 This class is experimental. The idea is that instead of storing ids as232 integers, we store them as ID objects,which allows a syntax like:233 p[3,4].set('tau_m',20.0)231 Instead of storing ids as integers, we store them as ID objects, 232 which allows a syntax like: 233 p[3,4].tau_m = 20.0 234 234 where p is a Population object. The question is, how big a memory/performance 235 235 hit is it to replace integers with ID objects? 236 """ 237 238 def set(self,param,val=None): 239 if hasattr(self,'in_population'): 240 set(self.in_population.pcsim_population[self],self._cellclass,param,val) 241 else: 242 set(self,self._cellclass,param,val) 243 244 def get(self,param): 245 raise Exception("Not yet implemented.") 246 # The following does no translation of names, units 236 """ 237 # Note that some of common.ID has to be reimplemented since PCSIM uses long ints 238 # for ids. 239 240 def __init__(self,n): 241 long.__init__(n) 242 self.parent = None 243 self._cellclass = None 244 245 cellclass = common.ID.cellclass 246 position = common.ID.position 247 248 def __setattr__(self,name,value): 249 if name in common.ID.non_parameter_attributes: 250 object.__setattr__(self,name,value) 251 else: 252 return self.setParameters(**{name:value}) 253 254 def __getattr__(self,name): 255 """Note that this currently does not translate units.""" 256 translated_name = self.cellclass.translations[name][0] 257 if self.parent: 258 return getattr(self.parent.pcsim_population.object(self), translated_name) 259 else: 260 return getattr(pcsim_globals.net.object(self), translated_name) 261 262 def setParameters(self,**parameters): 247 263 #if hasattr(self,'in_population'): 248 # return getattr(self.in_population.pcsim_population.object(self),param) # translation? 249 #else: 250 # raise getattr(pcsim_globals.net.object(self),param) 251 252 def setCellClass(self, cellclass): 253 self._cellclass = cellclass 264 if self.parent: 265 set(self.parent.pcsim_population[self], self.cellclass, parameters) 266 else: 267 set(self, self.cellclass, parameters) 268 269 def getParameters(self): 270 """Note that this currently does not translate units.""" 271 params = {} 272 for name in self.cellclass.translations.keys(): 273 params[name] = self.__getattr__(name) 274 return params 254 275 255 276 # ============================================================================== … … 532 553 else: 533 554 raise exceptions.AttributeError('Trying to create non-existent cellclass ' + cellclass.__name__ ) 534 cell_list = pcsim_globals.net.add(cellfactory, n) 555 cell_list = [ID(i) for i in pcsim_globals.net.add(cellfactory, n)] 556 #cell_list = pcsim_globals.net.add(cellfactory, n) 557 for id in cell_list: 558 id.cellclass = cellclass 535 559 if n == 1: 536 560 cell_list = cell_list[0] … … 704 728 raise exceptions.AttributeError('Trying to create non-existent cellclass ' + cellclass.__name__ ) 705 729 cellclass = eval(cellclass) 706 self.celltype = cellclass730 self.celltype = cellclass 707 731 if issubclass(cellclass, common.StandardCellType): 708 self.cellfactory = cellclass(cellparams).simObjFactory 709 else: 732 self.celltype = cellclass(cellparams) 733 self.cellfactory = self.celltype.simObjFactory 734 else: 735 self.celltype = cellclass 710 736 if issubclass(cellclass, SimObject): 711 737 self.cellfactory = apply(cellclass, (), cellparams) … … 716 742 # CuboidGridPopulation(SimNetwork &net, GridPoint3D origin, Volume3DSize dims, SimObjectFactory &objFactory) 717 743 self.pcsim_population = CuboidGridObjectPopulation(pcsim_globals.net, GridPoint3D(0,0,0), Volume3DSize(dims[0], dims[1], dims[2]), self.cellfactory) 744 self.cell = numpy.array(self.pcsim_population.idVector()) 745 self.cell -= self.cell[0] 718 746 719 747 if not self.label: … … 743 771 assert index == pcsim_index, " index = %s, pcsim_index = %s" % (index, pcsim_index) 744 772 id = ID(pcsim_index) 745 id.setCellClass(self.celltype) 746 id.in_population = self 773 id.parent = self 747 774 if orig_addr != self.locate(id): 748 775 raise IndexError, 'Invalid cell address %s' % str(addr) … … 830 857 """PCSIM: iteration through all elements """ 831 858 paramDict = checkParams(param, val) 832 if is subclass(self.celltype, common.StandardCellType):833 paramDict = self.celltype ({}).translate(paramDict)859 if isinstance(self.celltype, common.StandardCellType): 860 paramDict = self.celltype.translate(paramDict) 834 861 835 862 for index in range(0,len(self)): … … 849 876 values = numpy.copy(valueArray) # we do not wish to change the original valueArray in case it needs to be reused in user code 850 877 values = numpy.reshape(values, values.size) 851 if is subclass(self.celltype, common.StandardCellType):878 if isinstance(self.celltype, common.StandardCellType): 852 879 try: 853 unit_scale_factor = self.celltype ({}).translate({parametername: values[0]}).values()[0]/values[0]880 unit_scale_factor = self.celltype.translate({parametername: values[0]}).values()[0]/values[0] 854 881 except TypeError: 855 882 raise common.InvalidParameterValueError(values[0]) 856 parametername = self.celltype ({}).translate({parametername: values[0]}).keys()[0]883 parametername = self.celltype.translate({parametername: values[0]}).keys()[0] 857 884 values *= unit_scale_factor 858 885 for i, val in enumerate(values): branches/improved-ID/test/pcsimtests_population.py
r86 r99 400 400 401 401 402 # #class ProjectionConnectionTest(unittest.TestCase):403 # # """Tests of the connection attribute and connections() method of the Projection class."""404 # #405 # # def setUp(self):406 # # neuron.Population.nPop = 0407 # # self.pop1 = neuron.Population((5,),neuron.IF_curr_alpha)408 # # self.pop2 = neuron.Population((4,4),neuron.IF_curr_alpha)409 # # self.pop3 = neuron.Population((3,3,3),neuron.IF_curr_alpha)410 # # self.prj23 = neuron.Projection(self.pop2,self.pop3,"allToAll")411 # # self.prj11 = neuron.Projection(self.pop1,self.pop1,"fixedProbability",0.5)412 # #413 # # def testFullAddress(self):414 # # assert self.prj23.connection[(3,1),(2,0,1)] == "[3][1][2][0][1]"415 # # assert self.prj23.connection[(3,3),(2,2,2)] == "[3][3][2][2][2]"416 # #417 # # def testPreIDPostID(self):418 # # assert self.prj23.connection[0,0] == "[0][0][0][0][0]"419 # # assert self.prj23.connection[0,26] == "[0][0][2][2][2]"420 # # assert self.prj23.connection[0,25] == "[0][0][2][2][1]"421 # # assert self.prj23.connection[15,0] == "[3][3][0][0][0]"422 # # assert self.prj23.connection[14,0] == "[3][2][0][0][0]"423 # # assert self.prj23.connection[13,19] == "[3][1][2][0][1]"424 # #425 # # def testSingleID(self):426 # # assert self.prj23.connection[0] == "[0][0][0][0][0]"427 # # assert self.prj23.connection[26] == "[0][0][2][2][2]"428 # # assert self.prj23.connection[25] == "[0][0][2][2][1]"429 # # assert self.prj23.connection[27] == "[0][1][0][0][0]"430 # # assert self.prj23.connection[53] == "[0][1][2][2][2]"431 # # assert self.prj23.connection[52] == "[0][1][2][2][1]"432 # # assert self.prj23.connection[431] == "[3][3][2][2][2]"433 # # assert self.prj23.connection[377] == "[3][1][2][2][2]"434 # # assert self.prj23.connection[370] == "[3][1][2][0][1]"435 # #436 # # assert self.prj11.connection[0] == "[0][0]"437 438 439 402 class IDTest(unittest.TestCase): 440 403 """Tests of the ID class.""" … … 442 405 def setUp(self): 443 406 setup(max_delay=0.5) 444 self.pop = Population((5,), IF_curr_alpha,{'tau_m':10.0}) 445 446 def testIDSet(self): 447 self.pop[3].set('tau_m',20.0) 448 self.assertAlmostEqual( self.pop.pcsim_population.object(self.pop[3]).taum, 0.02, places = 5) 449 self.assertAlmostEqual( self.pop.pcsim_population.object(self.pop[1]).taum, 0.01, places = 5) 407 self.pop1 = Population((5,), IF_curr_alpha,{'tau_m':10.0}) 408 self.pop2 = Population((5,4), IF_curr_exp,{'v_reset':-60.0}) 409 410 def testIDSetAndGet(self): 411 self.pop1[3].tau_m = 20.0 412 self.pop2[3,2].v_reset = -70.0 413 self.assertAlmostEqual( self.pop1.pcsim_population.object(self.pop1[3]).taum, 0.02, places = 5) 414 self.assertAlmostEqual(0.02, self.pop1[3].tau_m, places = 5) 415 self.assertAlmostEqual(0.01, self.pop1[0].tau_m, places = 5) 416 self.assertAlmostEqual(-0.07, self.pop2[3,2].v_reset, places = 5) 417 self.assertAlmostEqual(-0.06, self.pop2[0,0].v_reset, places = 5) 418 419 def testGetCellClass(self): 420 self.assertEqual(IF_curr_alpha, self.pop1[0].cellclass) 421 self.assertEqual(IF_curr_exp, self.pop2[4,3].cellclass) 422 423 def testSetAndGetPosition(self): 424 self.assert_((self.pop2[0,2].position == (0.0,2.0,0.0)).all()) 425 new_pos = (0.5,1.5,0.0) 426 self.pop2[0,2].position = new_pos 427 self.assert_((self.pop2[0,2].position == (0.5,1.5,0.0)).all()) 428 new_pos = (-0.6,3.5,-100.0) # check that position is set-by-value from new_pos 429 self.assert_((self.pop2[0,2].position == (0.5,1.5,0.0)).all()) 450 430 451 431 # ==============================================================================

