.. 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_process_manipulation.py: Process manipulation ==================== The objective here is to manipulate a multivariate stochastic process :math:`X: \Omega \times \mathcal{D} \rightarrow \mathbb{R}^d`, where :math:`\mathcal{D} \in \mathbb{R}^n` is discretized on the mesh :math:`\mathcal{M}` and exhibit some of the services exposed by the *Process* objects: - ask for the dimension, with the method getOutputDimension - ask for the mesh, with the method getMesh - ask for the mesh as regular 1-d mesh, with the getTimeGrid method - ask for a realization, with the method the getRealization method - ask for a continuous realization, with the getContinuousRealization method - ask for a sample of realizations, with the getSample method - ask for the normality of the process with the isNormal method - ask for the stationarity of the process with the isStationary method .. code-block:: default from __future__ import print_function import openturns as ot import openturns.viewer as viewer from matplotlib import pylab as plt import math as m ot.Log.Show(ot.Log.NONE) Create a mesh which is a RegularGrid .. code-block:: default tMin = 0.0 timeStep = 0.1 n = 100 time_grid = ot.RegularGrid(tMin, timeStep, n) time_grid.setName('time') Create a process of dimension 3 Normal process with an Exponential covariance model Amplitude and scale values of the Exponential model .. code-block:: default scale = [4.0] amplitude = [1.0, 2.0, 3.0] # spatialCorrelation spatialCorrelation = ot.CorrelationMatrix(3) spatialCorrelation[0, 1] = 0.8 spatialCorrelation[0, 2] = 0.6 spatialCorrelation[1, 2] = 0.1 myCovarianceModel = ot.ExponentialModel(scale, amplitude, spatialCorrelation) process = ot.GaussianProcess(myCovarianceModel, time_grid) Get the dimension d of the process .. code-block:: default process.getOutputDimension() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 3 Get the mesh of the process .. code-block:: default mesh = process.getMesh() # Get the corners of the mesh minMesh = mesh.getVertices().getMin()[0] maxMesh = mesh.getVertices().getMax()[0] graph = mesh.draw() view = viewer.View(graph) .. image:: /auto_probabilistic_modeling/stochastic_processes/images/sphx_glr_plot_process_manipulation_001.png :alt: Mesh time :class: sphx-glr-single-img Get the time grid of the process only when the mesh can be interpreted as a regular time grid .. code-block:: default process.getTimeGrid() .. raw:: html

RegularGrid(start=0, step=0.1, n=100)



Get a realisation of the process .. code-block:: default realization = process.getRealization() #realization Draw one realization .. code-block:: default interpolate=False graph = realization.drawMarginal(0, interpolate) view = viewer.View(graph) .. image:: /auto_probabilistic_modeling/stochastic_processes/images/sphx_glr_plot_process_manipulation_002.png :alt: Unnamed - 0 marginal :class: sphx-glr-single-img Same graph, but draw interpolated values .. code-block:: default graph = realization.drawMarginal(0) view = viewer.View(graph) .. image:: /auto_probabilistic_modeling/stochastic_processes/images/sphx_glr_plot_process_manipulation_003.png :alt: Unnamed - 0 marginal :class: sphx-glr-single-img Get a function representing the process using P1 Lagrange interpolation (when not defined from a functional model) .. code-block:: default continuousRealization = process.getContinuousRealization() Draw its first marginal .. code-block:: default marginal0 = continuousRealization.getMarginal(0) graph = marginal0.draw(minMesh, maxMesh) view = viewer.View(graph) .. image:: /auto_probabilistic_modeling/stochastic_processes/images/sphx_glr_plot_process_manipulation_004.png :alt: y0 as a function of x0 :class: sphx-glr-single-img Get several realizations of the process .. code-block:: default number = 10 fieldSample = process.getSample(number) #fieldSample Draw a sample of the process .. code-block:: default graph = fieldSample.drawMarginal(0, False) view = viewer.View(graph) .. image:: /auto_probabilistic_modeling/stochastic_processes/images/sphx_glr_plot_process_manipulation_005.png :alt: Unnamed - 0 marginal :class: sphx-glr-single-img Same graph, but draw interpolated values .. code-block:: default graph = fieldSample.drawMarginal(0) view = viewer.View(graph) .. image:: /auto_probabilistic_modeling/stochastic_processes/images/sphx_glr_plot_process_manipulation_006.png :alt: Unnamed - 0 marginal :class: sphx-glr-single-img Get the marginal of the process at index 1 Care! Numerotation begins at 0 Not yet implemented for some processes .. code-block:: default process.getMarginal([1]) .. raw:: html

GaussianProcess(trend=[x0]->[0.0], covariance=ExponentialModel(scale=[4], amplitude=[2], no spatial correlation))



Get the marginal of the process at index in indices Not yet implemented for some processes .. code-block:: default process.getMarginal([0, 1]) .. raw:: html

GaussianProcess(trend=[x0]->[0.0,0.0], covariance=ExponentialModel(scale=[4], amplitude=[1,2], spatial correlation=
[[ 1 0.8 ]
[ 0.8 1 ]]))



Check wether the process is normal .. code-block:: default process.isNormal() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none True Check wether the process is stationary .. code-block:: default process.isStationary() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.543 seconds) .. _sphx_glr_download_auto_probabilistic_modeling_stochastic_processes_plot_process_manipulation.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_process_manipulation.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_process_manipulation.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_