.. 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 Click :ref:`here ` 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-17 .. code-block:: default 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 18-22 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 24-29 .. code-block:: default dimension = 1 amplitude = [1.0] * dimension scale = [1] * dimension covarianceModel = ot.GeneralizedExponential(scale, amplitude, 2) .. GENERATED FROM PYTHON SOURCE LINES 30-31 We define the time grid on which we want to sample the Gaussian process. .. GENERATED FROM PYTHON SOURCE LINES 33-38 .. code-block:: default tmin = 0.0 step = 0.01 n = 10001 timeGrid = ot.RegularGrid(tmin, step, n) .. GENERATED FROM PYTHON SOURCE LINES 39-40 Finally we define the Gaussian process. .. GENERATED FROM PYTHON SOURCE LINES 40-43 .. code-block:: default process = ot.GaussianProcess(covarianceModel, timeGrid) print(process) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none GaussianProcess(trend=[x0]->[0.0], covariance=GeneralizedExponential(scale=[1], amplitude=[1], p=2)) .. GENERATED FROM PYTHON SOURCE LINES 44-50 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 52-53 We set the sampling method to `HMAT` (default is the classical/dense case). .. GENERATED FROM PYTHON SOURCE LINES 53-56 .. code-block:: default process.setSamplingMethod(ot.GaussianProcess.HMAT) .. GENERATED FROM PYTHON SOURCE LINES 57-58 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 58-60 .. code-block:: default ot.ResourceMap.SetAsString("HMatrix-CompressionMethod", "AcaRandom") .. GENERATED FROM PYTHON SOURCE LINES 61-63 There are two threshold used in the HMatrix framework. The `AssemblyEpsilon` is the most important one. .. GENERATED FROM PYTHON SOURCE LINES 63-67 .. code-block:: default ot.ResourceMap.SetAsScalar("HMatrix-AssemblyEpsilon", 1e-7) ot.ResourceMap.SetAsScalar("HMatrix-RecompressionEpsilon", 1e-7) .. GENERATED FROM PYTHON SOURCE LINES 68-70 Process sampling ---------------- .. GENERATED FROM PYTHON SOURCE LINES 72-73 We eventually draw samples of this covariance model. .. GENERATED FROM PYTHON SOURCE LINES 73-78 .. code-block:: default 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 79-80 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. .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 2.310 seconds) .. _sphx_glr_download_auto_probabilistic_modeling_stochastic_processes_plot_gaussian_process_covariance_hmat.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_gaussian_process_covariance_hmat.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_gaussian_process_covariance_hmat.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_