Connectors API Reference
This page provides API reference documentation for the Connectors module, which contains classes and functions for creating complex connectivity patterns in BMTK networks.
Utility Functions
bmtool.connectors.num_prop(ratio, N)
Calculate numbers of total N in proportion to ratio.
Parameters:
ratio : array-like Proportions to distribute N across. N : int Total number to distribute.
Returns:
numpy.ndarray Array of integers that sum to N, proportionally distributed according to ratio.
Source code in bmtool/connectors.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
bmtool.connectors.decision(prob, size=None, rng=None)
Make random decision(s) based on input probability.
Parameters:
prob : float Probability threshold between 0 and 1. size : int or tuple, optional Size of the output array. If None, a single decision is returned. rng : numpy.random.Generator, optional Random number generator. If None, uses the default generator.
Returns:
bool or numpy.ndarray Boolean result(s) of the random decision(s). True if the random number is less than prob, False otherwise.
Source code in bmtool/connectors.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
bmtool.connectors.decisions(prob, rng=None)
Make multiple random decisions based on input probabilities.
Parameters:
prob : array-like Array of probability thresholds between 0 and 1. rng : numpy.random.Generator, optional Random number generator. If None, uses the default generator.
Returns:
numpy.ndarray Boolean array with the same shape as prob, containing results of the random decisions.
Source code in bmtool/connectors.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
bmtool.connectors.euclid_dist(p1, p2)
Euclidean distance between two points p1, p2: Coordinates in numpy array
Source code in bmtool/connectors.py
94 95 96 97 98 99 100 | |
bmtool.connectors.spherical_dist(node1, node2)
Spherical distance between two input nodes
Source code in bmtool/connectors.py
103 104 105 | |
bmtool.connectors.cylindrical_dist_z(node1, node2)
Cylindircal distance between two input nodes (ignoring z-axis)
Source code in bmtool/connectors.py
108 109 110 | |
Probability Functions
bmtool.connectors.ProbabilityFunction
Bases: ABC
Abstract base class for connection probability function
Source code in bmtool/connectors.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |
__call__(*arg, **kwargs)
abstractmethod
Return probability within [0, 1] for single input
Source code in bmtool/connectors.py
122 123 124 125 | |
decisions(*arg, **kwargs)
abstractmethod
Return bool array of decisions according probability
Source code in bmtool/connectors.py
127 128 129 130 | |
probability(*arg, **kwargs)
abstractmethod
Allow numpy array input and return probability in numpy array
Source code in bmtool/connectors.py
117 118 119 120 | |
bmtool.connectors.DistantDependentProbability
Bases: ProbabilityFunction
Base class for distance dependent probability
Source code in bmtool/connectors.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
__call__(dist, *arg, **kwargs)
Return probability for single distance input
Source code in bmtool/connectors.py
140 141 142 143 144 145 | |
decisions(dist, rng=None)
Return bool array of decisions given distance array
Source code in bmtool/connectors.py
147 148 149 150 151 152 153 154 155 156 | |
bmtool.connectors.UniformInRange
Bases: DistantDependentProbability
Constant probability within a distance range
Source code in bmtool/connectors.py
159 160 161 162 163 164 165 166 167 168 169 | |
bmtool.connectors.gaussian(x, mean=0.0, stdev=1.0, pmax=NORM_COEF)
Gaussian function. Default is the PDF of standard normal distribution
Source code in bmtool/connectors.py
175 176 177 178 | |
bmtool.connectors.GaussianDropoff
Bases: DistantDependentProbability
Connection probability class that follows a Gaussian function of distance.
This class calculates connection probabilities using a Gaussian function of the distance between cells, with options for spherical or cylindrical metrics.
Parameters:
mean : float, optional Mean parameter of the Gaussian function, typically 0 for peak at origin. stdev : float, optional Standard deviation parameter controlling the width of the Gaussian. min_dist : float, optional Minimum distance for connections. Below this distance, probability is zero. max_dist : float, optional Maximum distance for connections. Above this distance, probability is zero. pmax : float, optional Maximum probability value at the peak of the Gaussian function. ptotal : float, optional Overall connection probability within the specified distance range. If provided, pmax is calculated to achieve this overall probability. ptotal_dist_range : tuple, optional Distance range (min_dist, max_dist) for calculating pmax when ptotal is provided. dist_type : str, optional Distance metric to use, either 'spherical' (default) or 'cylindrical'.
Notes:
When ptotal is specified, the maximum probability (pmax) is calculated to achieve the desired overall connection probability within the specified distance range, assuming homogeneous cell density.
Source code in bmtool/connectors.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 | |
calc_pmax_from_ptotal()
Calculate the pmax value such that the expected overall connection
probability to all possible targets within the distance range [r1, r2]=
ptotal_dist_range equals ptotal, assuming homogeneous cell density.
That is, integral_r1^r2 {g(r)p(r)dr} = ptotal, where g is the Gaussian
function with pmax, p(r) is the cell density per unit distance at r
normalized by total cell number within the distance range.
For cylindrical distance, p(r) = 2 * r / (r2^2 - r1^2)
For spherical distance, p(r) = 3 * r^2 / (r2^3 - r1^3)
The solution has a closed form except that te error function erf is in
the expression, but only when resulting pmax <= 1.
Caveat: When the calculated pmax > 1, the actual overall probability will be lower than expected and all cells within certain distance will be always connected. This usually happens when the distance range is set too wide. Because a large population will be included for evaluating ptotal, and there will be a significant drop in the Gaussian function as distance gets further. So, a large pmax will be required to achieve the desired ptotal.
Source code in bmtool/connectors.py
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | |
compute_ptotal_integral(num_points=1000)
Compute the total integrated probability by numerically integrating the Gaussian probability function over the ptotal_dist_range.
This is useful when ptotal was not explicitly set and needs to be calculated from the distribution parameters (pmax, stdev, etc.).
Parameters:
num_points : int, optional Number of points to use for numerical integration (default: 1000).
Returns:
float The integrated total probability over the ptotal_dist_range.
Notes:
For cylindrical distance: integrates p(r) * 2πr over the range, normalized by the total cylindrical area. For spherical distance: integrates p(r) * 4πr² over the range, normalized by the total spherical volume.
Source code in bmtool/connectors.py
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | |
set_probability_func()
Set up function for calculating probability
Source code in bmtool/connectors.py
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 | |
bmtool.connectors.NormalizedReciprocalRate
Bases: ProbabilityFunction
Reciprocal connection probability given normalized reciprocal rate. Normalized reciprocal rate is defined as the ratio between the reciprocal connection probability and the connection probability for a randomly connected network where the two unidirectional connections between any pair of neurons are independent. NRR = pr / (p0 * p1)
Parameters: NRR: a constant or distance dependent function for normalized reciprocal rate. When being a function, it should be accept vectorized input. Returns: A callable object that returns the probability value.
Source code in bmtool/connectors.py
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 | |
__call__(dist, p0, p1, *arg, **kwargs)
Return probability for single distance input
Source code in bmtool/connectors.py
384 385 386 | |
decisions(dist, p0, p1, cond=None, rng=None)
Return bool array of decisions dist: distance (scalar or array). Will be ignored if NRR is constant. p0, p1: forward and backward probability (scalar or array) cond: A tuple (direction, array of outcomes) representing the condition. Conditional probability will be returned if specified. The condition event is determined by connection direction (0 for forward, or 1 for backward) and outcomes (bool array of whether connection exists). rng : numpy.random.Generator, optional Random number generator. If None, uses the default generator.
Source code in bmtool/connectors.py
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 | |
probability(dist, p0, p1)
Allow numpy array input and return probability in numpy array
Source code in bmtool/connectors.py
380 381 382 | |
Connector Base Classes
bmtool.connectors.AbstractConnector
Bases: ABC
Abstract base class for connectors
Source code in bmtool/connectors.py
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 | |
constant_function(val)
staticmethod
Convert a constant to a constant function
Source code in bmtool/connectors.py
427 428 429 430 431 432 433 434 | |
edge_params(**kwargs)
abstractmethod
Create the arguments for BMTK add_edges() method including the
connection_rule method.
Source code in bmtool/connectors.py
421 422 423 424 425 | |
setup_nodes(source=None, target=None)
abstractmethod
After network nodes are added to the BMTK network. Pass in the Nodepool objects of source and target nodes using this method. Must run this before building connections.
Source code in bmtool/connectors.py
414 415 416 417 418 419 | |
bmtool.connectors.is_same_pop(source, target, quick=False)
Check whether two NodePool objects direct to the same population
Source code in bmtool/connectors.py
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 | |
bmtool.connectors.Timer
Bases: object
Source code in bmtool/connectors.py
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 | |
bmtool.connectors.pr_2_rho(p0, p1, pr)
Calculate correlation coefficient rho given reciprocal probability pr
Source code in bmtool/connectors.py
480 481 482 483 484 485 | |
bmtool.connectors.rho_2_pr(p0, p1, rho)
Calculate reciprocal probability pr given correlation coefficient rho
Source code in bmtool/connectors.py
488 489 490 491 492 493 494 495 496 497 498 499 500 | |
Connector Implementations
bmtool.connectors.ReciprocalConnector
Bases: AbstractConnector
Object for buiilding connections in bmtk network model with reciprocal probability within a single population (or between two populations).
Algorithm: Create random connection for every pair of cells independently, following a bivariate Bernoulli distribution. Each variable is 0 or 1, whether a connection exists in a forward or backward direction. There are four possible outcomes for each pair, no connection, unidirectional connection in two ways, and reciprocal connection. The probability of each outcome forms a contingency table. b a c k w a r d f --------------- o | | 0 | 1 | The total forward connection probability is r |---|-----|-----| p0 = p10 + p11 w | 0 | p00 | p01 | The total backward connection probability is a |---|-----|-----| p1 = p01 + p11 r | 1 | p10 | p11 | The reciprocal connection probability is d --------------- pr = p11 The distribution can be characterized by three parameters, p0, p1, pr. pr = p0 * p1 when two directions are independent. The correlation coefficient rho between the two has a relation with pr as follow. rho = (pr-p0p1) / (p0(1-p0)p1(1-p1))^(1/2) Generating random outcome consists of two steps. First draw random outcome for forward connection with probability p0. Then draw backward outcome following a conditional probability given the forward outcome, represented by p0, p1, and either pr or rho.
Use with BMTK: 1. Create this object with parameters.
connector = ReciprocalConnector(**parameters)
2. After network nodes are added to the BMTK network. Pass in the
Nodepool objects of source and target nodes using setup_nodes() method.
source = net.nodes(**source_filter)
target = net.nodes(**target_filter)
connector.setup_nodes(source, target)
3. Use edge_params() method to get the arguments for BMTK add_edges()
method including the `connection_rule` method.
net.add_edges(**connector.edge_params(),
**other_source_to_target_edge_properties)
If the source and target are two different populations, do this again
for the backward connections (from target to source population).
net.add_edges(**connector.edge_params(),
**other_target_to_source_edge_properties)
4. When executing net.build(), BMTK uses built-in `one_to_all` iterator
that calls the make_forward_connection() method to build connections
from source to target. If the two are different populations,
`all_to_one` iterator that calls the make_backward_connection() method
is then used to build connections from target to source.
During the initial iteration when make_forward_connection() is called,
the algorithm is run to generate a connection matrix for both forward
and backward connections. In the iterations afterward, it's only
assigning the generated connections in BMTK.
Parameters:
p0, p1: Probability of forward and backward connection. It can be a
constant or a deterministic function whose value must be within
range [0, 1], otherwise incorrect value may occur in the algorithm.
When p0, p1 are constant, the connection is homogenous.
symmetric_p1: Whether p0 and p1 are identical. When the probabilities
are equal for forward and backward connections, set this to True,
Argument p1 will be ignored. This is forced to be True when the
population is recurrent, i.e., the source and target are the same.
This is forced to be False if symmetric_p1_arg is False.
p0_arg, p1_arg: Input argument(s) for p0 and p1 function, e.g.,
p0(p0_arg). It can be a constant or a deterministic function whose
input arguments are two node objects in BMTK, e.g.,
p0_arg(src_node,trg_node), p1_arg(trg_node,src_node). The latter
has reversed order since it's for backward connection. They are
usually distance between two nodes which is used for distance
dependent connection probability, where the order does not matter.
When p0 and p1 does not need inputs arguments, set p0_arg and
p1_arg to None as so by default. Functions p0 and p1 need to accept
one unused positional argument as placeholder, e.g., p0(args), so
it does not raise an error when p0(None) is called.
symmetric_p1_arg: Whether p0_arg and p1_arg are identical. If this is
set to True, argument p1_arg will be ignored. This is forced to be
True when the population is recurrent.
pr, pr_arg: Probability of reciprocal connection and its first input
argument when it is a function, similar to p0, p0_arg, p1, p1_arg.
It can be a function when it has an explicit relation with some node
properties such as distance. A function pr requires two additional
positional arguments p0 and p1 even if they are not used, i.e.,
pr(pr_arg, p0, p1), just in case pr is dependent on p0 and p1, e.g.,
when normalized reciprocal rate NRR = pr/(p0p1) is given.
When pr_arg is a string, the same value as p1_arg will be used for
pr_arg if the string contains '1', e.g., '1', 'p1'. Otherwise, e.g.,
'', '0', 'p0', p0_arg will be used for pr_arg. Specifying this can
avoid recomputing pr_arg when it's given by p0_arg or p1_arg.
estimate_rho: Whether estimate rho that result in an overall pr. This
is forced to be False if pr is a function or if rho is specified.
To estimate rho, all the pairs with possible connections, meaning
p0 and p1 are both non-zero for these pairs, are used to estimate
a value of rho that will result in an expected number of reciprocal
connections with the given pr. Note that pr is not over all pairs
of source and target cells but only those has a chance to connect,
e.g., for only pair of cells within some distance range. The
estimation is done before generating random connections. The values
of p0, p0_arg, p1, p1_arg can be cached during estimation of rho
and retrieved when generating random connections for performance.
dist_range_forward: If specified, when estimating rho, consider only
cell pairs whose distance (p0_arg) is within the specified range.
dist_range_backward: Similar to dist_range_forward but consider
backward distance range (p1_arg) instead. If both are specified,
consider only cell pairs whose both distances are within range. If
neither is specified, infer valid pairs by non-zero connection
probability.
rho: The correlation coefficient rho. When specified, do not estimate
it but instead use the given value throughout, pr will not be used.
In cases where both p0 and p1 are simple functions, i.e., are
constant on their support, e.g., function UniformInRange(), the
estimation of rho will be equal to pr_2_rho(p0, p1, pr) where p0,
p1 are non-zero. Estimation is not necessary. Directly set rho.
n_syn0, n_syn1: Number of synapses in the forward and backward
connection if connected. It can be a constant or a (deterministic
or random) function whose input arguments are two node objects in
BMTK like p0_arg, p1_arg. n_syn1 is force to be the same as n_syn0
when the population is recurrent. Warning: The number must not be
greater than 255 since it will be converted to uint8 when written
into the connection matrix to reduce memory consumption.
autapses: Whether to allow connecting a cell to itself. Default: False.
This is ignored when the population is not recurrent.
quick_pop_check: Whether to use quick method to check if source and
target populations are the same. Default: False.
Quick method checks only whether filter conditions match.
Strict method checks whether all node id's match considering order.
cache_data: Whether to cache the values of p0, p0_arg, p1, p1_arg
during estimation of rho. This improves performance when
estimate_rho is True while not creating a significant overhead in
the opposite case. However, it requires large memory allocation
as the population size grows. Set it to False if there is a memory
issue.
rng: Random number generator (numpy.random.Generator) used for
stochastic connection decisions in both forward and backward
directions. Provide a seeded generator for reproducible
connectivity. If None (default), fall back to the module-level
default RNG returned by _get_default_rng().
save_report: Whether to save connection report to CSV file.
report_name: Filename for connection report. If None, uses the
module-level report_name.
verbose: Whether show verbose information in console.
Returns: An object that works with BMTK to build edges in a network.
Important attributes: vars: Dictionary that stores part of the original input parameters. source, target: NodePool objects for the source and target populations. recurrent: Whether the source and target populations are the same. callable_set: Set of arguments that are functions but not constants. cache: ConnectorCache object for caching data. conn_mat: Connection matrix stage: Indicator of stage. 0 for forward and 1 for backward connection. conn_prop: List of two dictionaries that stores properties of connected pairs, for forward and backward connections respectively. In each dictionary, each key is the source node id and the value is a dictionary, where each key is the target node id that the source node connects to, and the value is the value of p0_arg or p1_arg. Example: [{sid0: {tid0: p0_arg0, tid1: p0_arg1, ...}, sid1: {...}, sid2: {...}, ... }, {tid2: {sid3: p1_arg0, sid4: p1_arg1, ...}, tid3: {...}, tid4: {...}, ... }] This is useful when properties of edges such as distance is used to determine other edge properties such as delay. So the distance does not need to be calculated repeatedly. The connector can be passed as an argument for the functions that generates additional edge properties, so that they can access the information here.
Source code in bmtool/connectors.py
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 | |
add_conn_prop(src, trg, prop, stage=0)
Store p0_arg and p1_arg for a connected pair
Source code in bmtool/connectors.py
964 965 966 967 968 969 970 971 972 | |
calc_pair(i, j)
Calculate intermediate data that can be cached
Source code in bmtool/connectors.py
911 912 913 914 915 916 917 918 919 | |
connection_number()
Return the number of the following: n_conn: connected pairs [forward, (backward,) reciprocal] n_poss: possible connections (prob>0) [forward, (backward, reciprocal)] n_pair: pairs of cells proportion: of connections in possible and total pairs
Source code in bmtool/connectors.py
1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 | |
connection_number_info()
Print connection numbers after connections built
Source code in bmtool/connectors.py
1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 | |
edge_params()
Create the arguments for BMTK add_edges() method
Source code in bmtool/connectors.py
782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 | |
free_memory()
Free up memory after connections are built
Source code in bmtool/connectors.py
1202 1203 1204 1205 1206 1207 | |
get_conn_prop(sid, tid)
Get stored value given node ids in a connection
Source code in bmtool/connectors.py
974 975 976 | |
get_nodes_info()
Get strings with source and target population information
Source code in bmtool/connectors.py
1210 1211 1212 1213 1214 | |
initial_all_to_all()
The major part of the algorithm run at beginning of BMTK iterator
Source code in bmtool/connectors.py
1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 | |
iterate_pairs()
Generate indices of source and target for each case
Source code in bmtool/connectors.py
895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 | |
make_backward_connection(targets, source, *args, **kwargs)
Function to be called by BMTK iterator for backward connection
Source code in bmtool/connectors.py
1194 1195 1196 1197 1198 1199 1200 | |
make_connection()
Assign number of synapses per iteration. Use iterator one_to_all for forward and all_to_one for backward.
Source code in bmtool/connectors.py
1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 | |
make_forward_connection(source, targets, *args, **kwargs)
Function to be called by BMTK iterator for forward connection
Source code in bmtool/connectors.py
1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 | |
node_2_idx_input(var_func, reverse=False)
Convert a function that accept nodes as input to accept indices as input
Source code in bmtool/connectors.py
881 882 883 884 885 886 887 888 889 890 891 892 893 | |
save_connection_report()
Save connections into a CSV file to be read from later
Source code in bmtool/connectors.py
1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 | |
setup_conditional_backward_probability()
Create a function that calculates the conditional probability of backward connection given the forward connection outcome 'cond'
Source code in bmtool/connectors.py
921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 | |
setup_nodes(source=None, target=None)
Must run this before building connections
Source code in bmtool/connectors.py
734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 | |
bmtool.connectors.UnidirectionConnector
Bases: AbstractConnector
Object for building unidirectional connections in bmtk network model with given probability within a single population (or between two populations).
Parameters:
p, p_arg: Probability of forward connection and its input argument when
it is a function, similar to p0, p0_arg in ReciprocalConnector. It
can be a constant or a deterministic function whose value must be
within range [0, 1]. When p is constant, the connection is
homogenous.
n_syn: Number of synapses in the forward connection if connected. It
can be a constant or a (deterministic or random) function whose
input arguments are two node objects in BMTK like p_arg.
rng: Random number generator (numpy.random.Generator) used for
stochastic connection decisions. Provide a seeded generator for
reproducible connectivity. If None (default), fall back to the
module-level default RNG returned by _get_default_rng().
save_report: Whether to save connection report to CSV file.
report_name: Filename for connection report. If None, uses the
module-level report_name.
verbose: Whether show verbose information in console.
Returns: An object that works with BMTK to build edges in a network.
Important attributes: vars: Dictionary that stores part of the original input parameters. source, target: NodePool objects for the source and target populations. conn_prop: A dictionaries that stores properties of connected pairs. Each key is the source node id and the value is a dictionary, where each key is the target node id that the source node connects to, and the value is the value of p_arg. Example: {sid0: {tid0: p_arg0, tid1: p_arg1, ...}, sid1: {...}, sid2: {...}, ... } This is useful in similar manner as in ReciprocalConnector.
Source code in bmtool/connectors.py
1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 | |
add_conn_prop(sid, tid, prop)
Store p0_arg and p1_arg for a connected pair
Source code in bmtool/connectors.py
1374 1375 1376 1377 | |
connection_number_info()
Print connection numbers after connections built
Source code in bmtool/connectors.py
1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 | |
edge_params()
Create the arguments for BMTK add_edges() method
Source code in bmtool/connectors.py
1362 1363 1364 1365 1366 1367 1368 1369 1370 | |
get_conn_prop(sid, tid)
Get stored value given node ids in a connection
Source code in bmtool/connectors.py
1379 1380 1381 | |
get_nodes_info()
Get strings with source and target population information
Source code in bmtool/connectors.py
1436 1437 1438 1439 1440 | |
make_connection(source, target, *args, **kwargs)
Assign number of synapses per iteration using one_to_one iterator
Source code in bmtool/connectors.py
1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 | |
save_connection_report()
Save connections into a CSV file to be read from later
Source code in bmtool/connectors.py
1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 | |
setup_nodes(source=None, target=None)
Must run this before building connections
Source code in bmtool/connectors.py
1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 | |
setup_variables()
Make constant variables constant functions
Source code in bmtool/connectors.py
1383 1384 1385 1386 1387 1388 1389 | |
bmtool.connectors.GapJunction
Bases: UnidirectionConnector
Object for buiilding gap junction connections in bmtk network model with given probabilities within a single population which is uncorrelated with the recurrent chemical synapses in this population.
Parameters:
p, p_arg: Probability of forward connection and its input argument when
it is a function, similar to p0, p0_arg in ReciprocalConnector. It
can be a constant or a deterministic function whose value must be
within range [0, 1]. When p is constant, the connection is
homogenous.
rng: Random number generator (numpy.random.Generator) used for
stochastic gap-junction decisions. Provide a seeded generator for
reproducible connectivity. If None (default), fall back to the
module-level default RNG returned by _get_default_rng().
save_report: Whether to save connection report to CSV file.
report_name: Filename for connection report. If None, uses the
module-level report_name.
verbose: Whether show verbose information in console.
Returns: An object that works with BMTK to build edges in a network.
Important attributes:
Similar to UnidirectionConnector.
Source code in bmtool/connectors.py
1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 | |
make_connection(source, target, *args, **kwargs)
Assign gap junction per iteration using one_to_one iterator
Source code in bmtool/connectors.py
1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 | |
save_connection_report()
Save connections into a CSV file to be read from later
Source code in bmtool/connectors.py
1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 | |
bmtool.connectors.CorrelatedGapJunction
Bases: GapJunction
Object for buiilding gap junction connections in bmtk network model with given probabilities within a single population which could be correlated with the recurrent chemical synapses in this population.
Parameters:
p_non, p_uni, p_rec: Probabilities of gap junction connection for each
pair of cells given the following three conditions of chemical
synaptic connections between them, no connection, unidirectional,
and reciprocal, respectively. It can be a constant or a
deterministic function whose value must be within range [0, 1].
p_arg: Input argument for p_non, p_uni, or p_rec, when any of them is a
function, similar to p0_arg, p1_arg in ReciprocalConnector.
connector: Connector object used to generate the chemical synapses of
within this population, which contains the connection information
in its attribute conn_prop. So this connector should have
generated the chemical synapses before generating the gap junction.
rng: Random number generator (numpy.random.Generator) used for
stochastic gap-junction decisions. Provide a seeded generator for
reproducible connectivity. If None (default), fall back to the
module-level default RNG returned by _get_default_rng().
save_report: Whether to save connection report to CSV file.
report_name: Filename for connection report. If None, uses the
module-level report_name.
verbose: Whether show verbose information in console.
Returns: An object that works with BMTK to build edges in a network.
Important attributes:
Similar to UnidirectionConnector.
Source code in bmtool/connectors.py
1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 | |
make_connection(source, target, *args, **kwargs)
Assign gap junction per iteration using one_to_one iterator
Source code in bmtool/connectors.py
1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 | |
bmtool.connectors.OneToOneSequentialConnector
Bases: AbstractConnector
Object for buiilding one to one correspondence connections in bmtk network model with between two populations. One of the population can consist of multiple sub-populations. These sub-populations need to be added sequentially using setup_nodes() and edge_params() methods followed by BMTK add_edges() method. For example, to connect 30 nodes in population A to 30 nodes in populations B1, B2, B3, each with 10 nodes, set up as follows. connector = OneToOneSequentialConnector(parameters) connector.setup_nodes(source=A, target=B1) net.add_edges(connector.edge_params()) connector.setup_nodes(target=B2) net.add_edges(connector.edge_params()) connector.setup_nodes(target=B3) net.add_edges(connector.edge_params()) After BMTK executes net.build(), the first 10 nodes in A will connect one- to-one to the 10 nodes in B1, then the 11 to 20-th nodes to those in B2, finally the 21 to 30-th nodes to those in B3. This connector is useful for creating input drives to a population. Each node in it receives an independent drive from a unique source node.
Parameters: n_syn: Number of synapses in each connection. It accepts only constant for now. partition_source: Whether the source population consists of multiple sub-populations. By default, the source has one population, and the target can have multiple sub-populations. If set to true, the source can have multiple sub-populations and the target has only one population. verbose: Whether show verbose information in console.
Returns: An object that works with BMTK to build edges in a network.
Important attributes: source: NodePool object for the single population. targets: List of NodePool objects for the multiple sub-populations.
Source code in bmtool/connectors.py
2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 | |
edge_params(target_pop_idx=-1)
Create the arguments for BMTK add_edges() method
Source code in bmtool/connectors.py
2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 | |
get_nodes_info(target_pop_idx=-1)
Get strings with source and target population information
Source code in bmtool/connectors.py
2494 2495 2496 2497 2498 2499 | |
make_connection(source, targets, *args, **kwargs)
Assign one connection per iteration using all_to_one iterator
Source code in bmtool/connectors.py
2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 | |
setup_nodes(source=None, target=None)
Must run this before building connections
Source code in bmtool/connectors.py
2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 | |
Synapse Helper Functions
bmtool.connectors.syn_const_delay(source=None, target=None, dist=100, min_delay=SYN_MIN_DELAY, velocity=SYN_VELOCITY, fluc_stdev=FLUC_STDEV, delay_bound=(DELAY_LOWBOUND, DELAY_UPBOUND), connector=None, rng=None, **kwargs)
Synapse delay approximately constant with some random fluctuation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
optional
|
Included for API consistency; not used in this implementation. |
None
|
target
|
optional
|
Included for API consistency; not used in this implementation. |
None
|
dist
|
float
|
Distance between source and target (micron). |
100
|
min_delay
|
float
|
Minimum delay (ms). |
SYN_MIN_DELAY
|
velocity
|
float
|
Synapse conduction velocity (micron/ms). |
SYN_VELOCITY
|
fluc_stdev
|
float
|
Standard deviation of random Gaussian fluctuation (ms). |
FLUC_STDEV
|
delay_bound
|
tuple of (float, float)
|
Lower and upper bounds for the delay (ms). |
(DELAY_LOWBOUND, DELAY_UPBOUND)
|
connector
|
optional
|
Included for API consistency; not used in this implementation. |
None
|
rng
|
Generator
|
Random number generator. If None, uses the default generator. |
None
|
Source code in bmtool/connectors.py
2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 | |
bmtool.connectors.syn_dist_delay_feng(source, target, min_delay=SYN_MIN_DELAY, velocity=SYN_VELOCITY, fluc_stdev=FLUC_STDEV, delay_bound=(DELAY_LOWBOUND, DELAY_UPBOUND), connector=None, rng=None, **kwargs)
Synpase delay linearly dependent on distance. min_delay: minimum delay (ms) velocity: synapse conduction velocity (micron/ms) fluc_stdev: standard deviation of random Gaussian fluctuation (ms) delay_bound: (lower, upper) bounds of delay (ms) connector: connector object from which to read distance rng : numpy.random.Generator, optional Random number generator. If None, uses the default generator.
Source code in bmtool/connectors.py
2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 | |
bmtool.connectors.syn_section_PN(source, target, p=0.9, sec_id=(1, 2), sec_x=(0.4, 0.6), rng=None, **kwargs)
Synapse location follows a Bernoulli distribution, with probability p to obtain the former in sec_id and sec_x
Source code in bmtool/connectors.py
2581 2582 2583 2584 2585 2586 | |
bmtool.connectors.syn_const_delay_feng_section_PN(source, target, p=0.9, sec_id=(1, 2), sec_x=(0.4, 0.6), rng=None, **kwargs)
Assign both synapse delay and location with constant distance assumed
Source code in bmtool/connectors.py
2589 2590 2591 2592 2593 2594 2595 | |
bmtool.connectors.syn_dist_delay_feng_section_PN(source, target, p=0.9, sec_id=(1, 2), sec_x=(0.4, 0.6), rng=None, **kwargs)
Assign both synapse delay and location
Source code in bmtool/connectors.py
2598 2599 2600 2601 2602 2603 2604 | |
bmtool.connectors.syn_uniform_delay_section(source, target, low=DELAY_LOWBOUND, high=DELAY_UPBOUND, rng=None, **kwargs)
Source code in bmtool/connectors.py
2607 2608 2609 | |