Skip to content

Gaussian Process Regression ​

Methods for Gaussian process regression.

Index ​

Types ​

UncertaintyQuantification.GaussianProcess Type
julia
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 except output; specify this argument to exclude metadata or other outputs.

Keyword Arguments

  • mean: Prior mean function. Defaults to ZeroMean().

  • kernel: Prior covariance kernel. Defaults to SqExponentialKernel().

  • normalize: Whether to standardize each input column using its training-data mean and standard deviation. Defaults to true. The fitted transformation is reused for predictions; false uses the inputs without transformation.

  • σ²: Nonnegative observation-noise variance. Defaults to 1.0e-10.

  • learn_noise: Whether to optimize the noise variance along with the other hyperparameters. Defaults to false; only takes effect when learn_hyperparameters = true.

  • learn_hyperparameters: Whether to optimize the prior hyperparameters. Defaults to true.

  • optimizer: Hyperparameter-optimization strategy. Defaults to MaximumLikelihoodEstimation(Optim.LBFGS(), Optim.Options(; iterations = 100, show_trace = false)).

Examples

julia
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
true
source
julia
GaussianProcess(
    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: A UQInput or vector of inputs defining the sampling distributions and parameters.

  • models: A UQModel or vector of models evaluated on the sampled data.

  • design: An AbstractMonteCarlo or AbstractDesignOfExperiments specifying 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 from inputs.

Keyword Arguments

  • mean: Prior mean function. Defaults to ZeroMean().

  • kernel: Prior covariance kernel. Defaults to SqExponentialKernel().

  • normalize: Whether to map the inputs to standard normal space using their distributions. Defaults to true. The same transformation is applied during prediction; false uses physical-space inputs directly.

  • σ²: Nonnegative observation-noise variance. Defaults to 1.0e-10.

  • learn_noise: Whether to optimize the noise variance along with the other hyperparameters. Defaults to false; only takes effect when learn_hyperparameters = true.

  • learn_hyperparameters: Whether to optimize the prior hyperparameters. Defaults to true.

  • optimizer: Hyperparameter-optimization strategy. Defaults to MaximumLikelihoodEstimation(Optim.LBFGS(), Optim.Options(; iterations = 100, show_trace = false)).

Examples

julia
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
true
source
UncertaintyQuantification.AdaptiveGaussianProcess Type
julia
AdaptiveGaussianProcess

An 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.

source
UncertaintyQuantification.MaximumLikelihoodEstimation Type
julia
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 be nothing when using gradient-free optimization)

Keyword Arguments

  • restarts: Number of additional randomized optimization runs. Defaults to 5.

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
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)
source

Functions ​

UncertaintyQuantification.evaluate! Method
julia
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 in gp.inputs.

Keyword Arguments

  • mean: Write the predictive mean to the column <output>_mean. Defaults to true.

  • variance: Write the predictive variance to the column <output>_var. Defaults to false.

Use sample! to draw joint samples from the predictive distribution.

Examples

julia
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)
true
source
UncertaintyQuantification.sample! Function
julia
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 in gp.inputs.

  • n: Number of realizations to draw. Defaults to 1.

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
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...))
true
source
Distributions.logpdf Method
julia
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.

source
UncertaintyQuantification.evaluate! Method
julia
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 to true.

  • variance: Whether to write the predictive variance. Defaults to false.

source
UncertaintyQuantification.sample! Function
julia
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 to 1.

source
UncertaintyQuantification.refine! Method
julia
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 to 1.

source
Distributions.logpdf Method
julia
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.

source

Aqcuisition Functions ​

UncertaintyQuantification.MaximumVariance Type
julia
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

source
UncertaintyQuantification.ExpectedImprovement Type
julia
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

source
UncertaintyQuantification.ProbabilityOfImprovement Type
julia
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

source
UncertaintyQuantification.UpperConfidenceBound Type
julia
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

source
UncertaintyQuantification.DeviationNumber Type
julia
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

source
UncertaintyQuantification.ExpectedFeasibility Type
julia
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

source
UncertaintyQuantification.MaximinDistance Type
julia
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

source
UncertaintyQuantification.ExpectedImprovementForGlobalFit Type
julia
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