Changeset 414
- Timestamp:
- 07/16/08 09:47:16 (1 month ago)
- Files:
-
- trunk/src/brian/__init__.py (modified) (2 diffs)
- trunk/src/common.py (modified) (8 diffs)
- trunk/src/nest1/__init__.py (modified) (2 diffs)
- trunk/src/nest2/__init__.py (modified) (7 diffs)
- trunk/src/neuron/__init__.py (modified) (4 diffs)
- trunk/src/neuron2/__init__.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/brian/__init__.py
r342 r414 532 532 f.close() 533 533 pass 534 535 def describe(self):536 """537 Returns a human readable description of the population538 """539 pass540 541 542 534 543 535 … … 750 742 # should be put here or in an external module. 751 743 raise Exception("Method not yet implemented") 752 753 def describe(self): 754 """ 755 Return a human readable description of the projection 756 """ 757 pass 744 758 745 759 746 # ============================================================================== trunk/src/common.py
r413 r414 11 11 from math import * 12 12 from pyNN import random 13 from string import Template 13 14 14 15 DEFAULT_WEIGHT = 0.0 … … 367 368 return [name for name in cls.translations if name not in cls.simple_parameters()+cls.scaled_parameters()] 368 369 369 370 370 def update_parameters(self, parameters): 371 371 """ … … 374 374 self.parameters.update(self.translate(parameters)) 375 375 376 def describe(self, template='standard'): 377 return str(self) 378 376 379 377 380 class StandardCellType(StandardModelType): … … 935 938 return _abstract_method(self) 936 939 937 def describe(self ):940 def describe(self, template='standard'): 938 941 """ 939 942 Returns a human readable description of the population 940 943 """ 941 return _abstract_method(self) 944 if template == 'standard': 945 #lines = ['==== Population $label ====', 946 # ' Dimensions: $dim', 947 # ' Local cells: $n_cells_local', 948 # ' Cell type: $celltype', 949 # ' ID range: $first_id-$last_id', 950 # ' First cell on this node:', 951 # ' ID: $local_first_id', 952 # ' Parameters: $cell_parameters'] 953 lines = ['------- Population description -------', 954 'Population called $label is made of $n_cells cells [$n_cells_local being local]'] 955 if self.parent: 956 lines += ['This population is a subpopulation of population $parent_label'] 957 lines += ["-> Cells are aranged on a ${ndim}D grid of size $dim", 958 "-> Celltype is $celltype", 959 "-> ID range is $first_id-$last_id", 960 "-> Cell Parameters used for cell[0] are: "] 961 for name, value in self.index(0).get_parameters().items(): 962 lines += [" | %-12s: %s" % (name, value)] 963 lines += ["--- End of Population description ----"] 964 template = "\n".join(lines) 965 966 context = self.__dict__.copy() 967 first_id = self._local_ids[0] 968 context.update(local_first_id=first_id) 969 context.update(cell_parameters=first_id.get_parameters()) 970 context.update(celltype=self.celltype.__class__.__name__) 971 context.update(n_cells=len(self)) 972 context.update(n_cells_local=len(self._local_ids)) 973 for k in context.keys(): 974 if k[0] == '_': 975 context.pop(k) 976 977 if template == None: 978 return context 979 else: 980 return Template(template).substitute(context) 942 981 943 982 def getSubPopulation(self, cells): … … 999 1038 self.label = label 1000 1039 self.rng = rng 1040 self._method = method 1001 1041 self.synapse_dynamics = synapse_dynamics 1002 1042 self.connection = None # access individual connections. To be defined by child, simulator-specific classes … … 1224 1264 return _abstract_method(self) 1225 1265 1226 def describe(self ):1266 def describe(self, template='standard'): 1227 1267 """ 1228 1268 Returns a human readable description of the projection 1229 1269 """ 1230 return _abstract_method(self) 1270 if template == 'standard': 1271 lines = ["------- Projection description -------", 1272 "Projection $label from $pre_label [$pre_n_cells cells] to $post_label [$post_n_cells cells]", 1273 " | Connector : $_method", 1274 " | Weights : $weights", 1275 " | Delays : $delays", 1276 " | Plasticity : $plasticity", 1277 " | Num. connections : $nconn", 1278 ] 1279 lines += ["---- End of Projection description -----"] 1280 template = '\n'.join(lines) 1281 1282 context = self.__dict__.copy() 1283 context.update({ 1284 'nconn': len(self), 1285 'pre_label': self.pre.label, 1286 'post_label': self.post.label, 1287 'pre_n_cells': self.pre.size, 1288 'post_n_cells': self.post.size, 1289 'weights': str(self._method.weights), 1290 'delays': str(self._method.delays), 1291 }) 1292 if self.synapse_dynamics: 1293 context.update(plasticity=self.synapse_dynamics.describe()) 1294 else: 1295 context.update(plasticity='None') 1296 1297 if template == None: 1298 return context 1299 else: 1300 return Template(template).substitute(context) 1231 1301 1232 1302 … … 1278 1348 else: 1279 1349 raise Exception("delays is of type %s" % type(self.delays)) 1280 if self.check_connections:1281 assert numpy.all(delays >= get_min_delay()), \1282 "Delay values must be greater than or equal to the minimum delay %g. The smallest delay is %g." % (get_min_delay(), delays.min())1283 assert numpy.all(delays <= get_max_delay()), \1284 "Delay values must be less than or equal to the maximum delay %s. The largest delay is %s" % (get_max_delay(), delays.max())1350 if self.check_connections: 1351 assert numpy.all(delays >= get_min_delay()), \ 1352 "Delay values must be greater than or equal to the minimum delay %g. The smallest delay is %g." % (get_min_delay(), delays.min()) 1353 assert numpy.all(delays <= get_max_delay()), \ 1354 "Delay values must be less than or equal to the maximum delay %s. The largest delay is %s" % (get_max_delay(), delays.max()) 1285 1355 self.d_index += N 1286 1356 return delays … … 1447 1517 self.fast = fast 1448 1518 self.slow = slow 1449 1450 1519 1520 def describe(self, template='standard'): 1521 if template == 'standard': 1522 lines = ["Short-term plasticity mechanism: $slow", 1523 "Long-term plasticity mechanism: $fast"] 1524 template = "\n".join(lines) 1525 context = {'fast': self.fast.describe(), 1526 'slow': self.slow.describe()} 1527 if template == None: 1528 return context 1529 else: 1530 return Template(template).substitute(context) 1531 1532 1451 1533 class ShortTermPlasticityMechanism(StandardModelType): 1452 1534 """Abstract base class for models of short-term synaptic dynamics.""" trunk/src/nest1/__init__.py
r408 r414 817 817 os.system("rm %s" %tmpfile) 818 818 result.close() 819 820 def describe(self): 821 """ 822 Returns a human readable description of the population 823 """ 824 print "\n------- Population description -------" 825 print "Population called %s is made of %d cells" %(self.label, len(self.cell.flatten())) 826 print "-> Cells are aranged on a %dD grid of size %s" %(len(self.dim), self.dim) 827 print "-> Celltype is %s" %self.celltype 828 print "-> Cell Parameters used for cell[0] (during initialization and now) are: " 829 for key, value in self.cellparams.items(): 830 print "\t|", key, "\t: ", "init->", value, "\t now->", pynest.getDict([self.cell.flatten()[0]])[0][key] 831 print "--- End of Population description ----" 832 833 819 834 820 835 821 … … 1256 1242 # should be put here or in an external module. 1257 1243 raise Exception("Method not yet implemented") 1258 1259 def describe(self): 1260 """ 1261 Return a human readable description of the projection 1262 """ 1263 print "\n------- Projection description -------" 1264 print "Projection %s from %s [%d cells] to %s [%d cells]" %(self.label, self.pre.label, len(self.pre.cell),self.post.label, len(self.post.cell)) 1265 print "\t| Connector : " %self._method 1266 if isinstance(self._method.weights,RandomDistribution): 1267 print "\t| Weights : drawn from %s distribution with params %s "%(self._method.weights.name, self._method.weights.parameters) 1268 else: 1269 print "\t| Weights : ", self._method.weights 1270 if isinstance(self._method.delays,RandomDistribution): 1271 print "\t| Delays : drawn from %s distribution with params %s " %(self._method.delays.name, self._method.delays.parameters) 1272 else: 1273 print "\t| Delays : ", self._method.delays 1274 print "\t| Plasticity : ", self._plasticity_model 1275 print "\t --> %d connections have been created for this projection" %len(self) 1276 print "\tParameters of connection from %d to %d" %(self._sources[0], self._targets[0]) 1277 print "\t| weights : ", pynest.getWeight([self._sources[0]],self._targetPorts[0]) 1278 print "\t| delays : ", pynest.getDelay([self._sources[0]], self._targetPorts[0]) 1279 1280 print "---- End of Projection description -----" 1244 1281 1245 1282 1246 # ============================================================================== trunk/src/nest2/__init__.py
r413 r414 585 585 self.cell = numpy.array([ ID(GID) for GID in self.cell ], ID) 586 586 self.cell_local = self.cell[numpy.array(nest.GetStatus(self.cell.tolist(),'local'))] 587 self.first_id = self.cell.reshape(self.size,)[0] 587 self.first_id = self.cell.flatten()[0] 588 self.last_id = self.cell.flatten()[-1] 588 589 for id in self.cell: 589 590 id.parent = self … … 593 594 if self.cellparams: 594 595 nest.SetStatus(self.cell_local, [self.cellparams]) 596 self._local_ids = self.cell_local 595 597 596 598 if not self.label: … … 951 953 return pop 952 954 953 def describe(self):954 """955 Return a human readable description of the population956 """957 print "\n------- Population description -------"958 print "Population called %s is made of %d cells [%d being local]" %(self.label, len(self.cell.flatten()), len(self.cell_local))959 if self.parent:960 print "This population is a subpopulation of population %s" %self.parent.label961 print "-> Cells are aranged on a %dD grid of size %s" %(len(self.dim), self.dim)962 print "-> Celltype is %s" %self.celltype963 print "-> Cell Parameters used for cell[0] (during initialization and now) are: "964 for key, value in self.cellparams.items():965 print "\t|", key, "\t: ", "init->", value, "\t now->", nest.GetStatus([self.cell.flatten()[0]])[0][key]966 print "--- End of Population description ----"967 968 955 969 956 class Projection(common.Projection): … … 1024 1011 self._sources = [] # holds gids 1025 1012 self.synapse_type = target 1026 self._method = method1027 1013 1028 1014 if synapse_dynamics and synapse_dynamics.fast and synapse_dynamics.slow: … … 1368 1354 f.close() 1369 1355 1370 1371 1356 def weightHistogram(self, min=None, max=None, nbins=10): 1372 1357 """ … … 1380 1365 return numpy.histogram(self.getWeights(format='list', gather=True), bins) # returns n, bins 1381 1366 1382 def describe(self): 1383 """ 1384 Return a human readable description of the projection 1385 """ 1386 print "\n------- Projection description -------" 1387 print "Projection %s from %s [%d cells] to %s [%d cells]" %(self.label, self.pre.label, len(self.pre.cell),self.post.label, len(self.post.cell)) 1388 print "\t| Connector : %s" %self._method 1389 if isinstance(self._method.weights,RandomDistribution): 1390 print "\t| Weights : drawn from %s distribution with params %s "%(self._method.weights.name, self._method.weights.parameters) 1391 else: 1392 print "\t| Weights : ", self._method.weights 1393 if isinstance(self._method.delays,RandomDistribution): 1394 print "\t| Delays : drawn from %s distribution with params %s " %(self._method.delays.name, self._method.delays.parameters) 1395 else: 1396 print "\t| Delays: ", self._method.delays 1397 print "\t| Plasticity : ", self._plasticity_model 1398 print "\t ----> %d connections have been created for this projection" %len(self) 1399 print "\tParameters of connection from %d to %d [port %d]" %(self._sources[0], self._targets[0], self._target_ports[0]) 1367 def describe(self, template='standard'): 1368 """ 1369 Returns a human readable description of the projection 1370 """ 1371 description = common.Projection.describe(self, template) 1372 description += "\n Parameters of connection from %d to %d [port %d]" % (self._sources[0], self._targets[0], self._target_ports[0]) 1400 1373 dict = nest.GetConnections([self.pre.cell.flat[0]], self._plasticity_model)[0] 1401 1374 for i in xrange(len(self._targets)): … … 1403 1376 if len(idx) > 0: 1404 1377 for key, value in dict.items(): 1405 print "\t| ", key, ": ", value[idx[0]]1378 description += "\n | %s: %s" % (key, value[idx[0]]) 1406 1379 break 1407 1408 print "---- End of Projection description -----"1380 description += "\n---- End of NEST-specific Projection description -----" 1381 return description 1409 1382 1410 1383 # ============================================================================== trunk/src/neuron/__init__.py
r391 r414 728 728 self.gidlist = [self.fullgidlist[i+myid] for i in range(0, len(self.fullgidlist), nhost) if i < len(self.fullgidlist)-myid] 729 729 self.first_id = gid 730 730 731 731 732 # Write hoc commands … … 743 744 Population.nPop += 1 744 745 gid = gid+self.size 746 self.last_id = gid-1 745 747 746 748 # We add the gidlist of the population to the global gidlist … … 758 760 for cell_id in self.gidlist: 759 761 cell_id.hocname = "%s.o(%d)" % (self.hoc_label, self.gidlist.index(cell_id)) 762 self._local_ids = self.gidlist 760 763 761 764 def __getitem__(self, addr): … … 1102 1105 hoc_comment("--- Population[%s].__randomInit()__ ---" %self.label) 1103 1106 self.rset("v_init", rand_distr) 1104 1105 def describe(self):1106 """1107 Return a human readable description of the population"1108 """1109 print "\n------- Population description -------"1110 print "Population called %s is made of %d cells [%d being local]" %(self.label, len(self.fullgidlist), len(self.gidlist))1111 print "-> Cells are aranged on a %dD grid of size %s" %(len(self.dim), self.dim)1112 print "-> Celltype is %s" %self.celltype1113 print "-> Cell Parameters used for cell[0] (during initialization and now) are: "1114 for key, value in self.cellparams.items():1115 print "\t|", key, "\t: ", "init->", value, "\t now->", getattr(self.cell[0],key)1116 print "--- End of Population description ----"1117 1107 1118 1108 trunk/src/neuron2/__init__.py
r413 r414 132 132 cell_parameters = param_dict 133 133 first_id = simulator.state.gid_counter 134 last_id = simulator.state.gid_counter + n 135 all_ids = numpy.array([id for id in range(first_id, last_id )], ID)134 last_id = simulator.state.gid_counter + n - 1 135 all_ids = numpy.array([id for id in range(first_id, last_id+1)], ID) 136 136 # mask_local is used to extract those elements from arrays that apply to the cells on the current node 137 137 mask_local = all_ids%num_processes()==0 # round-robin distribution of cells between nodes … … 268 268 simulator.initializer.register(self) 269 269 Population.nPop += 1 270 logging.info(self.describe('Creating Population " %(label)s" of shape %(dim)s, '+271 'containing ` %(celltype)s`s with indices between %(first_id)s and %(last_id)s'))270 logging.info(self.describe('Creating Population "$label" of shape $dim, '+ 271 'containing `$celltype`s with indices between $first_id and $last_id')) 272 272 logging.debug(self.describe()) 273 273 … … 333 333 raise common.InvalidDimensionsError 334 334 return coords 335 336 def index(self, n): 337 """Return the nth cell in the population (Indexing starts at 0).""" 338 if hasattr(n, '__len__'): 339 n = numpy.array(n) 340 return self._all_ids.flatten()[n] 335 341 336 342 def get(self, parameter_name, as_array=False): … … 530 536 return float(n_spikes)/n_rec 531 537 532 def describe(self, template=None): 533 if template is None: 534 rows = ['==== Population %(label)s ====', 535 'Dimensions: %(dim)s', 536 'Cell type: %(celltype)s', 537 'ID range: %(first_id)d-%(last_id)d', 538 'First cell on this node:', 539 ' ID: %(local_first_id)d', 540 ' Parameters: %(cell_parameters)s'] 541 template = "\n".join(rows) 542 context = self.__dict__.copy() 543 first_id = self._local_ids[0] 544 context.update(local_first_id=first_id) 545 context.update(cell_parameters=first_id.get_parameters()) 546 context.update(celltype=self.celltype.__class__.__name__) 547 return template % context 548 549 538 539 550 540 class Projection(common.Projection): 551 541 """
