Define and optimize the kriging mean term as a deterministic function dependent on space.

Hello,

I am currently trying to build a kriging model, but I am having difficulty defining the mean term as a function dependent on space. Here is a brief description of what I can do and what I want to do.

Kriging is formulated: Y(\omega,x)=\mu(x)+W(\omega,x)
For ordinary kriging, the deterministic term is formulated: \mu(x)=\beta
In this case, the implementation in OpenTurns is as follows:
basis = ot.ConstantBasisFactory(n_DIM).build()
model = ot.KrigingAlgorithm(x_OBS, y_OBS, covarianceModel, basis)
[…]
model.setOptimizationBounds(scaleOptimizationBounds)
model.setOptimizationAlgorithm(local_solver)
model.run()

For my study, I define the deterministic term such as: \mu(x)=\beta.\phi(x)
Given that the formulation of \mu has changed, I need to adapt the implementation in OpenTurns by changing the definition of the term basis.

Could you help me define basis as the product of a scalar \beta and a function defined in Python \phi(x)? (Note that \beta need to be optimized during the building of the kriging model and \phi(x) is not analytical.)

Best regards,

Clément.

Hi Clément,

The first thing to do is to create an OpenTURNS function based on your Python function. Then, you encapsulate it into a Basis and you can build a KrigingAlgorithm instance based on it:
``python
import openturns as ot

def myFuncPy(x): # x has to be a list of scalars or an 1d numpy array or an OT Point
return [x[0]**3] # the return value has to be a list of scalars or an 1d numpy array or an OT Point

# Adapt the dimensions to your case
inDim = 1
outDim = 1
myFunc = ot.PythonFunction(inDim, outDim, myFuncPy)

basis = ot.Basis([myFunc])
inSample = ot.Uniform().getSample(5)
outSample = ot.Uniform().getSample(5)
cov = ot.ExponentialModel()
myKriging = ot.KrigingAlgorithm(inSample, outSample, cov, basis)
```

Note that the KrigingAlgorithm class will be deprecated in favor of the GaussianProcessRegression class.

Cheers

Régis

1 Like