.. 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_random_walk_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_probabilistic_modeling_stochastic_processes_plot_random_walk_process.py: Create a random walk process ============================ .. GENERATED FROM PYTHON SOURCE LINES 6-24 This example details first how to create and manipulate a random walk. A random walk :math:`X: \Omega \times \mathcal{D} \rightarrow \mathbb{R}^d` is a process where :math:`\mathcal{D}=\mathbb{R}` discretized on the time grid :math:`(t_i)_{i \geq 0}` such that: .. math:: \begin{aligned} X_{t_0} & = & \underline{x}_{t_0} \\ \forall n>0,\: X_{t_n} & = & X_{t_{n-1}} + \varepsilon_{t_n} \end{aligned} where :math:`\underline{x}_0 \in \mathbb{R}^d` and :math:`\varepsilon` is a white noise of dimension :math:`d`. The library proposes to model it through the object *RandomWalk* defined thanks to the origin, the distribution of the white noise and the time grid. .. GENERATED FROM PYTHON SOURCE LINES 26-32 .. 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 33-34 Define the origin .. GENERATED FROM PYTHON SOURCE LINES 34-36 .. code-block:: Python origin = [0.0] .. GENERATED FROM PYTHON SOURCE LINES 37-38 Define an 1-d mesh .. GENERATED FROM PYTHON SOURCE LINES 38-40 .. code-block:: Python tgrid = ot.RegularGrid(0.0, 1.0, 500) .. GENERATED FROM PYTHON SOURCE LINES 41-42 1-d random walk and discrete distribution .. GENERATED FROM PYTHON SOURCE LINES 42-49 .. code-block:: Python dist = ot.UserDefined([[-1], [10]], [0.9, 0.1]) process = ot.RandomWalk(origin, dist, tgrid) sample = process.getSample(5) graph = sample.drawMarginal(0) graph.setTitle("1D Random Walk with discrete steps") view = viewer.View(graph) .. image-sg:: /auto_probabilistic_modeling/stochastic_processes/images/sphx_glr_plot_random_walk_process_001.png :alt: 1D Random Walk with discrete steps :srcset: /auto_probabilistic_modeling/stochastic_processes/images/sphx_glr_plot_random_walk_process_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 50-51 1-d random walk and continuous distribution .. GENERATED FROM PYTHON SOURCE LINES 51-58 .. code-block:: Python dist = ot.Normal(0.0, 1.0) process = ot.RandomWalk(origin, dist, tgrid) sample = process.getSample(5) graph = sample.drawMarginal(0) graph.setTitle("1D Random Walk with continuous steps") view = viewer.View(graph) .. image-sg:: /auto_probabilistic_modeling/stochastic_processes/images/sphx_glr_plot_random_walk_process_002.png :alt: 1D Random Walk with continuous steps :srcset: /auto_probabilistic_modeling/stochastic_processes/images/sphx_glr_plot_random_walk_process_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 59-60 Define the origin .. GENERATED FROM PYTHON SOURCE LINES 60-62 .. code-block:: Python origin = [0.0] * 2 .. GENERATED FROM PYTHON SOURCE LINES 63-64 color palette .. GENERATED FROM PYTHON SOURCE LINES 64-66 .. code-block:: Python pal = ["red", "cyan", "blue", "yellow", "green"] .. GENERATED FROM PYTHON SOURCE LINES 67-68 2-d random walk and discrete distribution .. GENERATED FROM PYTHON SOURCE LINES 68-76 .. code-block:: Python dist = ot.UserDefined([[-1.0, -2.0], [1.0, 3.0]], [0.5, 0.5]) process = ot.RandomWalk(origin, dist, tgrid) sample = process.getSample(5) graph = ot.Graph("2D Random Walk with discrete steps", "X1", "X2", True) for i in range(5): graph.add(ot.Curve(sample[i], pal[i % len(pal)], "solid")) view = viewer.View(graph) .. image-sg:: /auto_probabilistic_modeling/stochastic_processes/images/sphx_glr_plot_random_walk_process_003.png :alt: 2D Random Walk with discrete steps :srcset: /auto_probabilistic_modeling/stochastic_processes/images/sphx_glr_plot_random_walk_process_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 77-78 2-d random walk and continuous distribution .. GENERATED FROM PYTHON SOURCE LINES 78-86 .. code-block:: Python dist = ot.Normal(2) process = ot.RandomWalk(origin, dist, tgrid) sample = process.getSample(5) graph = ot.Graph("2D Random Walk with continuous steps", "X1", "X2", True) for i in range(5): graph.add(ot.Curve(sample[i], pal[i % len(pal)], "solid")) view = viewer.View(graph) plt.show() .. image-sg:: /auto_probabilistic_modeling/stochastic_processes/images/sphx_glr_plot_random_walk_process_004.png :alt: 2D Random Walk with continuous steps :srcset: /auto_probabilistic_modeling/stochastic_processes/images/sphx_glr_plot_random_walk_process_004.png :class: sphx-glr-single-img .. _sphx_glr_download_auto_probabilistic_modeling_stochastic_processes_plot_random_walk_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_random_walk_process.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_random_walk_process.py `