emulators
Provides the emulators for the simulators building upon the mogp
package
and adapting to work with the implemented designers from exauq.core.designers
.
MogpEmulator
correlation
Compute correlation matrix for Input Sequences.
covariance_matrix
Compute covariance matrix for Input Sequences.
fit
Fit emulator to the data.
fit_hyperparameters
(Read-Only) Hyperparameters of current fitted GP.
gp
(Read-Only) Underlying GP for this emulator.
predict
Make prediction for simulator output given Input.
training_data
(Read-only) The data on which the emulator has been trained.
MogpHyperparameters
from_mogp_gp_params
Create instance of MogpHyperparameters
.
to_mogp_gp_params
Convert to an instance of mogp_emulator.GPParams.GPParams
.
MogpEmulator
Bases: AbstractGaussianProcess
An emulator wrapping a GaussianProcess
object from the mogp-emulator
package.
This class allows mogp-emulator GaussianProcess
objects to be used with the
designers defined in the EXAUQ-Toolbox, ensuring the interface required by the
designers is present. Keyword arguments supplied to the MogpEmulator
are passed onto
the GaussianProcess
initialiser to create the underlying (i.e. wrapped)
GaussianProcess
object. Note that any inputs
or targets
supplied are
ignored: the underlying GaussianProcess
will initially be constructed with no
training data. Additionally, the only kernel
s currently supported are
'SquaredExponential' (the default), 'Matern52' and 'ProductMat52'; these should be
specified as strings during initialisation.
The underlying GaussianProcess
object can be obtained through the
gp
property. Note that the fit
method, used to train the emulator, will
modify the underlying GaussianProcess
.
Parameters:
-
**kwargs
(dict
, default:{}
) –Any permitted keyword arguments that can be used to create a mogp-emulator
GaussianProcess
object. See the mogp-emulator documentation for details. Ifinputs
ortargets
are supplied as keyword arguments then these will be ignored.kernel
, if supplied, should be a string of one of the currently supported kernels (see above).
Attributes:
-
gp
(GaussianProcess
) –(Read-only) The underlying mogp-emulator
GaussianProcess
object constructed by this class. -
training_data
(tuple[TrainingDatum]
) –(Read-only) Defines the pairs of inputs and simulator outputs on which the emulator has been trained.
-
fit_hyperparameters
(MogpHyperparameters or None
) –(Read-only) The hyperparameters of the underlying fitted Gaussian process model, or
None
if the model has not been fit to data. -
kinv
(ndarray
) –(Read-only) The inverse of the covariance matrix of the training data, or an empty NumPy array if the model has not been fitted to data.
Raises:
-
ValueError
–If the kernel supplied is not one of the supported kernel functions.
-
RuntimeError
–If keyword arguments are supplied upon initialisation that aren't supported by the initialiser of
GaussianProcess
from the mogp-emulator package.
Source code in exauq/core/emulators.py
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 |
|
fit_hyperparameters: Optional[MogpHyperparameters]
property
(Read-only) The hyperparameters of the underlying fitted Gaussian
process model, or None
if the model has not been fitted to data.
gp: GaussianProcess
property
(Read-only) The underlying mogp GaussianProcess for this emulator.
kinv: NDArray
property
(Read-only) The inverse of the covariance matrix of the training data, or an empty NumPy array if the model has not been fitted to data.
training_data: tuple[TrainingDatum]
property
(Read-only) The data on which the emulator has been trained.
correlation(inputs1, inputs2)
Compute the correlation matrix for two sequences of simulator inputs.
If corr_matrix
is the Numpy array output by this method, then its shape is
such that (in pseudocode) corr_matrix[i, j] = kernel(inputs1[i], inputs2[j])
,
where kernel
is the kernel function for the underlying Gaussian process. The
only exception to this is when either of the sequence of inputs is empty, in which
case an empty array is returned.
In order to calculate the correlation between nonempty sequences of inputs, this
emulator's fit_hyperparameters
needs to not be None
, i.e. the emulator
needs to have been trained on data.
Parameters:
-
inputs1
(Sequence[Input]
) –Sequences of simulator inputs.
-
inputs2
(Sequence[Input]
) –Sequences of simulator inputs.
Returns:
-
ndarray
–The correlation matrix for the two sequences of inputs, as an array of shape
(len(inputs1), len(inputs2))
.
Raises:
-
AssertionError
–If this emulator has not yet been trained on data.
-
ValueError
–If the dimension of any of the supplied simulator inputs doesn't match the dimension of training data inputs for this emulator.
Source code in exauq/core/emulators.py
covariance_matrix(inputs)
Compute the covariance matrix for a sequence of simulator inputs.
In pseudocode, the covariance matrix for a given collection inputs
of simulator
inputs is defined in terms of the correlation matrix as sigma^2 *
correlation(inputs, training_inputs)
, where sigma^2
is the process variance
for this Gaussian process (which was determined or supplied during training) and
training_inputs
are the simulator inputs used in training. The only exceptions
to this are when the supplied inputs
is empty or if this emulator hasn't been
trained on data: in these cases an empty array is returned.
Parameters:
-
inputs
(Sequence[Input]
) –A sequence of simulator inputs.
Returns:
-
ndarray
–The covariance matrix for the sequence of inputs, as an array of shape
(len(inputs), n)
wheren
is the number of training data points for this Gaussian process.
Raises:
-
ValueError
–If the dimension of any of the supplied simulator inputs doesn't match the dimension of training data inputs for this emulator.
Source code in exauq/core/emulators.py
fit(training_data, hyperparameters=None, hyperparameter_bounds=None)
Fit the emulator to data.
This method trains the underlying GaussianProcess
, as stored in
the gp
property, using the supplied training data. By default,
hyperparameters are estimated as part of this training, by maximising the
log-posterior. Alternatively, a collection of hyperparameters can be supplied to
use directly as the fitted values. (If the nugget is not supplied as part of these
values, then it will be calculated according to the 'nugget' argument used in the
construction of the underlying GaussianProcess
.)
If bounds are supplied for the hyperparameters, then fitting with hyperparameter
estimation will respect these bounds (i.e. the underlying log-posterior
maximisation will be constrained by the bounds). A bound that is set to None
is treated as unconstrained; additionally, upper bounds must be None
or a
positive number. Note that the bounds are ignored if fitting with specific
hyperparameters.
Parameters:
-
training_data
(Collection[TrainingDatum]
) –The pairs of inputs and simulator outputs on which the emulator should be trained. Should be a finite collection of such pairs.
-
hyperparameters
(Optional[MogpHyperparameters]
, default:None
) –Hyperparameters to use directly in fitting the Gaussian process. If
None
then the hyperparameters will be estimated as part of fitting to data. -
hyperparameter_bounds
(Optional[Sequence[OptionalFloatPairs]]
, default:None
) –A sequence of bounds to apply to hyperparameters during estimation, of the form
(lower_bound, upper_bound)
. All but the last tuple should represent bounds for the correlation length parameters, while the last tuple should represent bounds for the process variance.
Raises:
-
ValueError
–If
training_data
is provided with duplicate inputs: all inputs must be unique.If
hyperparameters
is provided with nugget beingNone
butself.gp
was created with nugget fitting method 'fit'.
Source code in exauq/core/emulators.py
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 |
|
predict(x)
Make a prediction of a simulator output for a given input.
Parameters:
-
x
(Input
) –A simulator input.
Returns:
-
GaussianProcessPrediction
–The Gaussian process' prediction of the simulator output from the given input.
Raises:
-
RuntimeError
–If this emulator has not been trained on any data before making the prediction.
Source code in exauq/core/emulators.py
MogpHyperparameters
dataclass
Bases: GaussianProcessHyperparameters
Hyperparameters for use in fitting Gaussian processes via MogpEmulator
.
This provides a simplified interface to parameters used in
mogp_emulator.GaussianProcess
objects and is comparable to the
mogp_emulator.GPParams.GPParams
class. The correlation length scale parameters,
process variance and nugget described below are on the 'transformed' (linear) scale
rather than the log scale; cf.
mogp_docs.GPParams.GPParams.
Equality of MogpHyperparameters
objects is tested hyperparameter-wise up to the
default numerical precision defined in exauq.core.numerics.FLOAT_TOLERANCE
(see exauq.core.numerics.equal_within_tolerance
).
Parameters:
-
corr_length_scales
(sequence or Numpy array of Real
) –The correlation length scale parameters. The length of the sequence or array should equal the number of input coordinates for an emulator and each scale parameter should be a positive.
-
process_var
(Real
) –The process variance, which should be positive.
-
nugget
(Real
, default:None
) –A nugget, which should be non-negative if provided.
Attributes:
-
corr_length_scales
(sequence or Numpy array of Real
) –(Read-only) The correlation length scale parameters.
-
process_var
(Real
) –(Read-only) The process variance.
-
nugget
((Real, optional)
) –(Read only) The nugget, or
None
if not supplied.
See Also
equal_within_tolerance : Numerical tolerance check.
Source code in exauq/core/emulators.py
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 |
|
from_mogp_gp_params(params)
classmethod
Create an instance of MogpHyperparameters from an
mogp_emulator.GPParams.GPParams
object.
Parameters:
-
params
(GPParams
) –A parameters object from mogp-emulator.
Returns:
-
MogpHyperparameters
–The hyperparameters extracted from the given
params
.
Source code in exauq/core/emulators.py
to_mogp_gp_params(nugget_type='fixed')
Convert this object to an instance of mogp_emulator.GPParams.GPParams
.
The correlation length scales and process variance hyperparameters are copied to
the returned mogp-emulator parameters object. How the nugget is set in the output
depends on the value of the nugget_type
, which describes the nugget fitting
method recorded in the output object:
-
If
nugget_type
is one of {'fixed', 'fit'} thenself.nugget
must be defined as a real number. The nugget will be copied over to the output and the fitting method will be as specified innugget_type
. (In this case, 'fixed' represents the case where the nugget has been assigned a specific value, whereas 'fit' represents the case where the value has been estimated when fitting the emulator.) -
If
nugget_type
is one of {'adaptive', 'pivot'} thenself.nugget
is ignored and will not be copied over to the output. The fitting method recorded in the output object will be as specified innugget_type
, representing the case where the nugget is computed in some way different to hyperparameter estimation.
Parameters:
-
nugget_type
(one of {"fixed", "fit", "adaptive", "pivot"}
, default:'fixed'
) –The type of nugget to be specified in construction of the returned
mogp_emulator.GPParams.GPParams
object. See above for discussion on valid values.
Returns:
-
GPParams
–An mogp-emulator parameters object with the hyperparameters given in this object.
See Also
See mogp-emulator/nugget_type
for details of the nugget_type
attribute in mogp_emulator.GPParams.GPParams
objects and
mogp-emulator/nugget_fitting_methods
for a discussion about what the different nugget fitting methods mean.
Source code in exauq/core/emulators.py
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 |
|