.. 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_user_stationary_covmodel.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_user_stationary_covmodel.py: Create a stationary covariance model ==================================== .. GENERATED FROM PYTHON SOURCE LINES 6-18 This use case illustrates how the user can define his own stationary covariance model thanks to the object *UserDefinedStationaryCovarianceModel* defined from: - a mesh :math:`\mathcal{M}` of dimension :math:`n` defined by the vertices :math:`(\underline{\tau}_0,\dots, \underline{\tau}_{N-1})` and the associated simplices, - a collection of covariance matrices stored in the object *CovarianceMatrixCollection* noted :math:`\underline{\underline{C}}_0, \dots, \underline{\underline{C}}_{N-1}` where :math:`\underline{\underline{C}}_k` :math:`\in \mathcal{M}_{d \times d}(\mathbb{R})` for :math:`0 \leq k \leq N-1` Then we build a stationary covariance function which is a piecewise constant function on :math:`\mathcal{D}` defined by: .. math:: \forall \underline{\tau} \in \mathcal{D}, \, C^{stat}(\underline{\tau}) = \underline{\underline{C}}_k where :math:`k` is such that :math:`\underline{\tau}_k` is the vertex of :math:`\mathcal{M}` the nearest to :math:`\underline{t}.` .. GENERATED FROM PYTHON SOURCE LINES 20-26 .. 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 27-29 We detail the example described in the documentation Create the time grid .. GENERATED FROM PYTHON SOURCE LINES 29-48 .. code-block:: Python t0 = 0.0 dt = 0.5 N = int((20.0 - t0) / dt) mesh = ot.RegularGrid(t0, dt, N) # Create the covariance function def gamma(tau): return 1.0 / (1.0 + tau * tau) # Create the collection of HermitianMatrix coll = ot.SquareMatrixCollection() for k in range(N): t = mesh.getValue(k) matrix = ot.SquareMatrix([[gamma(t)]]) coll.add(matrix) .. GENERATED FROM PYTHON SOURCE LINES 49-50 Create the covariance model .. GENERATED FROM PYTHON SOURCE LINES 50-58 .. code-block:: Python covmodel = ot.UserDefinedStationaryCovarianceModel(mesh, coll) # One vertex of the mesh tau = 1.5 # Get the covariance function computed at the vertex tau covmodel(tau) .. raw:: html

[[ 0.307692 ]]



.. GENERATED FROM PYTHON SOURCE LINES 59-60 Graph of the spectral function .. GENERATED FROM PYTHON SOURCE LINES 60-76 .. code-block:: Python x = ot.Sample(N, 2) for k in range(N): t = mesh.getValue(k) x[k, 0] = t value = covmodel(t) x[k, 1] = value[0, 0] # Create the curve of the spectral function curve = ot.Curve(x, "User Model") # Create the graph myGraph = ot.Graph("User covariance model", "Time", "Covariance function", True) myGraph.add(curve) myGraph.setLegendPosition("upper right") view = viewer.View(myGraph) plt.show() .. image-sg:: /auto_probabilistic_modeling/stochastic_processes/images/sphx_glr_plot_user_stationary_covmodel_001.png :alt: User covariance model :srcset: /auto_probabilistic_modeling/stochastic_processes/images/sphx_glr_plot_user_stationary_covmodel_001.png :class: sphx-glr-single-img .. _sphx_glr_download_auto_probabilistic_modeling_stochastic_processes_plot_user_stationary_covmodel.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_user_stationary_covmodel.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_user_stationary_covmodel.py `