GaussianProcessFitter¶
(Source code
, svg
)
- class GaussianProcessFitter(*args)¶
Fit gaussian process models
Refer to Gaussian process regression.
Warning
This class is experimental and likely to be modified in future releases. To use it, import the
openturns.experimental
submodule.- Parameters:
- inputSample, outputSample
Sample
or 2d-array The samples
and
.
- covarianceModel
CovarianceModel
Covariance model of the Gaussian process. See notes for the details.
- basis
Basis
Functional basis to estimate the trend:
.
The same basis is used for each marginal output.
Default value is Basis(0), i.e. no trend to estimate.
- inputSample, outputSample
Methods
BuildDistribution
(inputSample)Recover the distribution, with metamodel performance in mind.
Accessor to the object's name.
Accessor to the joint probability density function of the physical input vector.
Accessor to the input sample.
Keep Cholesky factor accessor.
Accessor to the linear algebra method.
getName
()Accessor to the object's name.
Accessor to solver used to optimize the covariance model parameters.
Optimization bounds accessor.
Accessor to the covariance model parameters optimization flag.
Accessor to the output sample.
Accessor to the log-likelihood function that writes as argument of the covariance's model parameters.
Get the results of the metamodel computation.
Return the weights of the input sample.
hasName
()Test if the object is named.
run
()Compute the response surface.
setDistribution
(distribution)Accessor to the joint probability density function of the physical input vector.
setKeepCholeskyFactor
(keepCholeskyFactor)Keep Cholesky factor setter.
setMethod
(method)Accessor to the linear algebra method.
setName
(name)Accessor to the object's name.
setOptimizationAlgorithm
(solver)Accessor to the solver used to optimize the covariance model parameters.
setOptimizationBounds
(optimizationBounds)Optimization bounds accessor.
setOptimizeParameters
(optimizeParameters)Accessor to the covariance model parameters optimization flag.
Notes
Refer to Gaussian process regression (Step 1) to get all the notations and the theoretical aspects. We only detail here the notions related to the class.
We suppose we have a sample
where
for all
, with
a given function.
The class creates the Gaussian process
such that the sample
is considered as its restriction on
. It is defined by:
where
with
and
the trend function basis for
and
.
Furthermore,
is a Gaussian process of dimension
with zero mean and a specified covariance model.
The GaussianProcessFitter class estimates the coefficients
and
where
is the vector of the parameters of the covariance model that has been declared as active: see
openturns.CovarianceModel
to get details on the activation of the estimation of the other parameters.The estimation is done by maximizing the reduced log-likelihood of the mode, defined in (1).
The default optimizer is
Cobyla
and can be changed thanks to thesetOptimizationAlgorithm()
method. User could also change the default optimization solver by setting the entry GaussianProcessFitter-DefaultOptimizationAlgorithm ofResourceMap
to one of theNLopt
solver names.It is also possible to proceed as follows:
ask for the reduced log-likelihood function thanks to the
getReducedLogLikelihoodFunction()
method,optimize it with respect to the parameters
and
using any optimization algorithms (that can take into account some additional constraints if needed),
set the optimal parameter value into the covariance model used in the GaussianProcessFitter,
tell the algorithm not to optimize the parameter using the
setOptimizeParameters()
method.
The behaviour of the reduction is controlled by the following keys in
ResourceMap
:ResourceMap.SetAsBool(‘GaussianProcessFitter-UseAnalyticalAmplitudeEstimate’, True) to use the reduction associated to
. It has no effect if
or if
and
is not part of
,
ResourceMap.SetAsBool(‘GaussianProcessFitter-UnbiasedVariance’, True) allows one to use the unbiased estimate of
where
is replaced by
in the optimality condition for
.
With huge samples, the hierarchical matrix implementation could be used if hmat-oss support has been enabled.
This implementation, which is based on a compressed representation of an approximated covariance matrix (and its Cholesky factor), has a better complexity both in terms of memory requirements and floating point operations. To use it, the entry GaussianProcessFitter-LinearAlgebra of the
openturns.ResourceMap
class should be instancied to HMAT. Default value of the key is LAPACK.Examples
Create the model
and the samples:
>>> import openturns as ot >>> import openturns.experimental as otexp >>> g = ot.SymbolicFunction(['x'], ['x + x * sin(x)']) >>> inputSample = ot.Sample([[1.0], [3.0], [5.0], [6.0], [7.0], [8.0]]) >>> outputSample = g(inputSample)
Create the algorithm:
>>> g1 = ot.SymbolicFunction(['x'], ['sin(x)']) >>> g2 = ot.SymbolicFunction(['x'], ['x']) >>> g3 = ot.SymbolicFunction(['x'], ['cos(x)']) >>> basis = ot.Basis([g1, g2, g3]) >>> covarianceModel = ot.SquaredExponential([1.0]) >>> covarianceModel.setActiveParameter([]) >>> algo = otexp.GaussianProcessFitter(inputSample, outputSample, covarianceModel, basis) >>> algo.run()
Get the resulting metamodel which is the trend function of the Gaussian process:
>>> result = algo.getResult() >>> metamodel = result.getMetaModel()
- __init__(*args)¶
- static BuildDistribution(inputSample)¶
Recover the distribution, with metamodel performance in mind.
For each marginal, find the best 1-d continuous parametric model else fallback to the use of a nonparametric one.
The selection is done as follow:
We start with a list of all parametric models (all factories)
For each model, we estimate its parameters if feasible.
We check then if model is valid, ie if its Kolmogorov score exceeds a threshold fixed in the MetaModelAlgorithm-PValueThreshold ResourceMap key. Default value is 5%
We sort all valid models and return the one with the optimal criterion.
For the last step, the criterion might be BIC, AIC or AICC. The specification of the criterion is done through the MetaModelAlgorithm-ModelSelectionCriterion ResourceMap key. Default value is fixed to BIC. Note that if there is no valid candidate, we estimate a non-parametric model (
KernelSmoothing
orHistogram
). The MetaModelAlgorithm-NonParametricModel ResourceMap key allows selecting the preferred one. Default value is HistogramOne each marginal is estimated, we use the Spearman independence test on each component pair to decide whether an independent copula. In case of non independence, we rely on a
NormalCopula
.- Parameters:
- sample
Sample
Input sample.
- sample
- Returns:
- distribution
Distribution
Input distribution.
- distribution
- getClassName()¶
Accessor to the object’s name.
- Returns:
- class_namestr
The object class name (object.__class__.__name__).
- getDistribution()¶
Accessor to the joint probability density function of the physical input vector.
- Returns:
- distribution
Distribution
Joint probability density function of the physical input vector.
- distribution
- getInputSample()¶
Accessor to the input sample.
- Returns:
- inputSample
Sample
Input sample of a model evaluated apart.
- inputSample
- getKeepCholeskyFactor()¶
Keep Cholesky factor accessor.
- Returns:
- keepCholeskybool
Tells whether we keep or not the final Cholesky factor.
- getMethod()¶
Accessor to the linear algebra method.
- Returns:
- linAlgMethodint
The used linear algebra method to fit the model:
otexp.GaussianProcessFitterResult.LAPACK or 0: using LAPACK to fit the model,
otexp.GaussianProcessFitterResult.HMAT or 1: using HMAT to fit the model.
- getName()¶
Accessor to the object’s name.
- Returns:
- namestr
The name of the object.
- getOptimizationAlgorithm()¶
Accessor to solver used to optimize the covariance model parameters.
- Returns:
- algorithm
OptimizationAlgorithm
Solver used to optimize the covariance model parameters. Default optimizer is
Cobyla
- algorithm
- getOptimizationBounds()¶
Optimization bounds accessor.
- Returns:
- bounds
Interval
Bounds for covariance model parameter optimization.
- bounds
- getOptimizeParameters()¶
Accessor to the covariance model parameters optimization flag.
- Returns:
- optimizeParametersbool
Whether to optimize the covariance model parameters.
- getOutputSample()¶
Accessor to the output sample.
- Returns:
- outputSample
Sample
Output sample of a model evaluated apart.
- outputSample
- getReducedLogLikelihoodFunction()¶
Accessor to the log-likelihood function that writes as argument of the covariance’s model parameters.
- Returns:
Notes
The log-likelihood function may be useful for some postprocessing: maximization using external optimizers for example.
Examples
Create the model
and the samples:
>>> import openturns as ot >>> import openturns.experimental as otexp >>> g = ot.SymbolicFunction(['x0'], ['x0 * sin(x0)']) >>> inputSample = ot.Sample([[1.0], [3.0], [5.0], [6.0], [7.0], [8.0]]) >>> outputSample = g(inputSample)
Create the algorithm:
>>> basis = ot.ConstantBasisFactory().build() >>> covarianceModel = ot.SquaredExponential(1) >>> algo = otexp.GaussianProcessFitter(inputSample, outputSample, covarianceModel, basis) >>> algo.run()
Get the log-likelihood function:
>>> likelihoodFunction = algo.getReducedLogLikelihoodFunction()
- getResult()¶
Get the results of the metamodel computation.
- Returns:
- result
GaussianProcessFitterResult
Structure containing all the results obtained after computation and created by the method
run()
.
- result
- getWeights()¶
Return the weights of the input sample.
- Returns:
- weightssequence of float
The weights of the points in the input sample.
- hasName()¶
Test if the object is named.
- Returns:
- hasNamebool
True if the name is not empty.
- run()¶
Compute the response surface.
Notes
It computes the response surface and creates a
GaussianProcessFitterResult
structure containing all the results.
- setDistribution(distribution)¶
Accessor to the joint probability density function of the physical input vector.
- Parameters:
- distribution
Distribution
Joint probability density function of the physical input vector.
- distribution
- setKeepCholeskyFactor(keepCholeskyFactor)¶
Keep Cholesky factor setter.
- Parameters:
- keepCholeskybool
Tells whether we keep or not the final Cholesky factor.
- setMethod(method)¶
Accessor to the linear algebra method.
- Parameters:
- linAlgMethodint
The used linear algebra method to fit the model:
otexp.GaussianProcessFitterResult.LAPACK or 0: using LAPACK to fit the model,
otexp.GaussianProcessFitterResult.HMAT or 1: using HMAT to fit the model.
- setName(name)¶
Accessor to the object’s name.
- Parameters:
- namestr
The name of the object.
- setOptimizationAlgorithm(solver)¶
Accessor to the solver used to optimize the covariance model parameters.
- Parameters:
- algorithm
OptimizationAlgorithm
Solver used to optimize the covariance model parameters.
- algorithm
- setOptimizationBounds(optimizationBounds)¶
Optimization bounds accessor.
- Parameters:
- bounds
Interval
Bounds for covariance model parameter optimization.
- bounds
Notes
Parameters involved by this method are:
Scale parameters,
Amplitude parameters if output dimension is greater than one or analytical sigma disabled,
Additional parameters.
Lower & upper bounds are defined in resource map. Default lower upper bounds value for all parameters is
and defined thanks to the GaussianProcessFitter-DefaultOptimizationLowerBound resource map key.
For scale parameters, default upper bounds are set as
times the difference between the max and min values of X for each coordinate, X being the (transformed) input sample. The value
is defined in resource map (GaussianProcessFitter-DefaultOptimizationScaleFactor).
Finally for other parameters (amplitude,…), default upper bound is set to
(corresponding resource map key is GaussianProcessFitter-DefaultOptimizationUpperBound)
- setOptimizeParameters(optimizeParameters)¶
Accessor to the covariance model parameters optimization flag.
- Parameters:
- optimizeParametersbool
Whether to optimize the covariance model parameters.
Examples using the class¶
Gaussian Process Regression: multiple input dimensions
Gaussian Process-based active learning for reliability

Gaussian Process Regression: choose an arbitrary trend
Gaussian Process Regression: choose a polynomial trend on the beam model
Gaussian Process Regression : cantilever beam model
Gaussian Process Regression: surrogate model with continuous and categorical variables
Gaussian Process Regression: choose a polynomial trend

Gaussian process fitter: configure the optimization solver
Gaussian Process Regression: use an isotropic covariance kernel
Gaussian Process Regression : generate trajectories from the metamodel
Gaussian Process Regression: metamodel of the Branin-Hoo function
Example of multi output Gaussian Process Regression on the fire satellite model
Sequentially adding new points to a Gaussian Process metamodel
Gaussian Process Regression: propagate uncertainties