Method 1: Linear model mixing
This method is derived from Coleman's thesis, and
uses a mixing function with hyperparameters to be estimated using data, to construct the mixed model. There are several possible mixing functions given in the code below for a user to play with and build off of to write their own mixing function. There are also priors to choose from (in the priors.py
file) for the hyperparameters of each mixing function.
Once the mixing function has been chosen, and data supplied or simulated, the user can construct the mixed model by sampling the parameter space using the sampler wrapper below, and then building the posterior predictive distribution (PPD). This is given as
$$ p(\tilde y(g)|\theta, \mathbf{D}) = \sum_{j=1}^{M} \alpha(g; \theta_{j}) F^{N_s}(g) + (1 - \alpha(g; \theta_{j})) F^{N_l}_{l}(g), $$
where $\alpha(g; \theta_{j})$ is the chosen mixing function with hyperparameters $\theta_{j}$.
LMM
Bases: Models
, Uncertainties
Source code in samba/mixing.py
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 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 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 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 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 |
|
MAP_values(thin, g, g_data, data, sigma, plot=True)
A function to calculate the MAP values of sampled distributions of parameters. Will calculate for as many parameters as are present and return results in an array.
Example
LMM.MAP_values(thin=np.array([]), g_data=np.linspace(), g=np.linspace(), data=np.array([]), sigma=np.array([]))
Parameters:
Name | Type | Description | Default |
---|---|---|---|
thin |
ndarray
|
The array of thinned samples from the stats_chain() function. |
required |
g |
linspace
|
The input space over which the mixing is calculated. |
required |
g_data |
linspace
|
The array of input points in g for the data set. |
required |
data |
ndarray
|
The data set being used for the mixing calculation. |
required |
sigma |
ndarray
|
The data error set being used for the mixing calculation. |
required |
plot |
bool
|
The option to plot the weights over the input space in g. Default is True. |
True
|
Returns:
Name | Type | Description |
---|---|---|
map_values |
ndarray
|
The MAP values of each parameter. |
Source code in samba/mixing.py
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 |
|
__init__(loworder, highorder, error_model='informative')
This class is designed with all of the necessary functions for creating a data set, plotting it along with the true model, and calculating expansions of specific orders of the true model to mix. Dependent on the Models class to run the expansion functions.
Example
LMM(loworder=np.array([2]), highorder=np.array([2]), error_model='informative')
Parameters:
Name | Type | Description | Default |
---|---|---|---|
loworder |
(ndarray, int)
|
The truncation order to which we calculate the small-g expansion. |
required |
highorder |
(ndarray, int)
|
The truncation order to which we calculate the large-g expansion. |
required |
error_model |
str
|
The error model chosen for this calculation. Can be either 'uninformative' or 'informative'. Default is 'informative'. |
'informative'
|
Returns:
Type | Description |
---|---|
None. |
Source code in samba/mixing.py
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 |
|
add_data(g_true, g_data, data=None, sigma=None, error=None, plot=True)
A data generation function that generates data based on the g_data linspace provided (with the number of points chosen by the user) and the error desired on each point (also input by the user), or accepts the user's input of an array of data and standard deviations of the data points.
Example
LMM.add_data(g_true=np.linspace(0.0, 0.5, 100), g_data=np.linspace(0.0, 0.5, 20), error=0.01, plot=False)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
g_true |
linspace
|
The linspace desired for the true model to be calculated. |
required |
g_data |
linspace
|
The linspace input for the data to be generated within. |
required |
data |
ndarray
|
The data array entered by the user; if user wishes to generate data, this remains set to None. |
None
|
sigma |
ndarray
|
The standard deviation array entered by the user; if user wishes to generate data, this will remain set to None. |
None
|
error |
float
|
The error to put on the data set if the data set is not being given by the user. Enter in decimal form (0.01 = 1%). Default is None. |
None
|
plot |
bool
|
The option to plot the data. Default is True. |
True
|
Returns:
Name | Type | Description |
---|---|---|
data |
ndarray
|
The array of data (generated or entered by the user). |
sigma |
ndarray
|
The standard deviation at each data point (generated or entered by the user). |
Source code in samba/mixing.py
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 |
|
burnin_trace(sampler_object, nsteps)
A small function to take the burn-in samples off of the sampler chain from the LMM.mixed_model function, and to send back the trace of the sampler chain to LMM.mixed_model.
Example
LMM.burnin_trace(sampler_object=sampler_mixed, nsteps=3000)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sampler_object |
object
|
The chain sent back by the emcee sampler after it finishes running through the samples and walkers. |
required |
nsteps |
int
|
The number of steps per walker. |
required |
Returns:
Name | Type | Description |
---|---|---|
emcee_trace_mixed |
ndarray
|
The trace of the sampler chain with the user's desired number of burn-in samples removed. |
Source code in samba/mixing.py
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 |
|
cdf(params, g)
staticmethod
The cumulative distribution function of a standard normal distribution, with two free parameters determined by sampling.
Example
cdf(params=np.array(), g=0.5)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
ndarray
|
The array of parameters the sampler will determine (here labelled beta0 and beta1, where beta0 controls the location of the function and beta1 controls the slope). |
required |
g |
float The value of g the cdf is calculated at. |
required |
Returns:
Name | Type | Description |
---|---|---|
function |
float
|
The result of the cdf function at the value of g. |
Source code in samba/mixing.py
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 |
|
hpd_interval(trace, fraction)
staticmethod
A function to calculate the Bayesian credible intervals of a posterior distribution. This function uses the HPD (highest posterior density) method.
Example
LMM.hpd_interval(trace=emcee_trace, fraction=0.95)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
trace |
ndarray
|
The trace generated by a sampler when sampling a variable to obtain its posterior distribution. |
required |
fraction |
float
|
The percent (in decimal form) requested by the user to set the credibility interval. |
required |
Returns:
Name | Type | Description |
---|---|---|
interval |
ndarray
|
The credibility interval bounds in a numpy array (format: [min, max]). |
Source code in samba/mixing.py
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 |
|
likelihood_high(g_data, data, sigma, sighigh)
The likelihood function for the data using the large-g expansion as the model in the chi-squared.
Example
LMM.likelihood_high(g_data=np.linspace(0.0, 0.5, 20), data=np.array(), sigma=np.array(), highorder=23)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
g_data |
linspace
|
A linspace used to generate data points. |
required |
data |
ndarray
|
An array of data points generated or supplied by the user. |
required |
sigma |
ndarray
|
An array of standard deviations at each point in 'data'. |
required |
Returns:
Type | Description |
---|---|
An array of the likelihood calculated at each data point. |
Source code in samba/mixing.py
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 |
|
likelihood_low(g_data, data, sigma, siglow)
The likelihood function for the data using the small-g expansion as the model in the chi-squared.
Example
LMM.likelihood_low(g_data=np.linspace(0.0, 0.5, 20), data=np.array(), sigma=np.array(), loworder=5)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
g_data |
linspace
|
A linspace used to generate data points. |
required |
data |
ndarray
|
An array of data points generated or supplied by the user. |
required |
sigma |
ndarray
|
An array of standard deviations at each point in 'data'. |
required |
Returns:
Type | Description |
---|---|
An array of the likelihood calculated at each data point. |
Source code in samba/mixing.py
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 |
|
logistic(params, g)
staticmethod
A basic logistic function often used in machine learning, implemented here with two free parameters to be determined via sampling.
Example
logistic(params=np.array(), g=0.5)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
ndarray
|
The array of parameters the sampler will determine (here labelled beta0 and beta1, where beta0 controls the location of the function and beta1 controls the slope). |
required |
Returns:
Name | Type | Description |
---|---|---|
mixing |
float
|
The result of the logistic function given the value g. |
Source code in samba/mixing.py
1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 |
|
mixed_model(g_data, data, sigma, mixing_function='cosine', nsteps=1000)
A function that will run the emcee ensemble sampler for a given mixed model to determine at least one unknown parameter in the mixing function selected. The function asks the user to decide which mixing function to use, and runs the subsequent code to use the correct one. Functions sent to the sampler are static methods defined at the end of this class.
Example
LMM.mixed_model(g_data=np.linspace(0.0, 0.5, 20), data=np.array(), sigma=np.array(), mixing_function='cosine', nsteps=3000)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
g_data |
linspace
|
The linspace over which the data was generated. |
required |
data |
ndarray
|
An array of data points, either generated or supplied by the user. |
required |
sigma |
ndarray
|
An array of standard deviations at each data point. |
required |
mixing_function |
str
|
The name of the mixing function to use for the LMM method. Default is the piecewise cosine. |
'cosine'
|
nsteps |
int
|
The number of steps per walker for the sampler to use. |
1000
|
Returns:
Name | Type | Description |
---|---|---|
sampler_mixed |
object
|
The sampler results, contained in a sampler object, from the determination of the unknown parameter. |
emcee_trace_mixed |
ndarray
|
The trace of each parameter, with burnin samples extracted. |
Source code in samba/mixing.py
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 388 389 390 391 |
|
plot_MAP(g, map_values)
A simple rough plotter to plot the weight/mixing function for the LMM method using the mixing function calculated at the points in g and the MAP values of its parameters.
Example
LMM.plot_MAP(g=np.linspace(), map_values=numpy.ndarray([]))
Parameters:
Name | Type | Description | Default |
---|---|---|---|
g |
linspace
|
The input space over which the mixing is calculated. |
required |
map_values |
ndarray
|
The results of the MAP_values() function (MAP values of each parameter in the mixing function selected). |
required |
Returns:
Type | Description |
---|---|
None. |
Source code in samba/mixing.py
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 |
|
plot_data(g_true, g_data, data)
The plotting function to display the generated data and true model.
Example
LMM.plot_data(g_true=np.linspace(0.0, 0.5, 100), g_data=np.linspace(0.0, 0.5, 20), data=np.array([]))
Parameters:
Name | Type | Description | Default |
---|---|---|---|
g_true |
linspace
|
The linspace desired for the true model to be calculated. |
required |
g_data |
linspace
|
The linspace over which the data was generated. |
required |
data |
ndarray
|
The array of data generated using the LMM.add_data function. |
required |
Returns:
Type | Description |
---|---|
None. |
Source code in samba/mixing.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 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
|
plot_ppd(results, g_data, g_ppd, data, ppd_results, ppd_intervals, percent)
A plotting function that can be used to plot the posterior predictive distribution (PPD) results (mean and credible interval) obtained from calling the functions above in the main code, as well as data generated, the true model, and the small- and large-g expansions chosen for the mixed model calculation.
Example
LMM.plot_ppd(g_data=np.linspace(0.0, 0.5, 20), g_true=np.linspace(0.0, 0.5, 100), g_ppd=np.linspace(0.0, 0.5, 200), data=np.array(), ppd_results=np.array(), ppd_intervals=np.array(), percent=68)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
results |
ndarray
|
The mean or the median of the estimated parameters from the posterior draws. |
required |
g_data |
linspace
|
The linspace used to generate the data. |
required |
g_ppd |
linspace
|
The linspace chosen to calculate the PPD over. |
required |
data |
ndarray
|
An array of data either generated or supplied by the user. |
required |
ppd_results |
ndarray
|
An array of the mean of the PPD at each point in the g_ppd linspace. |
required |
ppd_intervals |
ndarray
|
A 2D array of the credibility interval calculated for the PPD (containing both bounds). |
required |
percent |
int
|
The percent credibility interval calculated for the variable ppd_intervals (used in the plot legend). |
required |
Returns:
Type | Description |
---|---|
None. |
Source code in samba/mixing.py
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 |
|
ppd(trace, param_values, g_data, g, data, ci, plot=True)
A function to calculate the posterior predictive distribution (PPD) for any chosen mixing function defined in this class.
Example
LMM.ppd(trace, param_values=np.array([]),g_data=np.linspace(1e-6,1.0,10), g_ppd=np.linspace(0.0, 0.5, 100), ci=68)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
trace |
ndarray
|
The trace of each of the parameters from the sampler. |
required |
param_values |
ndarray
|
The mean, median, or MAP values of the parameters. |
required |
g_data |
linspace
|
The linspace in g from which the data set was calculated. |
required |
g |
linspace
|
The linspace over which the PPD result will be calculated. |
required |
data |
ndarray
|
The data set used to calculate the mixed model. |
required |
ci |
int
|
The desired credibility interval. Can be either 68 or 95. |
required |
plot |
bool
|
The option to plot the PPD result with the series expansions and true model. Default is True. |
True
|
Returns:
Name | Type | Description |
---|---|---|
switch_med_results |
ndarray
|
The array of median values from the PPD at each point in g. |
switch_g_intervals |
ndarray
|
The array of credibility interval values for the median results of the PPD. |
Source code in samba/mixing.py
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 |
|
sampler_mix(params, g_data, data, sigma, siglow, sighigh)
The model mixing function sent to the sampler to find the values of the parameters in the selected mixing function.
Example
emcee.EnsembleSampler(nwalkers, self.sampler_mix, args=[g_data, data, sigma])
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
ndarray
|
The parameters that are being determined by the sampler, in an array (not input). |
required |
g_data |
linspace
|
The linspace used to generate the data. |
required |
data |
ndarray
|
An array of data either generated or supplied by the user. |
required |
sigma |
ndarray
|
An array of standard deviations for each data point. |
required |
Returns:
Name | Type | Description |
---|---|---|
mixed_results |
ndarray
|
The results of the mixing function for the entire linspace in g, in an array format. |
Source code in samba/mixing.py
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 |
|
stats_chain(chain, plot=True)
Calculates the autocorrelation time and thins the samples accordingly for a better estimate of the mean, median, and MAP values.
Example
LMM.stats_chain(chain=emcee.object, plot=False)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
chain |
object
|
The object resulting from sampling the parameters using emcee. The chain of samples must be extracted from it. |
required |
plot |
bool
|
The option to plot the traces of the sample chains and the corner plot of the parameter distributions. Default is True. |
True
|
Returns:
Name | Type | Description |
---|---|---|
thin |
ndarray
|
The array of thinned samples per parameter. Used externally to calculate the MAP values. |
median_results |
ndarray
|
Each of the median parameter values found from the sampling. |
mean_results |
ndarray
|
Each of the mean parameter values found from the sampling. |
Source code in samba/mixing.py
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 |
|
stats_trace(trace)
A function to calculate the mean and credible intervals corresponding to each parameter. The trace plots for each parameter are plotted.
Example
LMM.stats_trace(trace=np.array([]))
Parameters:
Name | Type | Description | Default |
---|---|---|---|
trace |
ndarray
|
The trace from the sampler object that was generated when estimating the parameters of the mixing function. |
required |
Returns:
Name | Type | Description |
---|---|---|
mean |
ndarray
|
The array of mean values for each parameter. |
ci |
ndarray
|
The array of sets of credible interval bounds for each parameter. |
Source code in samba/mixing.py
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 |
|
step(params, g)
staticmethod
A step mixing function to switch between two models. Only useful for two models.
Example
step(params, g=0.2)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
ndarray
|
One single parameter to determine where the step function will break from one model to the other. |
required |
g |
float
|
One value of the input space. |
required |
Returns:
Type | Description |
---|---|
The value of the step function at a specific |
|
point in g. |
Source code in samba/mixing.py
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 |
|
switchcos(params, g)
staticmethod
A piecewise function using two constants at either end, and two cosine functions in the centre, to be used as a mixing function. One free parameter, g3, is found by sampling.
Example
switchcos(params=np.array(), g=0.5)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
ndarray
|
The array of parameters to be determined by the sampler (here labelled g1, g2, and g3, where g1 is the separation point between the first constant function and the first cosine function, g2 is the separation point between the second cosine function and the second constant function, and g3 is the point between the two cosine functions). |
required |
g |
float
|
The value of g that this cosine function is calculated at. |
required |
Returns:
Type | Description |
---|---|
The value of the function at a specific point in g. |
Source code in samba/mixing.py
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 |
|