Create a Gaussian process with or without nugget effect

This example shows how to create a Gaussian process:

  • from its covariance function,

  • from its covariance function including a nugget effect,

  • from its spectral density in the stationary case.

import openturns as ot
import openturns.viewer as otv

# sphinx_gallery_thumbnail_number = 2

Create a Gaussian process from its covariance model

Here, we create a Gaussian process \vect{X}: \Omega \times \cD \rightarrow \Rset on a domain \cD \subset \Rset from its covariance model.

See Covariance models to get more details on covariance models.

We first define a covariance model. We use a MaternModel model. By default, the nugget factor is equal to 10^{-12} and is defined through the CovarianceModel-DefaultNuggetFactor key in the class ResourceMap. That is why we set it to zero.

amplitude = [1.0]
scale = [1.0]
myModel = ot.MaternModel(scale, amplitude, 2.5)
myModel.setNuggetFactor(0.0)

We define a mesh that discretizes the domain \cD. We use a RegularGrid.

tmin = 0.0
N = 200
tmax = 5
step = (tmin - tmax) / (N - 1)
myTimeGrid = ot.RegularGrid(tmin, step, N)

We create the Gaussian process from the covariance model and the mesh.

GaussianProcess(trend=[x0]->[0], covariance=MaternModel(scale=[1], amplitude=[1], nu=2.5))

We draw some realizations of the Gaussian process.

n_real = 3
sample = process.getSample(n_real)
graph = sample.drawMarginal(0)
graph.setTitle("Processs realizations")
view = otv.View(graph)
Processs realizations

Add a nugget effect to the Gaussian process

Here, we add a nugget effect to the Gaussian process. We use the previous Gaussian process. The nugget factor is \varepsilon_{nugget}.

Refer to Covariance models to get more details on covariance models and the introduction of a nugget factor, and in particular see equation (5).

Refer also to the example Create a covariance model with and without a nugget effect which illustrates the impact of the nugget effect on a covariance model.

Adding a nugget factor modifies the covariance model. It transforms the process by adding a white noise of dimension \processDim with zero mean and a covariance matrix equal to \varepsilon_{nugget} \mat{C}^{spatial}:

\vect{X}_{nugget}(\omega, \vect{t}) = \vect{X}(\omega, \vect{t}) +
\vect{\varepsilon}(\omega), \quad \vect{\varepsilon} \sim \cN(\vect{0},
\varepsilon_{nugget} \mat{C}^{spatial})

We fix \varepsilon_{nugget} = 0.05.

GaussianProcess(trend=[x0]->[0], covariance=MaternModel(scale=[1], amplitude=[1], nu=2.5))

We draw some realizations of the Gaussian process. We notice that the realizations of the process with the nugget factor are more chaotic than the other ones.

Process realizations with nugget effect

Create a Gaussian process from its spectral density

Here, we create a Gaussian process \vect{X}: \Omega \times \cD \rightarrow \Rset on a domain \cD \subset \Rset from its spectral density.

We first define a spectral model. We use a CauchyModel.

amplitude = [1.0]
scale = [4.0]
mySpectralModel = ot.CauchyModel(scale, amplitude)

We define the associated mesh which is a RegularGrid.

myTimeGrid = ot.RegularGrid(0.0, 0.1, 20)

We create the Gaussian process using a SpectralGaussianProcess.

SpectralGaussianProcess=SpectralGaussianProcess dimension=1 spectralModel=class=CauchyModel amplitude=[1] scale=[4] no spatial correlation maximal frequency=5 n frequency=10

Eventually we draw some realizations of the Gaussian process.

Processs realizations

Display all figures.