References
=== Analysis functions ===
Helper classes and functions to perform analysis on fitted models
PklHandler
Helper class to handle metadata and fit data from pkl file
Source code in pytau/changepoint_analysis.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 |
|
__init__(file_path)
Initialize PklHandler class
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
str
|
Path to pkl file |
required |
Source code in pytau/changepoint_analysis.py
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 |
|
calc_significant_neurons_firing(state_firing, p_val=0.05)
Calculate significant changes in firing rate between states Iterate ANOVA over neurons for all states With Bonferroni correction
Args state_firing (3D Numpy array): trials x states x nrns p_val (float, optional): p-value to use for significance. Defaults to 0.05.
Returns:
Name | Type | Description |
---|---|---|
anova_p_val_array |
1D Numpy array
|
p-values for each neuron |
anova_sig_neurons |
1D Numpy array
|
indices of significant neurons |
Source code in pytau/changepoint_analysis.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
|
calc_significant_neurons_snippets(transition_snips, p_val=0.05)
Calculate pairwise t-tests to detect differences between each transition With Bonferroni correction
Args transition_snips (4D Numpy array): trials x nrns x bins x transitions p_val (float, optional): p-value to use for significance. Defaults to 0.05.
Returns:
Name | Type | Description |
---|---|---|
anova_p_val_array |
(neurons, transition)
|
p-values for each neuron |
anova_sig_neurons |
(neurons, transition)
|
indices of significant neurons |
Source code in pytau/changepoint_analysis.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
|
get_state_firing(spike_array, tau_array)
Calculate firing rates within states given changepoint positions on data
Parameters:
Name | Type | Description | Default |
---|---|---|---|
spike_array
|
3D Numpy array
|
trials x nrns x bins |
required |
tau_array
|
2D Numpy array
|
trials x switchpoints |
required |
Returns:
Name | Type | Description |
---|---|---|
state_firing |
3D Numpy array
|
trials x states x nrns |
Source code in pytau/changepoint_analysis.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
|
get_transition_snips(spike_array, tau_array, window_radius=300)
Get snippets of activty around changepoints for each trial
Parameters:
Name | Type | Description | Default |
---|---|---|---|
spike_array
|
3D Numpy array
|
trials x nrns x bins |
required |
tau_array
|
2D Numpy array
|
trials x switchpoints |
required |
Returns:
Type | Description |
---|---|
Numpy array: Transition snippets : trials x nrns x bins x transitions |
Make sure none of the snippets are outside the bounds of the data
Source code in pytau/changepoint_analysis.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
|
=== I/O functions ===
Pipeline to handle model fitting from data extraction to saving results
DatabaseHandler
Class to handle transactions with model database
Source code in pytau/changepoint_io.py
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 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 |
|
__init__()
Initialize DatabaseHandler class
Source code in pytau/changepoint_io.py
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 |
|
aggregate_metadata()
Collects information regarding data and current "experiment"
Raises:
Type | Description |
---|---|
Exception
|
If 'external_metadata' has not been ingested, that needs to be done first |
Returns:
Name | Type | Description |
---|---|---|
dict |
Dictionary of metadata given to FitHandler class |
Source code in pytau/changepoint_io.py
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 |
|
check_exists()
Check if the given fit already exists in database
Returns:
Name | Type | Description |
---|---|---|
bool |
Boolean for whether fit already exists or not |
Source code in pytau/changepoint_io.py
601 602 603 604 605 606 607 608 |
|
check_mismatched_paths()
Check if there are any mismatched pkl files between database and directory
Returns:
Name | Type | Description |
---|---|---|
pandas dataframe: Dataframe containing rows for which pkl file not present |
||
list |
pkl files which cannot be matched to model in database |
|
list |
all files in save directory |
Source code in pytau/changepoint_io.py
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 |
|
clear_mismatched_paths()
Remove mismatched files and rows in database
i.e. Remove 1) Files for which no entry can be found in database 2) Database entries for which no corresponding file can be found
Source code in pytau/changepoint_io.py
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 |
|
drop_duplicates()
Remove duplicated rows from database
Source code in pytau/changepoint_io.py
426 427 428 429 430 431 |
|
ingest_fit_data(met_dict)
Load external metadata
Parameters:
Name | Type | Description | Default |
---|---|---|---|
met_dict
|
dict
|
Dictionary of metadata from FitHandler class |
required |
Source code in pytau/changepoint_io.py
527 528 529 530 531 532 533 |
|
set_run_params(data_dir, experiment_name, taste_num, laser_type, region_name)
Store metadata related to inference run
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_dir
|
str
|
Path to directory containing HDF5 file |
required |
experiment_name
|
str
|
Name given to fitted batch (for metedata). Defaults to None. |
required |
taste_num
|
int
|
Index of taste to perform fit on (Corresponds to INDEX of taste in spike array, not actual dig_ins) |
required |
laser_type
|
None or str
|
None, 'on', or 'off' (For a laser session, which set of trials are wanted, None indicated return all trials) |
required |
region_name
|
str
|
Region on which to perform fit on (must match regions in .info file) |
required |
Source code in pytau/changepoint_io.py
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 |
|
show_duplicates(keep='first')
Find duplicates in database
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keep
|
str
|
Which duplicate to keep (refer to pandas duplicated). Defaults to 'first'. |
'first'
|
Returns:
Type | Description |
---|---|
pandas dataframe: Dataframe containing duplicated rows |
|
pandas series : Indices of duplicated rows |
Source code in pytau/changepoint_io.py
411 412 413 414 415 416 417 418 419 420 421 422 423 424 |
|
write_to_database()
Write out metadata to database
Source code in pytau/changepoint_io.py
588 589 590 591 592 593 594 595 596 597 598 599 |
|
write_updated_database()
Can be called following clear_mismatched_entries to update current database
Source code in pytau/changepoint_io.py
469 470 471 472 473 474 475 476 477 478 479 480 481 |
|
FitHandler
Class to handle pipeline of model fitting including: 1) Loading data 2) Preprocessing loaded arrays 3) Fitting model 4) Writing out fitted parameters to pkl file
Source code in pytau/changepoint_io.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 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 361 362 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 |
|
__init__(data_dir, taste_num, region_name, laser_type=None, experiment_name=None, model_params_path=None, preprocess_params_path=None)
Initialize FitHandler class
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_dir
|
str
|
Path to directory containing HDF5 file |
required |
taste_num
|
int
|
Index of taste to perform fit on (Corresponds to INDEX of taste in spike array, not actual dig_ins) |
required |
region_name
|
str
|
Region on which to perform fit on (must match regions in .info file) |
required |
experiment_name
|
str
|
Name given to fitted batch (for metedata). Defaults to None. |
None
|
model_params_path
|
str
|
Path to json file containing model parameters. Defaults to None. |
None
|
preprocess_params_path
|
str
|
Path to json file containing preprocessing parameters. Defaults to None. |
None
|
Raises:
Type | Description |
---|---|
Exception
|
If "experiment_name" is None |
Exception
|
If "laser_type" is not in [None, 'on', 'off'] |
Exception
|
If "taste_num" is not integer or "all" |
Source code in pytau/changepoint_io.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
|
create_model()
Create model and save as attribute
Will check for and complete: 1) Data preprocessed 2) Model template selected
Source code in pytau/changepoint_io.py
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 |
|
inference_func_selector()
Function to return model based off of input flag
Currently hard-coded to use "advi_fit"
Source code in pytau/changepoint_io.py
251 252 253 254 255 256 |
|
load_spike_trains()
Helper function to load spike trains from data_dir using EphysData module
Source code in pytau/changepoint_io.py
262 263 264 265 266 267 268 269 270 271 272 273 |
|
model_template_selector()
Function to set model based off of input flag
Models can be set manually but it is preferred to go through model selector
Raises:
Type | Description |
---|---|
Exception
|
If self.taste_num is neither int nor str |
Source code in pytau/changepoint_io.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
|
preprocess_data()
Perform data preprocessing
Will check for and complete: 1) Raw data loaded 2) Preprocessor selected
Source code in pytau/changepoint_io.py
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
|
preprocess_selector()
Function to return preprocess function based off of input flag
Preprocessing can be set manually but it is preferred to go through preprocess selector
Raises:
Type | Description |
---|---|
Exception
|
If self.taste_num is neither int nor str |
Source code in pytau/changepoint_io.py
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
|
run_inference()
Perform inference on data
Will check for and complete: 1) Model created 2) Inference function selected
Source code in pytau/changepoint_io.py
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
|
save_fit_output()
Save fit output (fitted data + metadata) to pkl file
Source code in pytau/changepoint_io.py
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 |
|
set_inference(inference_func)
Manually set inference function for model fit e.g.
FitHandler.set_inference(changepoint_model.advi_fit)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inference_func
|
func
|
Function to use for fitting model |
required |
Source code in pytau/changepoint_io.py
241 242 243 244 245 246 247 248 249 |
|
set_model_params(states, fit, samples, model_kwargs=None, file_path=None)
Load given params as "model_params" attribute
Parameters:
Name | Type | Description | Default |
---|---|---|---|
states
|
int
|
Number of states to use in model |
required |
fit
|
int
|
Iterations to use for model fitting (given ADVI fit) |
required |
samples
|
int
|
Number of samples to return from fitten model |
required |
model_kwargs
|
dict)
|
Additional paramters for model |
None
|
file_path
|
str
|
Path to json file containing preprocess parameters. Defaults to None. |
None
|
Source code in pytau/changepoint_io.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
|
set_model_template(model_template)
Manually set model_template for data e.g.
FitHandler.set_model(changepoint_model.single_taste_poisson)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_template
|
func
|
Function to generate model template for data] |
required |
Source code in pytau/changepoint_io.py
213 214 215 216 217 218 219 220 221 |
|
set_preprocess_params(time_lims, bin_width, data_transform, file_path=None)
Load given params as "preprocess_params" attribute
Parameters:
Name | Type | Description | Default |
---|---|---|---|
time_lims
|
array / tuple / list
|
Start and end of where to cut spike train array |
required |
bin_width
|
int
|
Bin width for binning spikes to counts |
required |
data_transform
|
str
|
Indicator for which transformation to use (refer to changepoint_preprocess) |
required |
file_path
|
str
|
Path to json file containing preprocess parameters. Defaults to None. |
None
|
Source code in pytau/changepoint_io.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
|
set_preprocessor(preprocessing_func)
Manually set preprocessor for data e.g.
FitHandler.set_preprocessor( changepoint_preprocess.preprocess_single_taste)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
preprocessing_func
|
func
|
|
required |
Source code in pytau/changepoint_io.py
182 183 184 185 186 187 188 189 190 191 192 |
|
=== Model building functions ===
PyMC3 Blackbox Variational Inference implementation of Poisson Likelihood Changepoint for spike trains.
advi_fit(model, fit, samples)
Convenience function to perform ADVI fit on model
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
pymc3 model
|
model object to run inference on |
required |
fit
|
int
|
Number of iterationst to fit the model for |
required |
samples
|
int
|
Number of samples to draw from fitted model |
required |
Returns:
Name | Type | Description |
---|---|---|
model |
original model on which inference was run, |
|
approx |
fitted model, |
|
lambda_stack |
array containing lambda (emission) values, |
|
tau_samples,: array containing samples from changepoint distribution |
||
model.obs.observations: processed array on which fit was run |
Source code in pytau/changepoint_model.py
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 |
|
all_taste_poisson(spike_array, states, **kwargs)
** Model to fit changepoint to single taste ** ** Largely taken from "_v1/poisson_all_tastes_changepoint_model.py"
spike_array :: Shape : tastes, trials, neurons, time_bins states :: number of states to include in the model
Source code in pytau/changepoint_model.py
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 |
|
all_taste_poisson_trial_switch(spike_array, switch_components, states)
Assuming only emissions change across trials Changepoint distribution remains constant
spike_array :: Tastes x trials x nrns x time_bins states :: number of states to include in the model
Source code in pytau/changepoint_model.py
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 |
|
all_taste_poisson_varsig_fixed(spike_array, states, inds_span=1)
** Model to fit changepoint to single taste ** ** Largely taken from "_v1/poisson_all_tastes_changepoint_model.py"
spike_array :: Shape : tastes, trials, neurons, time_bins states :: number of states to include in the model
Source code in pytau/changepoint_model.py
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 |
|
compile_wait()
Function to allow waiting while a model is already fitting Wait twice because lock blips out between steps 10 secs of waiting shouldn't be a problem for long fits (~mins) And wait a random time in the beginning to stagger fits
Source code in pytau/changepoint_model.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
|
dpp_fit(model, n_chains=24, n_cores=1, tune=500, draws=500)
Convenience function to fit DPP model
Source code in pytau/changepoint_model.py
1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 |
|
extract_inferred_values(trace)
Convenience function to extract inferred values from ADVI fit
Parameters:
Name | Type | Description | Default |
---|---|---|---|
trace
|
dict
|
trace |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
dictionary of inferred values |
Source code in pytau/changepoint_model.py
1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 |
|
find_best_states(data, model_generator, n_fit, n_samples, min_states=2, max_states=10)
Convenience function to find best number of states for model
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
array
|
array on which to run inference |
required |
model_generator
|
function
|
function that generates model |
required |
n_fit
|
int
|
Number of iterationst to fit the model for |
required |
n_samples
|
int
|
Number of samples to draw from fitted model |
required |
min_states
|
int
|
Minimum number of states to test |
2
|
max_states
|
int
|
Maximum number of states to test |
10
|
Returns:
Name | Type | Description |
---|---|---|
best_model |
model with best number of states, |
|
model_list |
list of models with different number of states, |
|
elbo_values |
list of elbo values for different number of states |
Source code in pytau/changepoint_model.py
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 |
|
gaussian_changepoint_mean_2d(data_array, n_states, **kwargs)
Model for gaussian data on 2D array detecting changes only in the mean.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_array
|
2D Numpy array
|
|
required |
n_states
|
int
|
Number of states to model |
required |
Returns:
Type | Description |
---|---|
pymc3 model: Model class containing graph to run inference on |
Source code in pytau/changepoint_model.py
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 |
|
gaussian_changepoint_mean_dirichlet(data_array, max_states=15)
Model for gaussian data on 2D array detecting changes only in the mean. Number of states determined using dirichlet process prior.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_array
|
2D Numpy array
|
|
required |
max_states
|
int
|
Max number of states to include in truncated dirichlet process |
15
|
Returns:
Type | Description |
---|---|
pymc3 model: Model class containing graph to run inference on |
Source code in pytau/changepoint_model.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 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 |
|
gaussian_changepoint_mean_var_2d(data_array, n_states, **kwargs)
Model for gaussian data on 2D array detecting changes in both mean and variance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_array
|
2D Numpy array
|
|
required |
n_states
|
int
|
Number of states to model |
required |
Returns:
Type | Description |
---|---|
pymc3 model: Model class containing graph to run inference on |
Source code in pytau/changepoint_model.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
|
gen_test_array(array_size, n_states, type='poisson')
Generate test array for model fitting Last 2 dimensions consist of a single trial Time will always be last dimension
Parameters:
Name | Type | Description | Default |
---|---|---|---|
array_size
|
tuple
|
Size of array to generate |
required |
n_states
|
int
|
Number of states to generate |
required |
type
|
str
|
Type of data to generate - normal - poisson |
'poisson'
|
Source code in pytau/changepoint_model.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
|
mcmc_fit(model, samples)
Convenience function to perform ADVI fit on model
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
pymc3 model
|
model object to run inference on |
required |
samples
|
int
|
Number of samples to draw using MCMC |
required |
Returns:
Name | Type | Description |
---|---|---|
model |
original model on which inference was run, |
|
trace |
samples drawn from MCMC, |
|
lambda_stack |
array containing lambda (emission) values, |
|
tau_samples,: array containing samples from changepoint distribution |
||
model.obs.observations: processed array on which fit was run |
Source code in pytau/changepoint_model.py
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 |
|
single_taste_poisson(spike_array, states, **kwargs)
Model for changepoint on single taste
** Largely taken from "non_hardcoded_changepoint_test_3d.ipynb" ** Note : This model does not have hierarchical structure for emissions
Parameters:
Name | Type | Description | Default |
---|---|---|---|
spike_array
|
3D Numpy array
|
trials x neurons x time |
required |
states
|
int
|
Number of states to model |
required |
Returns:
Type | Description |
---|---|
pymc3 model: Model class containing graph to run inference on |
Source code in pytau/changepoint_model.py
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 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 |
|
single_taste_poisson_dirichlet(spike_array, max_states=10, **kwargs)
Model for changepoint on single taste using dirichlet process prior
Parameters:
Name | Type | Description | Default |
---|---|---|---|
spike_array
|
3D Numpy array
|
trials x neurons x time |
required |
max_states
|
int
|
Maximum number of states to model |
10
|
Returns:
Type | Description |
---|---|
pymc3 model: Model class containing graph to run inference on |
Source code in pytau/changepoint_model.py
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 361 362 363 364 365 366 367 368 |
|
single_taste_poisson_trial_switch(spike_array, switch_components, states)
Assuming only emissions change across trials Changepoint distribution remains constant
spike_array :: trials x nrns x time states :: number of states to include in the model
Source code in pytau/changepoint_model.py
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 |
|
single_taste_poisson_varsig(spike_array, states, **kwargs)
Model for changepoint on single taste **Uses variables sigmoid slope inferred from data
** Largely taken from "non_hardcoded_changepoint_test_3d.ipynb" ** Note : This model does not have hierarchical structure for emissions
Parameters:
Name | Type | Description | Default |
---|---|---|---|
spike_array
|
3D Numpy array
|
trials x neurons x time |
required |
states
|
int
|
Number of states to model |
required |
Returns:
Type | Description |
---|---|
pymc3 model: Model class containing graph to run inference on |
Source code in pytau/changepoint_model.py
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 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 |
|
single_taste_poisson_varsig_fixed(spike_array, states, inds_span=1)
Model for changepoint on single taste **Uses sigmoid with given slope
** Largely taken from "non_hardcoded_changepoint_test_3d.ipynb" ** Note : This model does not have hierarchical structure for emissions
Parameters:
Name | Type | Description | Default |
---|---|---|---|
spike_array
|
3D Numpy array
|
trials x neurons x time |
required |
states
|
int
|
Number of states to model |
required |
inds_span(float)
|
Number of indices to cover 5-95% change in sigmoid |
required |
Returns:
Type | Description |
---|---|
pymc3 model: Model class containing graph to run inference on |
Source code in pytau/changepoint_model.py
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 |
|
theano_lock_present()
Check if theano compilation lock is present
Source code in pytau/changepoint_model.py
22 23 24 25 26 |
|
var_sig_exp_tt(x, b)
x --> b -->
Source code in pytau/changepoint_model.py
430 431 432 433 434 435 |
|
var_sig_tt(x, b)
x --> b -->
Source code in pytau/changepoint_model.py
438 439 440 441 442 443 |
|
=== Preprocessing functions ===
Code to preprocess spike trains before feeding into model
preprocess_all_taste(spike_array, time_lims, bin_width, data_transform)
Preprocess array containing trials for all tastes (in blocks) concatenated
Parameters:
Name | Type | Description | Default |
---|---|---|---|
spike_array
|
4D Numpy Array
|
Taste x Trials x Neurons x Time |
required |
time_lims
|
List/Tuple/Numpy Array
|
2-element object indicating limits of array |
required |
bin_width
|
int
|
Width to use for binning |
required |
data_transform
|
str
|
Data-type to return {actual, shuffled, simulated} |
required |
Raises:
Type | Description |
---|---|
Exception
|
If transforms do not belong to ['shuffled','simulated','None',None] |
Returns:
Type | Description |
---|---|
4D Numpy Array
|
Of processed data |
Source code in pytau/changepoint_preprocess.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
|
preprocess_single_taste(spike_array, time_lims, bin_width, data_transform)
Preprocess array containing trials for all tastes (in blocks) concatenated
** Note, it may be useful to use x-arrays here to keep track of coordinates
Parameters:
Name | Type | Description | Default |
---|---|---|---|
spike_array
|
3D Numpy array
|
trials x neurons x time |
required |
time_lims
|
List/Tuple/Numpy Array
|
2-element object indicating limits of array |
required |
bin_width
|
int
|
Width to use for binning |
required |
data_transform
|
str
|
Data-type to return {actual, trial_shuffled, spike_shuffled, simulated} |
required |
Raises:
Type | Description |
---|---|
Exception
|
If transforms do not belong to |
Returns:
Type | Description |
---|---|
3D Numpy Array
|
Of processed data |
Source code in pytau/changepoint_preprocess.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
|