Changeset 408
- Timestamp:
- 07/10/08 12:45:18 (1 month ago)
- Files:
-
- trunk/src/common.py (modified) (6 diffs)
- trunk/src/nest1/__init__.py (modified) (1 diff)
- trunk/src/nest2/__init__.py (modified) (5 diffs)
- trunk/src/nest2/connectors.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/common.py
r407 r408 125 125 def set_parameters(self, **parameters): 126 126 """Set cell parameters, given as a sequence of parameter=value arguments.""" 127 all_parameters = self.get_parameters()128 all_parameters.update(parameters)127 #all_parameters = self.get_parameters() 128 #all_parameters.update(parameters) 129 129 if self.is_standard_cell(): 130 parameters = self.cellclass.translate( all_parameters)130 parameters = self.cellclass.translate(parameters) 131 131 self.set_native_parameters(parameters) 132 132 … … 315 315 parameters = cls.checkParameters(parameters, with_defaults=False) 316 316 native_parameters = {} 317 for name,D in cls.translations.items(): 317 for name,value in parameters.items(): 318 D = cls.translations[name] 319 #for name,D in cls.translations.items(): 318 320 pname = D['translated_name'] 319 321 try: … … 1228 1230 """Base class for Connector classes.""" 1229 1231 1230 def __init__(self, weights=0.0, delays=None ):1232 def __init__(self, weights=0.0, delays=None, check_connections=False): 1231 1233 self.w_index = 0 # should probably use a generator 1232 1234 self.d_index = 0 # rather than storing these values 1233 1235 self.weights = weights 1234 1236 self.delays = delays 1237 self.check_connections = check_connections 1235 1238 if delays is None: 1236 1239 self.delays = get_min_delay() … … 1252 1255 else: 1253 1256 raise Exception("weights is of type %s" % type(self.weights)) 1254 #assert numpy.all(weights>=0), "Weight values must be positive"1255 1257 self.w_index += N 1256 1258 return weights … … 1268 1270 else: 1269 1271 raise Exception("delays is of type %s" % type(self.delays)) 1270 assert numpy.all(delays >= get_min_delay()), \ 1271 "Delay values must be greater than or equal to the minimum delay %g. The smallest delay is %g." % (get_min_delay(), delays.min()) 1272 assert numpy.all(delays <= get_max_delay()), \ 1273 "Delay values must be less than or equal to the maximum delay %s. The largest delay is %s" % (get_max_delay(), delays.max()) 1272 if self.check_connections: 1273 assert numpy.all(delays >= get_min_delay()), \ 1274 "Delay values must be greater than or equal to the minimum delay %g. The smallest delay is %g." % (get_min_delay(), delays.min()) 1275 assert numpy.all(delays <= get_max_delay()), \ 1276 "Delay values must be less than or equal to the maximum delay %s. The largest delay is %s" % (get_max_delay(), delays.max()) 1274 1277 self.d_index += N 1275 1278 return delays … … 1406 1409 d = 1e12; assert 0 <= eval(d_expression), eval(d_expression) 1407 1410 except ZeroDivisionError: 1408 print d_expression 1409 raise 1411 raise Exception("Error in the distance expression %s" %d_expression) 1410 1412 self.d_expression = d_expression 1411 1413 # We will use the numpy functions, so we need to parse the function trunk/src/nest1/__init__.py
r399 r408 1263 1263 print "\n------- Projection description -------" 1264 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 " Connector used is %s: " %self._method1265 print "\t| Connector : " %self._method 1266 1266 if isinstance(self._method.weights,RandomDistribution): 1267 print "\t| Weights are drawn from %s distribution with parameters %s "%(self._method.weights.name, self._method.weights.parameters)1268 else: 1269 print "\t| Weights : ", self._method.weights1267 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 1270 if isinstance(self._method.delays,RandomDistribution): 1271 print "\t| Delays are drawn from %s distribution with parameters %s " %(self._method.delays.name, self._method.delays.parameters)1272 else: 1273 print "\t| Delays : ", self._method.delays1274 print "\t| Plasticity : ", self._plasticity_model1271 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 1275 print "\t --> %d connections have been created for this projection" %len(self) 1276 print "To check, here are the parameters of one connection from this projection" 1277 print "\tsource\ttarget" 1278 print "\t%d\t%d" %(self._sources[0], self._targets[0]) 1279 print "\t| Weight: ", pynest.getWeight([self._sources[0]],self._targetPorts[0]) 1280 print "\t| Delay: ", pynest.getDelay([self._sources[0]], self._targetPorts[0]) 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]) 1281 1279 1282 1280 print "---- End of Projection description -----" trunk/src/nest2/__init__.py
r407 r408 10 10 from pyNN.random import * 11 11 from pyNN import recording 12 import numpy, types, sys, shutil, os, logging, copy, tempfile 12 import numpy, types, sys, shutil, os, logging, copy, tempfile, re 13 13 from math import * 14 14 from pyNN.nest2.cells import * … … 515 515 os.remove(nest_filename) 516 516 if gather and len(node_list) > 1: 517 #if rank() == 0: 517 518 raise Exception("gather not yet implemented") 518 519 return merged_filename … … 571 572 self.cell_local = self.cell[numpy.array(nest.GetStatus(self.cell.tolist(),'local'))] 572 573 self.first_id = self.cell.reshape(self.size,)[0] 573 574 574 for id in self.cell: 575 575 id.parent = self … … 864 864 Returns the mean number of spikes per neuron. 865 865 """ 866 n_spikes = nest.GetStatus(self.recorders['spikes']._device,'n_events')[0] 866 867 ## Routine to give an average firing rate over all the threads/nodes 868 ## This is a rough approximation, because in fact each nodes is only multiplying 869 ## the frequency of the recorders by the number of processes. To do better, we need a MPI 870 ## package to send informations to node 0. 871 node_list = range(nest.GetStatus([0], "total_num_virtual_procs")[0]) 872 n_spikes = 0 873 for node in node_list: 874 nest.sps(self.recorders['spikes']._device[0]) 875 nest.sr("%d GetAddress %d append" %(self.recorders['spikes']._device[0], node)) 876 nest.sr("GetStatus /n_events get") 877 n_spikes += nest.spp() 867 878 n_rec = len(self.recorders['spikes'].recorded) 868 879 return float(n_spikes)/n_rec … … 1361 1372 print "\n------- Projection description -------" 1362 1373 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)) 1363 print " Connector used is %s :" %self._method1374 print "\t| Connector : %s" %self._method 1364 1375 if isinstance(self._method.weights,RandomDistribution): 1365 print "\t| Weights are drawn from %s distribution with parameters %s "%(self._method.weights.name, self._method.weights.parameters)1366 else: 1367 print "\t| Weights : ", self._method.weights1376 print "\t| Weights : drawn from %s distribution with params %s "%(self._method.weights.name, self._method.weights.parameters) 1377 else: 1378 print "\t| Weights : ", self._method.weights 1368 1379 if isinstance(self._method.delays,RandomDistribution): 1369 print "\t| Delays are drawn from %s distribution with parameters %s " %(self._method.delays.name, self._method.delays.parameters)1380 print "\t| Delays : drawn from %s distribution with params %s " %(self._method.delays.name, self._method.delays.parameters) 1370 1381 else: 1371 1382 print "\t| Delays: ", self._method.delays 1372 print "\t| Plasticity: ", self._plasticity_model 1373 print "\t --> %d connections have been created for this projection" %len(self) 1374 print "To check, here are the parameters of one connection from this projection" 1375 print "\tsource\ttarget\tport" 1376 print "\t%d\t%d\t%d" %(self._sources[0], self._targets[0], self._target_ports[0]) 1383 print "\t| Plasticity : ", self._plasticity_model 1384 print "\t ----> %d connections have been created for this projection" %len(self) 1385 print "\tParameters of connection from %d to %d [port %d]" %(self._sources[0], self._targets[0], self._target_ports[0]) 1377 1386 dict = nest.GetConnections([self.pre.cell.flat[0]], self._plasticity_model)[0] 1378 1387 for i in xrange(len(self._targets)): trunk/src/nest2/connectors.py
r406 r408 87 87 88 88 def connect(self, projection): 89 postsynaptic_neurons = projection.post.cell_local.flatten()90 npost = projection.post.size89 postsynaptic_neurons = projection.post.cell.flatten() 90 npost = len(postsynaptic_neurons) 91 91 for pre in projection.pre.cell.flat: 92 92 if projection.rng: … … 120 120 print "Periodic boundaries activated and set to size ", periodic_boundaries 121 121 postsynaptic_neurons = projection.post.cell.flatten() # array 122 presynaptic_neurons = projection.pre.cell.flat # iterator 122 #postsynaptic_neurons = projection.post.cell_local 123 123 # what about NativeRNG? 124 124 if projection.rng: … … 130 130 else: 131 131 rng = numpy.random 132 for pre in pr esynaptic_neurons:132 for pre in projection.pre.cell.flat: 133 133 # We compute the distances from the post cell to all the others 134 134 distances = common.distances(pre, projection.post, self.mask,
