.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_probabilistic_modeling/stochastic_processes/plot_gaussian_process_covariance_hmat.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_probabilistic_modeling_stochastic_processes_plot_gaussian_process_covariance_hmat.py: Create a gaussian process from a cov. model using HMatrix ========================================================= .. GENERATED FROM PYTHON SOURCE LINES 6-9 In this basic example we build a gaussian process from its covariance model and use the `HMatrix` method as a sampling method. Several methods and parameters are presented to set the HMatrix compression. This is an advanced topic and we should highlight key ideas only in this example. .. GENERATED FROM PYTHON SOURCE LINES 12-18 .. code-block:: Python import openturns as ot import openturns.viewer as viewer from matplotlib import pylab as plt # ot.Log.Show(ot.Log.NONE) .. GENERATED FROM PYTHON SOURCE LINES 19-23 Definition of the covariance model ---------------------------------- We define our Gaussian process from its covariance model. We consider a Gaussian kernel with the following parameters. .. GENERATED FROM PYTHON SOURCE LINES 25-30 .. code-block:: Python dimension = 1 amplitude = [1.0] * dimension scale = [1] * dimension covarianceModel = ot.GeneralizedExponential(scale, amplitude, 2) .. GENERATED FROM PYTHON SOURCE LINES 31-32 We define the time grid on which we want to sample the Gaussian process. .. GENERATED FROM PYTHON SOURCE LINES 34-39 .. code-block:: Python tmin = 0.0 step = 0.01 n = 10001 timeGrid = ot.RegularGrid(tmin, step, n) .. GENERATED FROM PYTHON SOURCE LINES 40-41 Finally we define the Gaussian process. .. GENERATED FROM PYTHON SOURCE LINES 41-44 .. code-block:: Python process = ot.GaussianProcess(covarianceModel, timeGrid) print(process) .. rst-class:: sphx-glr-script-out .. code-block:: none GaussianProcess(trend=[x0]->[0.0], covariance=GeneralizedExponential(scale=[1], amplitude=[1], p=2)) .. GENERATED FROM PYTHON SOURCE LINES 45-51 Basics on the HMatrix algebra ----------------------------- The `HMatrix` framework uses efficient linear algebra techniques to speed-up the (Cholesky) factorization of the covariance matrix. This method can be tuned with several parameters. We should concentrate on the easiest ones. .. GENERATED FROM PYTHON SOURCE LINES 53-54 We set the sampling method to `HMAT` (default is the classical/dense case). .. GENERATED FROM PYTHON SOURCE LINES 54-57 .. code-block:: Python process.setSamplingMethod(ot.GaussianProcess.HMAT) .. GENERATED FROM PYTHON SOURCE LINES 58-59 The `HMatrix` framework uses an algebraic algorithm to compress sub-blocks of the matrix. Several algorithms are available and can be set from the ResourceMap key. .. GENERATED FROM PYTHON SOURCE LINES 59-61 .. code-block:: Python ot.ResourceMap.SetAsString("HMatrix-CompressionMethod", "AcaRandom") .. GENERATED FROM PYTHON SOURCE LINES 62-64 There are two threshold used in the HMatrix framework. The `AssemblyEpsilon` is the most important one. .. GENERATED FROM PYTHON SOURCE LINES 64-68 .. code-block:: Python ot.ResourceMap.SetAsScalar("HMatrix-AssemblyEpsilon", 1e-7) ot.ResourceMap.SetAsScalar("HMatrix-RecompressionEpsilon", 1e-7) .. GENERATED FROM PYTHON SOURCE LINES 69-71 Process sampling ---------------- .. GENERATED FROM PYTHON SOURCE LINES 73-74 We eventually draw samples of this covariance model. .. GENERATED FROM PYTHON SOURCE LINES 74-79 .. code-block:: Python sample = process.getSample(6) graph = sample.drawMarginal(0) view = viewer.View(graph) plt.show() .. image-sg:: /auto_probabilistic_modeling/stochastic_processes/images/sphx_glr_plot_gaussian_process_covariance_hmat_001.png :alt: Unnamed - 0 marginal :srcset: /auto_probabilistic_modeling/stochastic_processes/images/sphx_glr_plot_gaussian_process_covariance_hmat_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 80-81 We notice here that we are able to sample the covariance model over a mesh of size `10000`, which is usually tricky on a laptop. This is mainly due to the compression. .. GENERATED FROM PYTHON SOURCE LINES 83-84 Reset default settings .. GENERATED FROM PYTHON SOURCE LINES 84-85 .. code-block:: Python ot.ResourceMap.Reload() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.123 seconds) .. _sphx_glr_download_auto_probabilistic_modeling_stochastic_processes_plot_gaussian_process_covariance_hmat.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_gaussian_process_covariance_hmat.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_gaussian_process_covariance_hmat.py `