Changeset 90
- Timestamp:
- 06/05/07 14:59:46 (1 year ago)
- Files:
-
- branches/connector-class/common.py (modified) (2 diffs)
- branches/connector-class/nest.py (modified) (7 diffs)
- branches/connector-class/neuron.py (modified) (8 diffs)
- branches/connector-class/pcsim.py (modified) (1 diff)
- branches/connector-class/test/nesttests.py (modified) (3 diffs)
- branches/connector-class/test/neurontests.py (modified) (3 diffs)
- branches/connector-class/test/pcsimtests_population.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/connector-class/common.py
r89 r90 9 9 10 10 import types, time, copy 11 from math import * 12 11 13 12 14 class InvalidParameterValueError(Exception): pass … … 699 701 pass 700 702 701 703 class FixedProbabilityConnector(Connector): 704 """ 705 For each pair of pre-post cells, the connection probability is constant. 706 """ 707 708 def __init__(self, p_connect, allow_self_connections=True): 709 assert isinstance(allow_self_connections, bool) 710 self.allow_self_connections = allow_self_connections 711 self.p_connect = float(p_connect) 712 assert 0 <= self.p_connect 713 714 class DistanceDependentProbabilityConnector(Connector): 715 """ 716 For each pair of pre-post cells, the connection probability depends on distance. 717 d_expression should be the right-hand side of a valid python expression 718 for probability, involving 'd', e.g. "exp(-abs(d))", or "float(d<3)" 719 """ 720 721 def __init__(self, d_expression, allow_self_connections=True): 722 assert isinstance(allow_self_connections, bool) 723 assert isinstance(d_expression, str) 724 d = 0; assert 0 <= eval(d_expression) 725 d = 1e12; assert 0 <= eval(d_expression) 726 self.d_expression = d_expression 727 self.allow_self_connections = allow_self_connections 728 702 729 # ============================================================================== 703 730 # Utility classes branches/connector-class/nest.py
r89 r90 22 22 23 23 # ============================================================================== 24 # Utility classes 24 # Utility classes and functions 25 25 # ============================================================================== 26 26 … … 48 48 set(self,self._cellclass,param,val) 49 49 50 50 def _distance(presynaptic_population, postsynaptic_population, src, tgt): 51 """ 52 Return the Euclidian distance between two cells. For the moment, we do 53 a scaling between the two dimensions of the populations: the target 54 population is scaled to the size of the source population.""" 55 dist = 0.0 56 src_position = src.getPosition() 57 tgt_position = tgt.getPosition() 58 if (len(src_position) == len(tgt_position)): 59 for i in xrange(len(src_position)): 60 # We normalize the positions in each population and calculate the 61 # Euclidian distance : 62 #scaling = float(presynaptic_population.dim[i])/float(postsynaptic_population.dim[i]) 63 src_coord = float(src_position[i]) 64 tgt_coord = float(tgt_position[i]) 65 66 dist += float(src_coord-tgt_coord)*float(src_coord-tgt_coord) 67 else: 68 raise Exception("Method _distance() not yet implemented for Populations with different sizes.") 69 return sqrt(dist) 70 51 71 # ============================================================================== 52 72 # Standard cells … … 886 906 yield self.connection[i] 887 907 888 def _distance(self, presynaptic_population, postsynaptic_population, src, tgt): 889 """ 890 Return the Euclidian distance between two cells. For the moment, we do 891 a scaling between the two dimensions of the populations: the target 892 population is scaled to the size of the source population.""" 893 dist = 0.0 894 src_position = src.getPosition() 895 tgt_position = tgt.getPosition() 896 if (len(src_position) == len(tgt_position)): 897 for i in xrange(len(src_position)): 898 # We normalize the positions in each population and calculate the 899 # Euclidian distance : 900 #scaling = float(presynaptic_population.dim[i])/float(postsynaptic_population.dim[i]) 901 src_coord = float(src_position[i]) 902 tgt_coord = float(tgt_position[i]) 903 904 dist += float(src_coord-tgt_coord)*float(src_coord-tgt_coord) 905 else: 906 raise Exception("Method _distance() not yet implemented for Populations with different sizes.") 907 return sqrt(dist) 908 908 909 909 910 # --- Connection methods --------------------------------------------------- … … 930 931 in row i of a 2D post population of size (n,m). 931 932 """ 932 if self.pre.dim == self.post.dim: 933 self._sources = numpy.reshape(self.pre.cell,(self.pre.cell.size,)) 934 self._targets = numpy.reshape(self.post.cell,(self.post.cell.size,)) 935 for pre,post in zip(self._sources,self._targets): 936 pre_addr = pynest.getAddress(pre) 937 post_addr = pynest.getAddress(post) 938 self._targetPorts.append(pynest.connect(pre_addr,post_addr)) 939 return self.pre.size 940 else: 941 raise Exception("Method 'oneToOne' not yet implemented for the case where presynaptic and postsynaptic Populations have different sizes.") 933 c = OneToOneConnector() 934 return c.connect(self) 935 #if self.pre.dim == self.post.dim: 936 # self._sources = numpy.reshape(self.pre.cell,(self.pre.cell.size,)) 937 # self._targets = numpy.reshape(self.post.cell,(self.post.cell.size,)) 938 # for pre,post in zip(self._sources,self._targets): 939 # pre_addr = pynest.getAddress(pre) 940 # post_addr = pynest.getAddress(post) 941 # self._targetPorts.append(pynest.connect(pre_addr,post_addr)) 942 # return self.pre.size 943 #else: 944 # raise Exception("Method 'oneToOne' not yet implemented for the case where presynaptic and postsynaptic Populations have different sizes.") 942 945 943 946 def _fixedProbability(self,parameters): … … 952 955 if parameters.has_key('allow_self_connections'): 953 956 allow_self_connections = parameters['allow_self_connections'] 954 955 postsynaptic_neurons = numpy.reshape(self.post.cell,(self.post.cell.size,)) 956 presynaptic_neurons = numpy.reshape(self.pre.cell,(self.pre.cell.size,)) 957 npre = self.pre.size 958 for post in postsynaptic_neurons: 959 if self.rng: 960 rarr = self.rng.uniform(0,1,(npre,)) 961 else: 962 rarr = numpy.random.uniform(0,1,(npre,)) 963 source_list = numpy.compress(numpy.less(rarr,p_connect),presynaptic_neurons).tolist() 964 self._targets += [post]*len(source_list) 965 self._sources += source_list 966 self._targetPorts += pynest.convergentConnect(source_list,post,[1.0],[0.1]) 967 return len(self._sources) 957 c = FixedProbabilityConnector(p_connect, allow_self_connections) 958 return c.connect(self) 959 960 #postsynaptic_neurons = numpy.reshape(self.post.cell,(self.post.cell.size,)) 961 #presynaptic_neurons = numpy.reshape(self.pre.cell,(self.pre.cell.size,)) 962 #npre = self.pre.size 963 #for post in postsynaptic_neurons: 964 # if self.rng: 965 # rarr = self.rng.uniform(0,1,(npre,)) 966 # else: 967 # rarr = numpy.random.uniform(0,1,(npre,)) 968 # source_list = numpy.compress(numpy.less(rarr,p_connect),presynaptic_neurons).tolist() 969 # # if self connections are not allowed, check whether pre and post are the same 970 # if not allow_self_connections and post in source_list: 971 # source_list.remove(post) 972 # self._targets += [post]*len(source_list) 973 # self._sources += source_list 974 # self._targetPorts += pynest.convergentConnect(source_list,post,[1.0],[0.1]) 975 #return len(self._sources) 968 976 969 977 def _distanceDependentProbability(self,parameters): … … 980 988 if parameters.has_key('allow_self_connections'): 981 989 allow_self_connections = parameters['allow_self_connections'] 982 983 #raise Exception("Method not yet implemented") 984 # Here we observe the connectivity rule: if it is a probability function 985 # like "exp(-d^2/2s^2)" then distance_expression should have only 986 # alphanumeric characters. Otherwise, if we have characters 987 # like >,<, = the connectivity rule is by itself a test. 988 alphanum = True 989 operators = ['<', '>', '='] 990 for i in xrange(len(operators)): 991 if not d_expression.find(operators[i])==-1: 992 alphanum = False 993 994 postsynaptic_neurons = numpy.reshape(self.post.cell,(self.post.cell.size,)) 995 presynaptic_neurons = numpy.reshape(self.pre.cell,(self.pre.cell.size,)) 996 997 # We need to use the gid stored as ID, so we should modify the loop to scan the global gidlist (containing ID) 998 for post in postsynaptic_neurons: 999 if self.rng: 1000 rarr = self.rng.uniform(0,1,(self.pre.size,)) 1001 else: 1002 rarr = numpy.random.uniform(0,1,(self.pre.size,)) 1003 count = 0 1004 for pre in presynaptic_neurons: 1005 if allow_self_connections or pre != post: 1006 # calculate the distance between the two cells : 1007 dist = self._distance(self.pre, self.post, pre, post) 1008 distance_expression = d_expression.replace('d', '%f' %dist) 1009 1010 # calculate the addresses of cells 1011 pre_addr = pynest.getAddress(pre) 1012 post_addr = pynest.getAddress(post) 1013 1014 if alphanum: 1015 if rarr[count] < eval(distance_expression): 1016 self._sources.append(pre) 1017 self._targets.append(post) 1018 self._targetPorts.append(pynest.connect(pre_addr,post_addr)) 1019 count = count + 1 1020 elif eval(distance_expression): 1021 self._sources.append(pre) 1022 self._targets.append(post) 1023 self._targetPorts.append(pynest.connect(pre_addr,post_addr)) 1024 990 c = DistanceDependentProbabilityConnector(d_expression, allow_self_connections) 991 return c.connect(self) 992 993 ## Here we observe the connectivity rule: if it is a probability function 994 ## like "exp(-d^2/2s^2)" then distance_expression should have only 995 ## alphanumeric characters. Otherwise, if we have characters 996 ## like >,<, = the connectivity rule is by itself a test. 997 #alphanum = True 998 #operators = ['<', '>', '='] 999 #for i in xrange(len(operators)): 1000 # if not d_expression.find(operators[i])==-1: 1001 # alphanum = False 1002 # 1003 #postsynaptic_neurons = numpy.reshape(self.post.cell,(self.post.cell.size,)) 1004 #presynaptic_neurons = numpy.reshape(self.pre.cell,(self.pre.cell.size,)) 1005 # 1006 ## We need to use the gid stored as ID, so we should modify the loop to scan the global gidlist (containing ID) 1007 #for post in postsynaptic_neurons: 1008 # if self.rng: 1009 # if isinstance(self.rng, NativeRNG): 1010 # print "Warning: use of NativeRNG not implemented. Using NumpyRNG" 1011 # rarr = numpy.random.uniform(0,1,(self.pre.size,)) 1012 # else: 1013 # rarr = self.rng.uniform(0,1,(self.pre.size,)) 1014 # else: 1015 # rarr = numpy.random.uniform(0,1,(self.pre.size,)) 1016 # count = 0 1017 # for pre in presynaptic_neurons: 1018 # if allow_self_connections or pre != post: 1019 # # calculate the distance between the two cells : 1020 # dist = _distance(self.pre, self.post, pre, post) 1021 # distance_expression = d_expression.replace('d', '%f' %dist) 1022 # 1023 # # calculate the addresses of cells 1024 # pre_addr = pynest.getAddress(pre) 1025 # post_addr = pynest.getAddress(post) 1026 # 1027 # if alphanum: 1028 # if rarr[count] < eval(distance_expression): 1029 # self._sources.append(pre) 1030 # self._targets.append(post) 1031 # self._targetPorts.append(pynest.connect(pre_addr,post_addr)) 1032 # #count = count + 1 1033 # elif eval(distance_expression): 1034 # self._sources.append(pre) 1035 # self._targets.append(post) 1036 # self._targetPorts.append(pynest.connect(pre_addr,post_addr)) 1037 # count = count + 1 1038 1025 1039 def _fixedNumberPre(self,parameters): 1026 1040 """Each presynaptic cell makes a fixed number of connections.""" … … 1606 1620 raise Exception("Connection method not yet implemented for the case where presynaptic and postsynaptic Populations have different sizes.") 1607 1621 1608 1622 class FixedProbabilityConnector(common.FixedProbabilityConnector): 1623 1624 def connect(self, projection): 1625 postsynaptic_neurons = numpy.reshape(projection.post.cell,(projection.post.cell.size,)) 1626 presynaptic_neurons = numpy.reshape(projection.pre.cell,(projection.pre.cell.size,)) 1627 npre = projection.pre.size 1628 for post in postsynaptic_neurons: 1629 if projection.rng: 1630 rarr = projection.rng.uniform(0,1,(npre,)) # what about NativeRNG? 1631 else: 1632 rarr = numpy.random.uniform(0,1,(npre,)) 1633 source_list = numpy.compress(numpy.less(rarr,self.p_connect),presynaptic_neurons).tolist() 1634 # if self connections are not allowed, check whether pre and post are the same 1635 if not self.allow_self_connections and post in source_list: 1636 source_list.remove(post) 1637 projection._targets += [post]*len(source_list) 1638 projection._sources += source_list 1639 projection._targetPorts += pynest.convergentConnect(source_list,post,[1.0],[0.1]) 1640 return len(projection._sources) 1641 1642 class DistanceDependentProbabilityConnector(common.DistanceDependentProbabilityConnector): 1643 1644 def connect(self, projection): 1645 postsynaptic_neurons = numpy.reshape(projection.post.cell,(projection.post.cell.size,)) 1646 presynaptic_neurons = numpy.reshape(projection.pre.cell,(projection.pre.cell.size,)) 1647 # what about NativeRNG? 1648 if projection.rng: 1649 if isinstance(projection.rng, NativeRNG): 1650 print "Warning: use of NativeRNG not implemented. Using NumpyRNG" 1651 rarr = numpy.random.uniform(0,1,(projection.pre.size*projection.post.size,)) 1652 else: 1653 rarr = projection.rng.uniform(0,1,(projection.pre.size*projection.post.size,)) 1654 else: 1655 rarr = numpy.random.uniform(0,1,(projection.pre.size*projection.post.size,)) 1656 j = 0 1657 for post in postsynaptic_neurons: 1658 for pre in presynaptic_neurons: 1659 if self.allow_self_connections or pre != post: 1660 # calculate the distance between the two cells : 1661 d = _distance(projection.pre, projection.post, pre, post) 1662 p = eval(self.d_expression) 1663 # calculate the addresses of cells 1664 pre_addr = pynest.getAddress(pre) 1665 post_addr = pynest.getAddress(post) 1666 if p >= 1 or (0 < p < 1 and rarr[j] < p): 1667 projection._sources.append(pre) 1668 projection._targets.append(post) 1669 projection._targetPorts.append(pynest.connect(pre_addr,post_addr)) 1670 j += 1 1671 1609 1672 # ============================================================================== 1610 1673 # Utility classes branches/connector-class/neuron.py
r89 r90 231 231 return HocToPy.hocvar 232 232 233 def _distance(presynaptic_population, postsynaptic_population, src, tgt): 234 """ 235 Return the Euclidian distance between two cells. For the moment, we do 236 a scaling between the two dimensions of the populations: the target 237 population is scaled to the size of the source population.""" 238 dist = 0.0 239 src_position = src.getPosition() 240 tgt_position = tgt.getPosition() 241 if (len(src_position) == len(tgt_position)): 242 for i in xrange(len(src_position)): 243 # We normalize the positions in each population and calculate the 244 # Euclidian distance : 245 #scaling = float(presynaptic_population.dim[i])/float(postsynaptic_population.dim[i]) 246 src_coord = float(src_position[i]) 247 tgt_coord = float(tgt_position[i]) 248 249 dist += float(src_coord-tgt_coord)*float(src_coord-tgt_coord) 250 else: 251 raise Exception("Method _distance() not yet implemented for Populations with different sizes.") 252 return sqrt(dist) 253 233 254 # ============================================================================== 234 255 # Standard cells … … 1176 1197 return len(self.connections) 1177 1198 1178 def _distance(self, presynaptic_population, postsynaptic_population, src, tgt): 1179 """ 1180 Return the Euclidian distance between two cells. For the moment, we do 1181 a scaling between the two dimensions of the populations: the target 1182 population is scaled to the size of the source population.""" 1183 dist = 0.0 1184 src_position = src.getPosition() 1185 tgt_position = tgt.getPosition() 1186 if (len(src_position) == len(tgt_position)): 1187 for i in xrange(len(src_position)): 1188 # We normalize the positions in each population and calculate the 1189 # Euclidian distance : 1190 #scaling = float(presynaptic_population.dim[i])/float(postsynaptic_population.dim[i]) 1191 src_coord = float(src_position[i]) 1192 tgt_coord = float(tgt_position[i]) 1193 1194 dist += float(src_coord-tgt_coord)*float(src_coord-tgt_coord) 1195 else: 1196 raise Exception("Method _distance() not yet implemented for Populations with different sizes.") 1197 return sqrt(dist) 1199 1198 1200 1199 1201 … … 1248 1250 if parameters.has_key('allow_self_connections'): 1249 1251 allow_self_connections = parameters['allow_self_connections'] 1250 1251 hoc_commands = [] 1252 if isinstance(self.rng, NativeRNG): # use hoc Random object 1253 hoc_commands = ['rng = new Random(%d)' % 0 or self.rng.seed, 1254 'tmp = rng.uniform(0,1)'] 1255 # Here we are forced to execute the commands on line to be able to 1256 # catch the connections from NEURON. 1257 hoc_execute(hoc_commands) 1258 hoc_commands = [] 1259 #Then we do the loop 1260 for tgt in self.post.gidlist: 1261 for src in self.pre.fullgidlist: 1262 if HocToPy.get('rng.repick()','float') < p_connect: 1263 if allow_self_connections or self.pre != self.post or tgt != src: 1264 self.__connect(src,tgt) 1265 return hoc_commands 1266 else: # use Python RNG 1267 for tgt in self.post.gidlist: 1268 rarr = self.rng.uniform(0, 1, self.pre.size) 1269 for j in xrange(self.pre.size): 1270 src = j + self.pre.gid_start 1271 if rarr[j] < p_connect: 1272 if allow_self_connections or self.pre != self.post or tgt != src: 1273 hoc_commands += self.__connect(src,tgt) 1274 return hoc_commands 1252 c = FixedProbabilityConnector(p_connect=p_connect, 1253 allow_self_connections=allow_self_connections) 1254 return c.connect(self) 1275 1255 1276 1256 def _distanceDependentProbability(self,parameters): … … 1287 1267 if parameters.has_key('allow_self_connections'): 1288 1268 allow_self_connections = parameters['allow_self_connections'] 1289 hoc_commands = [] 1290 1291 # Here we observe the connectivity rule: if it is a probability function 1292 # like "exp(-d^2/2s^2)" then distance_expression should have only 1293 # alphanumeric characters. Otherwise, if we have characters 1294 # like >,<, = the connectivity rule is by itself a test. 1295 alphanum = True 1296 operators = ['<', '>', '='] 1297 for i in xrange(len(operators)): 1298 if not d_expression.find(operators[i])==-1: 1299 alphanum = False 1300 1301 if isinstance(self.rng, NativeRNG): 1302 hoc_commands = ['rng = new Random(%d)' % 0 or distribution.rng.seed, 1303 'tmp = rng.uniform(0,1)'] 1304 # Here we are forced to execute the commands on line to be able to 1305 # catch the connections from Neuron 1306 hoc_execute(hoc_commands) 1307 hoc_commands = [] 1308 # We need to use the gid stored as ID, so we should modify the loop to scan the global gidlist (containing ID) 1309 for tgt in self.post.gidlist: 1310 for src in self.pre.fullgidlist: 1311 if allow_self_connections or self.pre != self.post or tgt != src: 1312 # calculate the distance between the two cells : 1313 dist = self._distance(self.pre, self.post, src, tgt) 1314 distance_expression = d_expression.replace('d', '%f' %dist) 1315 if alphanum: 1316 if HocToPy('rng.repick()','float') < eval(distance_expression): 1317 hoc_commands += self.__connect() 1318 elif eval(distance_expression): 1319 hoc_commands += self.__connect() 1320 return hoc_commands 1321 else: # use a python RNG 1322 for tgt in self.post.gidlist: 1323 rarr = self.rng.uniform(0,1,self.pre.size) 1324 for j in xrange(self.pre.size): 1325 # Again, we should have an ID (stored in the global gidlist) instead 1326 # of a simple int. 1327 src = self.pre.fullgidlist[j] 1328 if allow_self_connections or self.pre != self.post or tgt != src: 1329 # calculate the distance between the two cells : 1330 dist = self._distance(self.pre, self.post, src, tgt) 1331 distance_expression = d_expression.replace('d', '%f' %dist) 1332 if alphanum: 1333 if rarr[j] < eval(distance_expression): 1334 hoc_commands += self.__connect(src,tgt) 1335 elif eval(distance_expression): 1336 hoc_commands += self.__connect(src,tgt) 1337 return hoc_commands 1269 c = DistanceDependentProbabilityConnector(d_expression=d_expression, 1270 allow_self_connections=allow_self_connections) 1271 return c.connect(self) 1338 1272 1339 1273 def _fixedNumberPre(self,parameters): … … 1573 1507 idx_src = self.pre.fullgidlist.index(src) 1574 1508 idx_tgt = self.post.fullgidlist.index(tgt) 1575 dist = self._distance(self.pre, self.post, self.pre.fullgidlist[idx_src], self.post.fullgidlist[idx_tgt])1509 dist = _distance(self.pre, self.post, self.pre.fullgidlist[idx_src], self.post.fullgidlist[idx_tgt]) 1576 1510 # then evaluate the delay according to the delay rule 1577 1511 delay = eval(delay_rule.replace('d', '%f' %dist)) … … 1589 1523 idx_src = self.pre.fullgidlist.index(src) 1590 1524 idx_tgt = self.post.fullgidlist.index(tgt) 1591 dist = self._distance(self.pre, self.post, self.pre.fullgidlist[idx_src], self.post.fullgidlist[idx_tgt])1525 dist = _distance(self.pre, self.post, self.pre.fullgidlist[idx_src], self.post.fullgidlist[idx_tgt]) 1592 1526 # then evaluate the delay according to the delay rule 1593 1527 delay = delay_rule.replace('d', '%f' % dist) … … 1601 1535 idx_src = self.pre.fullgidlist.index(src) 1602 1536 idx_tgt = self.post.fullgidlist.index(tgt) 1603 dist = self._distance(self.pre, self.post, self.pre.fullgidlist[idx_src], self.post.fullgidlist[idx_tgt])1537 dist = _distance(self.pre, self.post, self.pre.fullgidlist[idx_src], self.post.fullgidlist[idx_tgt]) 1604 1538 # then evaluate the delay according to the delay rule : 1605 1539 delay = delay_rule.replace('d', '%f' %dist) … … 1786 1720 raise Exception("Method '%s' not yet implemented for the case where presynaptic and postsynaptic Populations have different sizes." % sys._getframe().f_code.co_name) 1787 1721 return hoc_commands 1722 1723 class FixedProbabilityConnector(common.FixedProbabilityConnector, HocConnector): 1724 1725 def connect(self, projection): 1726 if isinstance(projection.rng, NativeRNG): 1727 hoc_commands = ['rng = new Random(%d)' % 0 or distribution.rng.seed, 1728 'tmp = rng.uniform(0,1)'] 1729 # Here we are forced to execute the commands on line to be able to 1730 # catch the connections from NEURON 1731 hoc_execute(hoc_commands) 1732 rarr = [HocToPy.get('rng.repick()','float') for j in xrange(projection.pre.size*projection.post.size)] 1733 else: 1734 rarr = projection.rng.uniform(0,1,projection.pre.size*projection.post.size) 1735 hoc_commands = [] 1736 j = 0 1737 for tgt in projection.post.gidlist: 1738 for src in projection.pre.fullgidlist: 1739 if self.allow_self_connections or projection.pre != projection.post or tgt != src: 1740 if rarr[j] < self.p_connect: 1741 hoc_commands += self.singleConnect(projection,src,tgt) 1742 j += 1 1743 return hoc_commands 1744 1745 class DistanceDependentProbabilityConnector(common.DistanceDependentProbabilityConnector, HocConnector): 1746 1747 def connect(self, projection): 1748 if isinstance(projection.rng, NativeRNG): 1749 hoc_commands = ['rng = new Random(%d)' % 0 or distribution.rng.seed, 1750 'tmp = rng.uniform(0,1)'] 1751 # Here we are forced to execute the commands on line to be able to 1752 # catch the connections from NEURON 1753 hoc_execute(hoc_commands) 1754 rarr = [HocToPy.get('rng.repick()','float') for j in xrange(projection.pre.size*projection.post.size)] 1755 else: 1756 rarr = projection.rng.uniform(0,1,projection.pre.size*projection.post.size) 1757 # We need to use the gid stored as ID, so we should modify the loop to scan the global gidlist (containing ID) 1758 hoc_commands = [] 1759 j = 0 1760 for tgt in projection.post.gidlist: 1761 for src in projection.pre.fullgidlist: 1762 if self.allow_self_connections or projection.pre != projection.post or tgt != src: 1763 # calculate the distance between the two cells : 1764 d = _distance(projection.pre, projection.post, src, tgt) 1765 p = eval(self.d_expression) 1766 if 0 < p < 1: 1767 if rarr[j] < p: 1768 hoc_commands += self.singleConnect(projection,src,tgt) 1769 elif p >= 1: 1770 hoc_commands += self.singleConnect(projection,src,tgt) 1771 j += 1 1772 return hoc_commands 1788 1773 1789 1774 # ============================================================================== branches/connector-class/pcsim.py
r89 r90 1288 1288 else: 1289 1289 raise Exception("Connection method not yet implemented for the case where presynaptic and postsynaptic Populations have different sizes.") 1290 1291 class FixedProbabilityConnector(common.FixedProbabilityConnector): 1292 1293 def connect(self,projection): 1294 decider = RandomConnections(float(self.p_connect)) 1295 wiring_method = DistributedSyncWiringMethod(pcsim_globals.net) 1296 return decider, wiring_method 1290 1297 1291 1298 branches/connector-class/test/nesttests.py
r89 r90 418 418 assert weights == [1.0]*len(prj._sources) 419 419 420 def test oneToOne(self):420 def testOneToOne(self): 421 421 """For all connections created with "OneToOne" it should be possible to obtain the weight using pyneuron.getWeight()""" 422 422 prj1 = nest.Projection(self.source33, self.target33, 'oneToOne') … … 425 425 assert len(prj2) == self.source33.size 426 426 427 def test distantDependentProbability(self):428 """For all connections created with "distanceDependentProbability" it should be possible to obtain the weight using pyneuron.getWeight()"""427 def testDistantDependentProbability(self): 428 """For all connections created with "distanceDependentProbability"...""" 429 429 # Test should be improved..." 430 distrib_Numpy = random.RandomDistribution(random.NumpyRNG(12345),'uniform',(0,1)) 431 prj1 = nest.Projection(self.source33, self.target33, 'distanceDependentProbability',{'d_expression' : 'exp(-d)'}, distrib_Numpy) 432 prj2 = nest.Projection(self.source33, self.target33, 'distanceDependentProbability',{'d_expression' : 'd < 0.5'}, distrib_Numpy) 433 assert (0 < len(prj1) < len(self.source33)*len(self.target33)) and (0 < len(prj2) < len(self.source33)*len(self.target33)) 434 430 for rngclass in (nest.NumpyRNG, nest.NativeRNG): 431 for expr in ('exp(-d)', 'd < 0.5'): 432 prj1 = nest.Projection(self.source33, self.target33, 433 'distanceDependentProbability', 434 {'d_expression' : expr},rng=rngclass(12345)) 435 prj2 = nest.Projection(self.source33, self.target33, 436 nest.DistanceDependentProbabilityConnector(d_expression=expr), 437 rng=rngclass(12345)) 438 assert (0 < len(prj1) < len(self.source33)*len(self.target33)) \ 439 and (0 < len(prj2) < len(self.source33)*len(self.target33)) 440 if rngclass == nest.NumpyRNG: 441 assert prj1._sources == prj2._sources, "%s %s" % (rngclass, expr) 442 assert prj1._targets == prj2._targets, "%s %s" % (rngclass, expr) 443 435 444 def testFixedProbability(self): 436 445 """For all connections created with "fixedProbability" it should be possible to obtain the weight using pynest.getWeight()""" … … 438 447 for tgtP in [self.target6, self.target33]: 439 448 prj1 = nest.Projection(srcP, tgtP, "fixedProbability", 0.5) 440 assert len(prj1._sources) == len(prj1._targets) 441 weights = [] 442 for src, tgt in prj1.connections(): 443 weights.append(nest.pynest.getWeight(src,tgt)) 444 assert weights == [1.0]*len(prj1._sources) 445 449 prj2 = nest.Projection(srcP, tgtP, nest.FixedProbabilityConnector(0.5)) 450 for prj in prj1, prj2: 451 assert len(prj._sources) == len(prj._targets) 452 weights = [] 453 for src, tgt in prj.connections(): 454 weights.append(nest.pynest.getWeight(src,tgt)) 455 assert weights == [1.0]*len(prj._sources) 456 446 457 def testSaveAndLoad(self): 447 458 prj1 = nest.Projection(self.source22, self.target33, 'allToAll') branches/connector-class/test/neurontests.py
r89 r90 458 458 459 459 def testAllToAll(self): 460 """For all connections created with "allToAll" it should be possible to obtain the weight using pyneuron.getWeight()"""460 """For all connections created with "allToAll" it should be possible to obtain the weight using HocToPy.get()""" 461 461 for srcP in [self.source5, self.source22]: 462 462 for tgtP in [self.target6, self.target33]: … … 472 472 473 473 def testFixedProbability(self): 474 """For all connections created with "fixedProbability" it should be possible to obtain the weight using pyneuron.getWeight()""" 475 distrib_Numpy = RandomDistribution(NumpyRNG(12345),'uniform',(0,1)) 476 distrib_Native= RandomDistribution(NativeRNG(12345),'uniform',(0,1)) 474 """For all connections created with "fixedProbability"...""" 477 475 for srcP in [self.source5, self.source22]: 478 476 for tgtP in [self.target6, self.target33]: 479 prj1 = neuron.Projection(srcP, tgtP, 'fixedProbability', 0.5, distrib_Numpy) 480 prj2 = neuron.Projection(srcP, tgtP, 'fixedProbability', 0.5, distrib_Native) 481 assert (0 < len(prj1) < len(srcP)*len(tgtP)) and (0 < len(prj2) < len(srcP)*len(tgtP)) 477 prj1 = neuron.Projection(srcP, tgtP, 'fixedProbability', 0.5, rng=NumpyRNG(12345)) 478 prj2 = neuron.Projection(srcP, tgtP, 'fixedProbability', 0.5, rng=NativeRNG(12345)) 479 prj3 = neuron.Projection(srcP, tgtP, FixedProbabilityConnector(0.5), rng=NumpyRNG(12345)) 480 assert (0 < len(prj1) < len(srcP)*len(tgtP)) \ 481 and (0 < len(prj2) < len(srcP)*len(tgtP)) \ 482 and (0 < len(prj3) < len(srcP)*len(tgtP)) 482 483 483 484 def testoneToOne(self): 484 """For all connections created with "OneToOne" it should be possible to obtain the weight using pyneuron.getWeight()"""485 """For all connections created with "OneToOne" ...""" 485 486 prj1 = neuron.Projection(self.source33, self.target33, 'oneToOne') 486 487 prj2 = neuron.Projection(self.source33, self.target33, neuron.OneToOneConnector()) … … 489 490 490 491 def testdistantDependentProbability(self): 491 """For all connections created with "distanceDependentProbability" it should be possible to obtain the weight using pyneuron.getWeight()"""492 """For all connections created with "distanceDependentProbability"...""" 492 493 # Test should be improved..." 493 distrib_Numpy = RandomDistribution(NumpyRNG(12345),'uniform',(0,1)) 494 distrib_Native= RandomDistribution(NativeRNG(12345),'uniform',(0,1)) 495 prj1 = neuron.Projection(self.source33, self.target33, 'distanceDependentProbability',{'d_expression' : 'exp(-d)'}, distrib_Numpy) 496 prj2 = neuron.Projection(self.source33, self.target33, 'distanceDependentProbability',{'d_expression' : 'd < 0.5'}, distrib_Native) 497 assert (0 < len(prj1) < len(self.source33)*len(self.target33)) and (0 < len(prj2) < len(self.source33)*len(self.target33)) 498 494 for rngclass in (NumpyRNG, NativeRNG): 495 for expr in ('exp(-d)', 'd < 0.5'): 496 prj1 = neuron.Projection(self.source33, self.target33, 497 'distanceDependentProbability', 498 {'d_expression' : expr},rng=rngclass(12345)) 499 prj2 = neuron.Projection(self.source33, self.target33, 500 neuron.DistanceDependentProbabilityConnector(d_expression=expr), 501 rng=rngclass(12345)) 502 assert (0 < len(prj1) < len(self.source33)*len(self.target33)) \ 503 and (0 < len(prj2) < len(self.source33)*len(self.target33)) 504 assert prj1.connections == prj2.connections, "%s %s" % (rngclass, expr) 505 499 506 def testSaveAndLoad(self): 500 507 prj1 = neuron.Projection(self.source33, self.target33, 'oneToOne') branches/connector-class/test/pcsimtests_population.py
r89 r90 296 296 297 297 def testAllToAll(self): 298 """For all connections created with "allToAll" it should be possible to obtain the weight using pyneuron.getWeight()"""298 """For all connections created with "allToAll" it should be possible to obtain the weights""" 299 299 for srcP in [self.source5, self.source22]: 300 300 for tgtP in [self.target6, self.target33]: … … 310 310 311 311 def testFixedProbability(self): 312 """For all connections created with "fixedProbability" it should be possible to obtain the weight using pyneuron.getWeight()"""312 """For all connections created with "fixedProbability" ...""" 313 313 for srcP in [self.source5, self.source22]: 314 314 for tgtP in [self.target6, self.target33]: … … 317 317 assert (0 < len(prj1) < len(srcP)*len(tgtP)) and (0 < len(prj2) < len(srcP)*len(tgtP)) 318 318 319 def test oneToOne(self):320 """For all connections created with "OneToOne" it should be possible to obtain the weight using pyneuron.getWeight()"""319 def testOneToOne(self): 320 """For all connections created with "OneToOne" ...""" 321 321 prj1 = Projection(self.source33, self.target33, 'oneToOne') 322 322 prj2 = Projection(self.source33, self.target33, OneToOneConnector()) … … 324 324 assert len(prj2) == self.source33.size 325 325 326 def test distantDependentProbability(self):327 """For all connections created with "distanceDependentProbability" it should be possible to obtain the weight using pyneuron.getWeight()"""326 def testDistantDependentProbability(self): 327 """For all connections created with "distanceDependentProbability" ...""" 328 328 # Test should be improved..." 329 329 distrib_Numpy = random.RandomDistribution(random.NumpyRNG(12345),'uniform',(0,1))

