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
and given in the functions below.
GP(g, loworder, highorder, kernel='RBF', nu=None, ci=68, error_model='informative', new=False)
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'
|
new
|
bool
|
Control variable for additional edits being made to the code for the dissertation alterations. Default is False. |
False
|
Returns:
| Type | Description |
|---|---|
|
None. |
Source code in samba/gaussprocess.py
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
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 | |
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
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
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 | |
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
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 | |
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
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
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
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
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 | |
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
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
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
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
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
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 | |
validate(plot=True, run_taweret=False, bars=True)
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
|
bars
|
bool
|
Whether to plot and show the error bands of each training point or not. 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. |