.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_stochastic_processes/plot_create_normal_process.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_stochastic_processes_plot_create_normal_process.py: Create a Gaussian process with or without nugget effect ======================================================= .. GENERATED FROM PYTHON SOURCE LINES 7-12 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. .. GENERATED FROM PYTHON SOURCE LINES 14-19 .. code-block:: Python import openturns as ot import openturns.viewer as otv # sphinx_gallery_thumbnail_number = 2 .. GENERATED FROM PYTHON SOURCE LINES 20-31 Create a Gaussian process from its covariance model --------------------------------------------------- Here, we create a Gaussian process :math:`\vect{X}: \Omega \times \cD \rightarrow \Rset` on a domain :math:`\cD \in \Rset` from its covariance model. See :ref:`Covariance models ` to get more details on covariance models. We first define a covariance model. We use a :class:`~openturns.MaternModel` model. By default, the nugget factor is equal to :math:`10^{-12}` and is defined through the `CovarianceModel-DefaultNuggetFactor` key in the class :class:`~openturns.ResourceMap`. That is why we set it to zero. .. GENERATED FROM PYTHON SOURCE LINES 31-36 .. code-block:: Python amplitude = [1.0] scale = [1.0] myModel = ot.MaternModel(scale, amplitude, 2.5) myModel.setNuggetFactor(0.0) .. GENERATED FROM PYTHON SOURCE LINES 37-38 We define a mesh that discretizes the domain :math:`\cD`. We use a :class:`~openturns.RegularGrid`. .. GENERATED FROM PYTHON SOURCE LINES 38-44 .. code-block:: Python tmin = 0.0 N = 200 tmax = 5 step = (tmin - tmax) / (N - 1) myTimeGrid = ot.RegularGrid(tmin, step, N) .. GENERATED FROM PYTHON SOURCE LINES 45-46 We create the Gaussian process from the covariance model and the mesh. .. GENERATED FROM PYTHON SOURCE LINES 46-49 .. code-block:: Python process = ot.GaussianProcess(myModel, myTimeGrid) print(process) .. rst-class:: sphx-glr-script-out .. code-block:: none GaussianProcess(trend=[x0]->[0], covariance=MaternModel(scale=[1], amplitude=[1], nu=2.5)) .. GENERATED FROM PYTHON SOURCE LINES 50-51 We draw some realizations of the Gaussian process. .. GENERATED FROM PYTHON SOURCE LINES 51-58 .. code-block:: Python n_real = 3 sample = process.getSample(n_real) graph = sample.drawMarginal(0) graph.setTitle("Processs realizations") view = otv.View(graph) .. image-sg:: /auto_stochastic_processes/images/sphx_glr_plot_create_normal_process_001.svg :alt: Processs realizations :srcset: /auto_stochastic_processes/images/sphx_glr_plot_create_normal_process_001.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 59-84 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 :math:`\varepsilon_{nugget}`. Refer to :ref:`Covariance models ` to get more details on covariance models and the introduction of a nugget factor, and in particular see equation :eq:`Css`. Refer also to the example :doc:`/auto_stochastic_processes/plot_covariance_model_nugget` 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 :math:`d` with zero mean and a covariance matrix equal to :math:`\varepsilon_{nugget} \mat{C}^{spatial}`: .. math:: \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 :math:`\varepsilon_{nugget} = 0.05`. .. GENERATED FROM PYTHON SOURCE LINES 84-89 .. code-block:: Python epsilon_nugget = 0.05 myModel.setNuggetFactor(epsilon_nugget) process_nugget = ot.GaussianProcess(myModel, myTimeGrid) print(process_nugget) .. rst-class:: sphx-glr-script-out .. code-block:: none GaussianProcess(trend=[x0]->[0], covariance=MaternModel(scale=[1], amplitude=[1], nu=2.5)) .. GENERATED FROM PYTHON SOURCE LINES 90-92 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. .. GENERATED FROM PYTHON SOURCE LINES 92-97 .. code-block:: Python sample_nugget = process_nugget.getSample(n_real) graph_nugget = sample_nugget.drawMarginal(0) graph_nugget.setTitle("Process realizations with nugget effect") view = otv.View(graph_nugget) .. image-sg:: /auto_stochastic_processes/images/sphx_glr_plot_create_normal_process_002.svg :alt: Process realizations with nugget effect :srcset: /auto_stochastic_processes/images/sphx_glr_plot_create_normal_process_002.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 98-105 Create a Gaussian process from its spectral density --------------------------------------------------- Here, we create a Gaussian process :math:`\vect{X}: \Omega \times \cD \rightarrow \Rset` on a domain :math:`\cD \in \Rset` from its spectral density. We first define a spectral model. We use a :class:`~openturns.CauchyModel`. .. GENERATED FROM PYTHON SOURCE LINES 105-109 .. code-block:: Python amplitude = [1.0] scale = [4.0] mySpectralModel = ot.CauchyModel(scale, amplitude) .. GENERATED FROM PYTHON SOURCE LINES 110-111 We define the associated mesh which is a :class:`~openturns.RegularGrid`. .. GENERATED FROM PYTHON SOURCE LINES 111-113 .. code-block:: Python myTimeGrid = ot.RegularGrid(0.0, 0.1, 20) .. GENERATED FROM PYTHON SOURCE LINES 114-115 We create the Gaussian process using a :class:`~openturns.SpectralGaussianProcess`. .. GENERATED FROM PYTHON SOURCE LINES 115-118 .. code-block:: Python process = ot.SpectralGaussianProcess(mySpectralModel, myTimeGrid) print(process) .. rst-class:: sphx-glr-script-out .. code-block:: none SpectralGaussianProcess=SpectralGaussianProcess dimension=1 spectralModel=class=CauchyModel amplitude=[1] scale=[4] no spatial correlation maximal frequency=5 n frequency=10 .. GENERATED FROM PYTHON SOURCE LINES 119-120 Eventually we draw some realizations of the Gaussian process. .. GENERATED FROM PYTHON SOURCE LINES 120-125 .. code-block:: Python sample = process.getSample(n_real) graph = sample.drawMarginal(0) graph.setTitle("Processs realizations") view = otv.View(graph) .. image-sg:: /auto_stochastic_processes/images/sphx_glr_plot_create_normal_process_003.svg :alt: Processs realizations :srcset: /auto_stochastic_processes/images/sphx_glr_plot_create_normal_process_003.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 126-127 Display all figures. .. GENERATED FROM PYTHON SOURCE LINES 127-128 .. code-block:: Python otv.View.ShowAll() .. _sphx_glr_download_auto_stochastic_processes_plot_create_normal_process.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_create_normal_process.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_create_normal_process.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_create_normal_process.zip `