Gaussian Process Regression
Methods for Gaussian process regression.
Index
UncertaintyQuantification.AdaptiveGaussianProcessUncertaintyQuantification.DeviationNumberUncertaintyQuantification.ExpectedFeasibilityUncertaintyQuantification.ExpectedImprovementUncertaintyQuantification.ExpectedImprovementForGlobalFitUncertaintyQuantification.GaussianProcessUncertaintyQuantification.MaximinDistanceUncertaintyQuantification.MaximumLikelihoodEstimationUncertaintyQuantification.MaximumVarianceUncertaintyQuantification.ProbabilityOfImprovementUncertaintyQuantification.UpperConfidenceBoundDistributions.logpdfDistributions.logpdfUncertaintyQuantification.evaluate!UncertaintyQuantification.evaluate!UncertaintyQuantification.refine!UncertaintyQuantification.sample!UncertaintyQuantification.sample!
Types
UncertaintyQuantification.GaussianProcess Type
GaussianProcess(
data::DataFrame, output::Symbol,
input_names::Vector{Symbol} = propertynames(data[:, Not(output)]); kwargs...
)Fit a Gaussian process surrogate to the input and output columns in data. The returned model stores the fitted posterior, selected input names, noise variance, input transformation, and training data in posterior, input_names, σ², transform, and data, respectively. The output is kept on its original scale. The training DataFrame is stored by reference.
Arguments
data: Training data containing the input columns and observed output.output: Name of the output column to approximate.input_names: Input columns, in the order used by the GP. Defaults to all columns exceptoutput; specify this argument to exclude metadata or other outputs.
Keyword Arguments
mean: Prior mean function. Defaults toZeroMean().kernel: Prior covariance kernel. Defaults toSqExponentialKernel().normalize: Whether to standardize each input column using its training-data mean and standard deviation. Defaults totrue. The fitted transformation is reused for predictions;falseuses the inputs without transformation.σ²: Nonnegative observation-noise variance. Defaults to1.0e-10.learn_noise: Whether to optimize the noise variance along with the other hyperparameters. Defaults tofalse; only takes effect whenlearn_hyperparameters = true.learn_hyperparameters: Whether to optimize the prior hyperparameters. Defaults totrue.optimizer: Hyperparameter-optimization strategy. Defaults toMaximumLikelihoodEstimation(Optim.LBFGS(), Optim.Options(; iterations = 100, show_trace = false)).
Examples
julia> data = DataFrame(x = [0.0, 1.0, 2.0], y = [0.0, 1.0, 4.0], id = 1:3);
julia> gp = GaussianProcess(
data, :y, [:x]; mean = ConstMean(0.0), kernel = SqExponentialKernel(),
σ² = 1.0e-3, learn_hyperparameters = false,
);
julia> gp.inputs == [:x] && gp.output == :y && nrow(gp.data) == 3
trueGaussianProcess(
inputs, models, design, output::Symbol,
input_names::Vector{Symbol} = wrap(names(inputs)); kwargs...
)Sample an initial experimental design, evaluate models at those points, and fit a Gaussian-process surrogate for output. Training data are stored in physical space in the returned model's data field. The output is kept on its original scale.
Arguments
inputs: AUQInputor vector of inputs defining the sampling distributions and parameters.models: AUQModelor vector of models evaluated on the sampled data.design: AnAbstractMonteCarloorAbstractDesignOfExperimentsspecifying the sampling method and number of initial points, e.g.QuasiMonteCarloSampling(10, LatinHypercubeSample()).output: Name of the model output to approximate.input_names: Input columns, in the order used by the GP. Defaults to all names frominputs.
Keyword Arguments
mean: Prior mean function. Defaults toZeroMean().kernel: Prior covariance kernel. Defaults toSqExponentialKernel().normalize: Whether to map the inputs to standard normal space using their distributions. Defaults totrue. The same transformation is applied during prediction;falseuses physical-space inputs directly.σ²: Nonnegative observation-noise variance. Defaults to1.0e-10.learn_noise: Whether to optimize the noise variance along with the other hyperparameters. Defaults tofalse; only takes effect whenlearn_hyperparameters = true.learn_hyperparameters: Whether to optimize the prior hyperparameters. Defaults totrue.optimizer: Hyperparameter-optimization strategy. Defaults toMaximumLikelihoodEstimation(Optim.LBFGS(), Optim.Options(; iterations = 100, show_trace = false)).
Examples
julia> using QuasiMonteCarlo
julia> x = RandomVariable(Uniform(0, 5), :x);
julia> model = Model(df -> sin.(df.x), :y);
julia> gp = GaussianProcess(
x, model, QuasiMonteCarloSampling(10, LatinHypercubeSample()), :y;
mean = ConstMean(0.0), kernel = SqExponentialKernel(),
learn_hyperparameters = false,
);
julia> gp.inputs == [:x] && nrow(gp.data) == 10
trueUncertaintyQuantification.AdaptiveGaussianProcess Type
AdaptiveGaussianProcessAn adaptive Gaussian-process model that stores a fitted GaussianProcess and the settings needed to refine it repeatedly with refine!.
The fields gp, input, model, acquisition_function, and candidate_sampling store the current surrogate, input distributions and model(s) to evaluate, candidate-selection rule, and candidate-sampling method. The remaining fields store the hyperparameter-learning settings used when refitting. Use evaluate!, sample!, and logpdf to access the corresponding operations of the contained Gaussian process.
UncertaintyQuantification.MaximumLikelihoodEstimation Type
MaximumLikelihoodEstimation(
optimizer = LBFGS(),
options = Optim.Options(; iterations = 100, show_trace = false),
backend = AutoMooncake();
restarts = 5,
)Represents a hyperparameter optimization strategy that maximizes the log marginal likelihood of a Gaussian process model with random restarts of the optimization.
Arguments
optimizer::Union{Optim.ZerothOrderOptimizer, Optim.FirstOrderOptimizer}: chosen optimizer (default:LBFGS())options::Optim.Options: options for the optimizer (default:Optim.Options(; iterations = 100, show_trace = false))backend::AbstractADType: automatic differentiation backend (default:AutoMooncake(); can benothingwhen using gradient-free optimization)
Keyword Arguments
restarts: Number of additional randomized optimization runs. Defaults to5.
Note
You can choose from any first order (gradient-based) and zeroth order (gradient-free) optimizer and set of options provided by Optim.jl, such as LBFGS(), Adam(), or ConjugateGradient().
Examples
julia> using Optim
julia> MaximumLikelihoodEstimation(Optim.Adam(alpha = 0.01), Optim.Options(; iterations = 1000, show_trace = false))
MaximumLikelihoodEstimation(Adam{Float64, Float64, Flat}(0.01, 0.9, 0.999, 1.0e-8, Flat()), Optim.Options(x_abstol = 0.0, x_reltol = 0.0, f_abstol = 0.0, f_reltol = 0.0, g_abstol = 1.0e-8, outer_x_abstol = 0.0, outer_x_reltol = 0.0, outer_f_abstol = 0.0, outer_f_reltol = 0.0, outer_g_abstol = 1.0e-8, f_calls_limit = 0, g_calls_limit = 0, h_calls_limit = 0, allow_f_increases = true, allow_outer_f_increases = true, successive_f_tol = 1, iterations = 1000, outer_iterations = 1000, store_trace = false, trace_simplex = false, show_trace = false, extended_trace = false, show_warnings = true, show_every = 1, time_limit = NaN, )
, ADTypes.AutoMooncake(), 5)Functions
UncertaintyQuantification.evaluate! Method
evaluate!(gp::GaussianProcess, data::DataFrame; mean::Bool = true, variance::Bool = false)Evaluate a GaussianProcess at the input locations in data, append or replace prediction columns in data, and return nothing.
Arguments
gp: Gaussian-process model.data: Prediction locations containing the columns ingp.inputs.
Keyword Arguments
mean: Write the predictive mean to the column<output>_mean. Defaults totrue.variance: Write the predictive variance to the column<output>_var. Defaults tofalse.
Use sample! to draw joint samples from the predictive distribution.
Examples
julia> data = DataFrame(x = [0.0, 1.0, 2.0], y = [0.0, 1.0, 4.0]);
julia> gp = GaussianProcess(data, :y; σ² = 1.0e-3, learn_hyperparameters = false);
julia> predictions = DataFrame(x = [0.5, 1.5]);
julia> evaluate!(gp, predictions; variance = true);
julia> propertynames(predictions) == [:x, :y_mean, :y_var]
true
julia> all(isfinite, predictions.y_mean) && all(>=(0), predictions.y_var)
trueUncertaintyQuantification.sample! Function
sample!(gp::GaussianProcess, data::DataFrame, n::Int = 1)Draw n independent realizations from the GP's joint posterior predictive distribution at the input locations in data. Each realization contains correlated values across the rows of data; row i of data is assigned the vector of its n sample values in the column gp.output, replacing any existing values in that column. Return nothing.
Arguments
gp:GaussianProcess.data: Prediction locations containing the columns ingp.inputs.n: Number of realizations to draw. Defaults to1.
Only the gp.output column of data is modified; other columns are left unchanged. The fitted posterior is not modified.
Drawing joint samples requires factoring a covariance matrix whose size is the number of rows in data. Very close or repeated locations can cause numerical difficulties when the observation-noise variance is too small.
Examples
julia> training = DataFrame(x = [0.0, 1.0, 2.0], y = [0.0, 1.0, 4.0]);
julia> gp = GaussianProcess(training, :y; σ² = 1.0e-3, learn_hyperparameters = false);
julia> draws = DataFrame(x = [0.5, 1.5]);
julia> sample!(gp, draws, 2);
julia> length(draws.y[1]) == 2
true
julia> all(isfinite, hcat(draws.y...))
trueDistributions.logpdf Method
logpdf(gp::GaussianProcess, data::DataFrame)Evaluate the joint posterior predictive log density of the output values in data at the input locations in the same DataFrame.
Arguments
gp: Gaussian process to compute the density for.data: DataFrame containing the input and output values.
UncertaintyQuantification.evaluate! Method
evaluate!(
agp::AdaptiveGaussianProcess, data::DataFrame;
mean::Bool = true, variance::Bool = false
)Evaluate the Gaussian process contained in agp at the input locations in data, writing requested predictions to data and returning nothing. Prediction columns are named <output>_mean and <output>_var. This is a convenience wrapper for evaluate!(agp.gp, data; mean, variance).
Arguments
agp: Adaptive Gaussian process whose current fitted GP is evaluated.data: Prediction locations containing the input columns used by the GP.
Keyword Arguments
mean: Whether to write the predictive mean. Defaults totrue.variance: Whether to write the predictive variance. Defaults tofalse.
UncertaintyQuantification.sample! Function
sample!(agp::AdaptiveGaussianProcess, data::DataFrame, n::Int = 1)Draw n independent realizations from the joint posterior predictive distribution of the Gaussian process in agp at the locations in data. This delegates to sample!(agp.gp, data, n) and returns its result.
Arguments
agp: Adaptive Gaussian process whose current fitted GP is sampled.data: Prediction locations containing the input columns used by the GP.n: Number of realizations to draw. Defaults to1.
UncertaintyQuantification.refine! Method
refine!(agp::AdaptiveGaussianProcess, n::Int = 1)Adaptively add up to n observations to agp and refit its Gaussian process. Each iteration samples candidates using agp.candidate_sampling, selects a candidate with agp.acquisition_function, evaluates agp.model there, and updates agp.gp. Training rows that duplicate existing rows are not appended. The fitted model is changed in place; the function returns nothing. Passing n = 0 leaves the model unchanged.
Arguments
agp: Adaptive Gaussian process to refine.n: Number of adaptive iterations. Defaults to1.
Distributions.logpdf Method
logpdf(agp::AdaptiveGaussianProcess, data::DataFrame)Evaluate the joint posterior predictive log density of the output values in data at the input locations in the same table. The calculation uses the current Gaussian process stored in agp.gp and returns its logpdf result.
Arguments
agp: Adaptive Gaussian process whose current fitted GP is used.data: DataFrame containing the GP input columns and observed output column.
Aqcuisition Functions
UncertaintyQuantification.MaximumVariance Type
MaximumVariance()Selects the candidate with the largest posterior variance.
Reference
Sacks, J., Welch, W. J., Mitchell, T. J., & Wynn, H. P. (1989). Design and Analysis of Computer Experiments. Statistical Science, 4(4), 409–423. https://doi.org/10.1214/ss/1177012413
sourceUncertaintyQuantification.ExpectedImprovement Type
ExpectedImprovement(ξ = 0.0)Selects the candidate maximizing expected improvement over the current best (minimum) observed training output. ξ controls the exploration/exploitation trade-off (higher ξ favors exploration).
Reference
Jones, D. R., Schonlau, M., & Welch, W. J. (1998). Efficient Global Optimization of Expensive Black-Box Functions. Journal of Global Optimization, 13(4), 455–492. https://doi.org/10.1023/A:1008306431147
sourceUncertaintyQuantification.ProbabilityOfImprovement Type
ProbabilityOfImprovement(ξ = 0.0)Selects the candidate maximizing the probability of improving over the current best (minimum) observed training output.
Reference
Kushner, H. J. (1964). A New Method of Locating the Maximum Point of an Arbitrary Multipeak Curve in the Presence of Noise. Journal of Basic Engineering, 86(1), 97–106. https://doi.org/10.1115/1.3653121
sourceUncertaintyQuantification.UpperConfidenceBound Type
UpperConfidenceBound(κ = 2.0)Selects the candidate minimizing μ(x) - κ·σ(x) (lower confidence bound for a minimization objective). κ controls the exploration weight.
Reference
Cox, D. D., & John, S. (1992). A Statistical Method for Global Optimization. Proceedings of the 1992 IEEE International Conference on Systems, Man, and Cybernetics, 1241–1246. https://doi.org/10.1109/ICSMC.1992.271617
sourceUncertaintyQuantification.DeviationNumber Type
DeviationNumber(threshold = 0.0)U-function: selects the candidate minimizing |μ(x) - threshold| / σ(x), i.e. the point closest to the limit state and with the highest uncertainty.
Reference
Echard, B., Gayton, N., & Lemaire, M. (2011). AK-MCS: An active learning reliability method combining Kriging and Monte Carlo Simulation. Structural Safety, 33(2), 145–154. https://doi.org/10.1016/j.strusafe.2011.01.002
sourceUncertaintyQuantification.ExpectedFeasibility Type
ExpectedFeasibility(threshold = 0.0, epsilon_factor = 2.0)Selects the candidate with the largest expected feasibility function (EFF) near the limit state G(x) = threshold. The feasibility half-width is set per candidate as epsilon_factor * σ(x).
Reference
Bichon, B. J., Eldred, M. S., Swiler, L. P., Mahadevan, S., & McFarland, J. M. (2008). Efficient Global Reliability Analysis for Nonlinear Implicit Performance Functions. AIAA Journal, 46(10), 2459-2468. https://doi.org/10.2514/1.34321
sourceUncertaintyQuantification.MaximinDistance Type
MaximinDistance()Space-filling score that selects the candidate farthest from every existing training point (maximizes the nearest-neighbor distance).
Reference
Johnson, M. E., Moore, L. M., & Ylvisaker, D. (1990). Minimax and Maximin Distance Designs. Journal of Statistical Planning and Inference, 26(2), 131–148. https://doi.org/10.1016/0378-3758(90)90122-B
sourceUncertaintyQuantification.ExpectedImprovementForGlobalFit Type
ExpectedImprovementForGlobalFit()EIGF score rewards candidates far (in output) from their nearest training observation, adjusted by local posterior variance.
Reference
Lam, C. Q. (2008). Sequential Adaptive Designs in Computer Experiments for Response Surface Model Fit. PhD dissertation, The Ohio State University.
source