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

**URL:** <https://openturns.discourse.group/t/define-and-optimize-the-kriging-mean-term-as-a-deterministic-function-dependent-on-space/425>\
**Category:** Python usage\
**Tags:** kriging\
**Created:** [September 28, 2025, 3:36pm UTC](https://openturns.discourse.group/t/define-and-optimize-the-kriging-mean-term-as-a-deterministic-function-dependent-on-space/425 "2025-09-28T15:36:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Clement](https://avatars.discourse-cdn.com/v4/letter/c/7ba0ec/32.png) [@Clement](https://openturns.discourse.group/u/Clement)\
**Post date:** [September 28, 2025, 3:36pm UTC](https://openturns.discourse.group/t/define-and-optimize-the-kriging-mean-term-as-a-deterministic-function-dependent-on-space/425/1 "2025-09-28T15:36:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![regislebrun](https://yyz2.discourse-cdn.com/free1/user_avatar/openturns.discourse.group/regislebrun/32/154_2.png) [@regislebrun](https://openturns.discourse.group/u/regislebrun)\
**Post date:** [September 30, 2025, 7:16pm UTC](https://openturns.discourse.group/t/define-and-optimize-the-kriging-mean-term-as-a-deterministic-function-dependent-on-space/425/2 "2025-09-30T19:16:52Z")

</div>

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
