Method 3: Multivariate model mixing with a Gaussian process
This method uses the same framework as the previous method, but now includes a Gaussian process (GP) in the mixing.
A diagnostic tool that helps with determining whether or not our mixed model result is reasonable is the Mahalanobis distance, calculated as
$$ D^{2}_{MD} = (\mathbf{y} - \mathbf{m})^{T}\textit{K}^{-1}(\mathbf{y} - \mathbf{m}), $$
and given in the functions below.
GP
Bases: Bivariate
Source code in samba/gaussprocess.py
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 |
|
MD_set(pts=3, plot=False)
Takes the training set of points and uses them to cut the testing set to their limits. This reduces the MD calculation to the region of interest.
Example
GP.MD_set()
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pts |
int
|
The number of points to use to calculate the Mahalanobis distance. Can be any number up to the size of self.gpredict. |
3
|
plot |
bool
|
The option to plot the MD points across the input space. Default is False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
md_g |
ndarray
|
The input values used in the MD calculation. |
md_mean |
ndarray
|
The mean values from the GP corresponding to the md_g points. |
md_sig |
ndarray
|
The error bars corresponding to the md_g points. |
md_cov |
ndarray
|
The covariance matrix corresponding to the md_g points. |
Source code in samba/gaussprocess.py
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 |
|
__init__(g, loworder, highorder, kernel='RBF', nu=None, ci=68, error_model='informative')
A class that will pull from the Models class to perform GP emulation on two models from the small-g expansion region to the large-g expansion region. The parameter settings of the kernel will be set by the user in this initial function. This class 'wraps' the scikit learn package.
Example
GP(g=np.linspace(1e-6,1.0,100), loworder=5, highorder=2, kernel="Matern", ci=68, error_model='informative')
Parameters:
Name | Type | Description | Default |
---|---|---|---|
g |
numpy linspace
|
The linspace across the coupling constant space used for the GP. |
required |
highorder |
(ndarray, float, int)
|
The truncation order of the large-g expansion. |
required |
kernel |
str
|
The type of kernel the user wishes to use. Default is the RBF kernel; possible choices are RBF, Matern, and Rational Quadratic. |
'RBF'
|
nu |
float
|
The value of the Matern kernel used, if kernel="Matern". Otherwise, default is None. |
None
|
ci |
int
|
The uncertainty interval to use. Must be 68 or 95. |
68
|
error_model |
str
|
The error model to be used in the calculation. Options are 'uninformative' and 'informative'. Default is 'informative'. |
'informative'
|
Returns:
Type | Description |
---|---|
None. |
Source code in samba/gaussprocess.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 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 |
|
create_points(N, a, b)
staticmethod
A code to create a given number of points from a linspace evenly from points a to b.
Example
GP.create_points(N=3, a=0.0, b=1.0)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
N |
int
|
The number of points desired. |
required |
a |
(float, int)
|
The left endpoint of the region of interest. |
required |
b |
(float, int)
|
The right endpoint of the region of interest. |
required |
Returns:
Name | Type | Description |
---|---|---|
pts |
ndarray
|
The resulting array of points. |
Source code in samba/gaussprocess.py
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 |
|
mahalanobis(y, mean, inv=None, chol=False, svd=False)
staticmethod
A diagnostic testing function that can calculate the Mahalanobis distance for a given set of mean, covariance data and a vector.
1). Calculate the MD of the predictions of the GP using
the inverse covariance matrix (usual method);
2). Calculate the MD of the predictions to construct a
reference distribution using the inverse covariance
matrix (usual method);
3). Calculate the Cholesky decomposition of the MD
information;
4). Perform an SVD analysis and send back the MD
calculated via SVD.
Example
GP.MD(y=np.array([]), mean=np.array([]), inv=numpy.ndarray([]), chol=False, svd=False)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
y |
ndarray
|
An array of predicted values from the emulator. |
required |
mean |
ndarray
|
An array of true values from the true model (simulator). |
required |
inv |
ndarray
|
The covariance matrix to be inverted in the MD calculation. |
None
|
chol |
bool
|
The option to calculate the Cholesky decomposition of the data. |
False
|
svd |
bool
|
An option to perform the SVD analysis of the MD data. To use, must also have a covariance matrix sent to inv. |
False
|
Returns:
Name | Type | Description |
---|---|---|
md |
float
|
(if calculating MD) The Mahalanobis distance. |
chol_decomp |
ndarray
|
(if calculating Cholesky decomposition) The Cholesky decomposition results. |
svderrs |
ndarray
|
(if calculating SVD) The SVD errors at each |
svd_md (float) (if calculating SVD) The Mahalanobis distance. |
Source code in samba/gaussprocess.py
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 |
|
md_plotter(md_gp, md_ref, md_mean=None, md_cov=None, hist=True, box=False)
A plotting function that allows the Mahalanobis distance to be plotted using either a histogram or a box and whisker plot, or both.
Box and whisker plot code heavily drawn from J. Melendez' gsum code (https://github.com/buqeye/gsum).
Example
GP.md_plotter(md_gp=np.array([]), md_ref=np.array([]), hist=False, box=True)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
md_gp |
float
|
The MD^2 value for the GP curve. |
required |
md_ref |
ndarray
|
The array of MD^2 values for the reference distribution. |
required |
md_mean |
ndarray
|
The values of the GP mean at the md_g points. Only used for box and whisker option; default is None. |
None
|
md_cov |
ndarray
|
The values of the GP covariance matrix at the md_g points. Only used for box and whisker option; default is None. |
None
|
hist |
bool
|
Toggle for plotting a histogram. Default is True. |
True
|
box |
bool
|
Toggle for plotting a box plot. Default is False. |
False
|
Returns:
Type | Description |
---|---|
None. |
Source code in samba/gaussprocess.py
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 |
|
md_squared(md_g, md_mean, md_cov, n_curves=1000)
A wrapper for the Mahalanobis distance calculation for the reference distribution and the GP curve. To calculate the Cholesky decomposition or to perform an SVD analysis, consult GP.mahalanobis() below.
Example
GP.md_squared(md_g=np.linspace, md_mean=np.array([]), md_cov=np.array([,]), n_curves=1000)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
md_g |
linspace
|
The points in input space g from the GP.MD_set() function. |
required |
md_mean |
ndarray
|
The values of the GP mean at the md_g points. |
required |
md_cov |
ndarray
|
The values of the GP covariance matrix at the md_g points. |
required |
n_curves |
int
|
The number of curves from the reference distribution that are drawn for the MD^2 calculation (md_ref). |
1000
|
Returns:
Name | Type | Description |
---|---|---|
md_gp |
float
|
The individual MD^2 value for the GP curve. |
md_ref (numpy.ndarray): The array of MD^2 values from the reference distribution.
Source code in samba/gaussprocess.py
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 |
|
nearest_value(array, value)
staticmethod
A static method to find the index of the nearest value of an array to a desired value.
Example
GP.nearest_value(array=numpy.ndarray, value=5)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
array |
ndarray
|
The array of values to search. |
required |
value |
int
|
The desired value to search the array for. |
required |
index (int): The index of the nearest value of the array to the desired value.
Source code in samba/gaussprocess.py
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 |
|
plot_training(gs, datas, sigmas)
A simple plotter to plot the trained GP results and models, as well as the points at which the GP was trained.
Example
GP.plot_training(gs=np.array([]), datas=np.array([]), sigmas=np.array([]))
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gs |
ndarray
|
Points chosen by GP.training_set() in input space g. |
required |
datas |
ndarray
|
Corresponding values of the series expansions at gs. |
required |
sigmas |
ndarray
|
Corresponding error model results at each training point. |
required |
Returns:
Type | Description |
---|---|
None. |
Source code in samba/gaussprocess.py
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 |
|
plot_validate(intervals)
A simple plotter to show the results of the GP predictions at new points in g.
Example
GP.plot_validate(intervals=np.array([,]))
Parameters:
Name | Type | Description | Default |
---|---|---|---|
intervals |
ndarray
|
The uncertainty band around the prediction set. |
required |
Returns:
Type | Description |
---|---|
None. |
Source code in samba/gaussprocess.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 332 333 |
|
ref_boxplot(dist, q1=0.25, q3=0.75, whislo=0.025, whishi=0.975, ax=None, **kwargs)
staticmethod
Taken from the gsum code written by J. Melendez (https://github.com/buqeye/gsum).
Source code in samba/gaussprocess.py
895 896 897 898 899 900 901 902 903 904 905 |
|
ref_dist(mean, cov)
staticmethod
Constructs a multivariate normal distribution to act as a reference distribution for the Mahalanobis distance calculation.
Example
Diagnostics.ref_dist(mean=np.array([]), cov=np.array([]))
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mean |
ndarray
|
The mean of the GP (given by the prediction set). |
required |
cov |
ndarray
|
The covariance matrix of the GP (given by the prediction set). |
required |
Returns:
Name | Type | Description |
---|---|---|
dist |
object
|
A multivariate normal distribution that can be used to generate samples for the reference distribution. |
Source code in samba/gaussprocess.py
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 |
|
sample_ref(dist, n_curves)
staticmethod
Generate some sample curves from the reference distribution.
Example
Diagnostics.sample_ref(dist, n_curves=10)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dist |
object
|
The reference distribution object. |
required |
n_curves |
int
|
The number of draws from the reference distribution. |
required |
Returns:
Name | Type | Description |
---|---|---|
samples |
ndarray
|
The array of curves from the distribution. |
Source code in samba/gaussprocess.py
838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 |
|
training(error=True, method=2, plot=True)
A function that links the model data and the training function in scikit learn, and plots the training data using GP.plot_training().
Example
GP.training(error=False, method=3)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
error |
bool
|
A boolean variable to toggle use of a truncation error model in the kernel during training. Default is True. |
True
|
method |
int
|
The method used for determining the training points. Options: 1,2,3. For an extensive explanation of the methods, see the paper. |
2
|
plot |
bool
|
Option to plot the training set with series expansions and true model. Default is True. |
True
|
Returns:
Name | Type | Description |
---|---|---|
sk |
object
|
The object storing all training information from the sklearn regression performed on the data. |
Source code in samba/gaussprocess.py
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 |
|
training_set()
An internal function to calculate the necessary training data set from the input prediction set.
Example
GP.training_set()
Returns: gs (numpy.ndarray): The modified array of input values for the training.
datas (numpy.ndarray): The modified array of data values for the training.
sigmas (numpy.ndarray): The modified array of the truncation errors for the training.
Source code in samba/gaussprocess.py
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 |
|
validate(plot=True, run_taweret=False)
A wrapper function for scikit learn's GP prediction function. This will predict the GP results with an interval and plot against the expansions using GP.plot_validate().
Example
GP.validate()
Parameters:
Name | Type | Description | Default |
---|---|---|---|
plot |
bool
|
The option to plot the GP mean and variance over the testing set and true model. Default is True. |
True
|
Returns:
Name | Type | Description |
---|---|---|
meanp |
ndarray
|
The mean array of the GP prediction results. |
sigp |
ndarray
|
The standard deviation array of the GP prediction results. |
cov |
ndarray
|
The covariance matrix of the GP prediction results. |
Source code in samba/gaussprocess.py
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 |
|