The MultiOutputGP
Class¶
Implementation of a multiple-output Gaussian Process Emulator.
Essentially a parallelized wrapper for the predict method. To fit
in parallel, use the fit_GP_MAP
routine
Required arguments are inputs
and targets
, both of which
must be numpy arrays. inputs
can be 1D or 2D (if 1D, assumes
second axis has length 1). targets
can be 1D or 2D (if 2D,
assumes a single emulator and the first axis has length 1).
Optional arguments specify how each individual emulator is
constructed, including the mean function, kernel, priors, and how
to handle the nugget. Each argument can take values allowed by the
base GaussianProcess
class, in which case all emulators are
assumed to use the same value. Any of these arguments can
alternatively be a list of values with length matching the number
of emulators to set those values individually.
-
class
mogp_emulator.MultiOutputGP.
MultiOutputGP
(inputs, targets, mean=None, kernel='SquaredExponential', priors=None, nugget='adaptive', inputdict={}, use_patsy=True)¶ Implementation of a multiple-output Gaussian Process Emulator.
Essentially a parallelized wrapper for the predict method. To fit in parallel, use the
fit_GP_MAP
routineRequired arguments are
inputs
andtargets
, both of which must be numpy arrays.inputs
can be 1D or 2D (if 1D, assumes second axis has length 1).targets
can be 1D or 2D (if 2D, assumes a single emulator and the first axis has length 1).Optional arguments specify how each individual emulator is constructed, including the mean function, kernel, priors, and how to handle the nugget. Each argument can take values allowed by the base
GaussianProcess
class, in which case all emulators are assumed to use the same value. Any of these arguments can alternatively be a list of values with length matching the number of emulators to set those values individually.-
__init__
(inputs, targets, mean=None, kernel='SquaredExponential', priors=None, nugget='adaptive', inputdict={}, use_patsy=True)¶ Create a new multi-output GP Emulator
-
D
¶ Number of Dimensions in inputs
Returns number of dimentions of the input data
Returns: Number of dimentions of inputs Return type: int
-
fit
(thetas)¶ Fit all emulators
Fit all emulators given an 2D array of hyperparameter values (if all emulators have the same number of parameters) or an iterable containing 1D numpy arrays (if the emulators have a variable number of hyperparameter values).
Note that this routine does not run in parallel for the CPU version.
Parameters: thetas (np.array or iterable) – hyperparameters for all emulators. 2D array or iterable containing 1D numpy arrays, must have first dimension of size n_emulators
-
fit_emulator
(index, theta)¶ Fit a specific emulator :param index: index of emulator whose hyperparameters we will set :type index: int :param theta: hyperparameters for all emulators. 1D array of length n_param :type theta: np.array
-
get_emulators_fit
()¶ Returns the emulators that have been fit
When a
MultiOutputGP
class is initialized, none of the emulators are fit. Fitting is done by passing the object to an external fitting routine, which modifies the object to fit the hyperparameters. Any emulators where the fitting fails are returned to the initialized state, and this method is used to obtain a list of emulators that have successfully been fit.Returns a list of
GaussianProcess
objects which have been fit (i.e. those which have a current valid set of hyperparameters).Returns: List of GaussianProcess
objects indicating the emulators that have been fit. If no emulators have been fit, returns an empty list.Return type: list of GaussianProcess
objects
-
get_emulators_not_fit
()¶ Returns the indices of the emulators that have not been fit
When a
MultiOutputGP
class is initialized, none of the emulators are fit. Fitting is done by passing the object to an external fitting routine, which modifies the object to fit the hyperparameters. Any emulators where the fitting fails are returned to the initialized state, and this method is used to obtain a list of emulators that have not been fit.Returns a list of
GaussianProcess
objects which have not been fit (i.e. those which do not have a current set of hyperparameters).Returns: List of GaussianProcess
objects indicating the emulators that have not been fit. If all emulators have been fit, returns an empty list.Return type: list of GaussianProcess
objects
-
get_indices_fit
()¶ Returns the indices of the emulators that have been fit
When a
MultiOutputGP
class is initialized, none of the emulators are fit. Fitting is done by passing the object to an external fitting routine, which modifies the object to fit the hyperparameters. Any emulators where the fitting fails are returned to the initialized state, and this method is used to determine the indices of the emulators that have succesfully been fit.Returns a list of non-negative integers indicating the indices of the emulators that have been fit.
Returns: List of integer indicies indicating the emulators that have been fit. If no emulators have been fit, returns an empty list. Return type: list of int
-
get_indices_not_fit
()¶ Returns the indices of the emulators that have not been fit
When a
MultiOutputGP
class is initialized, none of the emulators are fit. Fitting is done by passing the object to an external fitting routine, which modifies the object to fit the hyperparameters. Any emulators where the fitting fails are returned to the initialized state, and this method is used to determine the indices of the emulators that have not been fit.Returns a list of non-negative integers indicating the indices of the emulators that have not been fit.
Returns: List of integer indicies indicating the emulators that have not been fit. If all emulators have been fit, returns an empty list. Return type: list of int
-
inputs
¶ Full array of emulator inputs
Returns input array (2D array of shape
(n, D)
).Returns: Array of input values Return type: ndarray
-
n
¶ Number of training examples in inputs
Returns length of training data.
Returns: Length of training inputs Return type: int
-
n_params
¶ Returns the number of parameters for all emulators as a list of integers
Returns: Number of parameters for each emulator as a list of integers Return type: list
-
predict
(testing, unc=True, deriv=False, include_nugget=True, full_cov=False, allow_not_fit=False, processes=None)¶ Make a prediction for a set of input vectors
Makes predictions for each of the emulators on a given set of input vectors. The input vectors must be passed as a
(n_predict, D)
or(D,)
shaped array-like object, wheren_predict
is the number of different prediction points under consideration andD
is the number of inputs to the emulator. If the prediction inputs array has shape(D,)
, then the method assumesn_predict == 1
. The prediction points are passed to each emulator and the predictions are collected into an(n_emulators, n_predict)
shaped numpy array as the first return value from the method.Optionally, the emulator can also calculate the uncertainties in the predictions (as a variance) and the derivatives with respect to each input parameter. If the uncertainties are computed, they are returned as the second output from the method as an
(n_emulators, n_predict)
shaped numpy array. If the derivatives are computed, they are returned as the third output from the method as an(n_emulators, n_predict, D)
shaped numpy array. Finally, if uncertainties are computed, theinclude_nugget
flag determines if the uncertainties should include the nugget. By default, this is set toTrue
.If desired, the full covariance can be computed by setting
full_cov=True
. In that case, the returned uncertainty will have shape(n_emulators, n_predict, n_predict)
. This argument is optional and the default is to only compute the variance, not the full covariance.Derivatives have been deprecated due to changes in how the mean function is computed, so setting
deriv=True
will have no effect and will raise aDeprecationWarning
.The
allow_not_fit
flag determines how the object handles any emulators that do not have fit hyperparameter values (because fitting presumably failed). By default,allow_not_fit=False
and the method will raise an error if any emulators are not fit. Passingallow_not_fit=True
will override this andNaN
will be returned from any emulators that have not been fit.As with the fitting, this computation can be done independently for each emulator and thus can be done in parallel.
Parameters: - testing (ndarray) – Array-like object holding the points where
predictions will be made. Must have shape
(n_predict, D)
or(D,)
(for a single prediction) - unc (bool) – (optional) Flag indicating if the uncertainties
are to be computed. If
False
the method returnsNone
in place of the uncertainty array. Default value isTrue
. - include_nugget (bool) – (optional) Flag indicating if the
nugget should be included in the
predictive variance. Only relevant if
unc = True
. Default isTrue
. - full_cov (bool) – (optional) Flag indicating if the full
predictive covariance should be computed.
Only relevant if
unc = True
. Default isFalse
. - allow_not_fit (bool) – (optional) Flag that allows predictions
to be made even if not all emulators have
been fit. Default is
False
which will raise an error if any unfitted emulators are present. - processes (int or None) – (optional) Number of processes to use when
making the predictions. Must be a positive
integer or
None
to use the number of processors on the computer (default isNone
)
Returns: PredictResult
object holding numpy arrays containing the predictions, uncertainties, and derivatives, respectively. Predictions and uncertainties have shape(n_emulators, n_predict)
while the derivatives have shape(n_emulators, n_predict, D)
. If thedo_unc
ordo_deriv
flags are set toFalse
, then those arrays are replaced byNone
.Return type: - testing (ndarray) – Array-like object holding the points where
predictions will be made. Must have shape
-
reset_fit_status
()¶ Reset the fit status of all emulators
-
targets
¶ Full array of emulator targets
Returns target array (2D array of shape
(n_emulators, n)
).Returns: Array of target values Return type: ndarray
-