.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_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_stochastic_processes_plot_random_walk_process.py: Create a random walk process ============================ .. GENERATED FROM PYTHON SOURCE LINES 7-25 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} & = & \vect{x}_{t_0} \\ \forall n>0,\: X_{t_n} & = & X_{t_{n-1}} + \varepsilon_{t_n} \end{aligned} where :math:`\vect{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 :class:`~openturns.RandomWalk` defined thanks to the origin, the distribution of the white noise and the time grid. .. GENERATED FROM PYTHON SOURCE LINES 27-30 .. code-block:: Python import openturns as ot import openturns.viewer as otv .. GENERATED FROM PYTHON SOURCE LINES 31-32 Define the origin .. GENERATED FROM PYTHON SOURCE LINES 32-34 .. code-block:: Python origin = [0.0] .. GENERATED FROM PYTHON SOURCE LINES 35-36 Define an 1-d mesh .. GENERATED FROM PYTHON SOURCE LINES 36-38 .. code-block:: Python tgrid = ot.RegularGrid(0.0, 1.0, 500) .. GENERATED FROM PYTHON SOURCE LINES 39-40 1-d random walk and discrete distribution .. GENERATED FROM PYTHON SOURCE LINES 40-47 .. 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 = otv.View(graph) .. image-sg:: /auto_stochastic_processes/images/sphx_glr_plot_random_walk_process_001.svg :alt: 1D Random Walk with discrete steps :srcset: /auto_stochastic_processes/images/sphx_glr_plot_random_walk_process_001.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 48-49 1-d random walk and continuous distribution .. GENERATED FROM PYTHON SOURCE LINES 49-56 .. 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 = otv.View(graph) .. image-sg:: /auto_stochastic_processes/images/sphx_glr_plot_random_walk_process_002.svg :alt: 1D Random Walk with continuous steps :srcset: /auto_stochastic_processes/images/sphx_glr_plot_random_walk_process_002.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 57-58 Define the origin .. GENERATED FROM PYTHON SOURCE LINES 58-60 .. code-block:: Python origin = [0.0] * 2 .. GENERATED FROM PYTHON SOURCE LINES 61-62 Color palette .. GENERATED FROM PYTHON SOURCE LINES 62-64 .. code-block:: Python pal = ["red", "cyan", "blue", "yellow", "green"] .. GENERATED FROM PYTHON SOURCE LINES 65-66 2-d random walk and discrete distribution .. GENERATED FROM PYTHON SOURCE LINES 66-74 .. 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 = otv.View(graph) .. image-sg:: /auto_stochastic_processes/images/sphx_glr_plot_random_walk_process_003.svg :alt: 2D Random Walk with discrete steps :srcset: /auto_stochastic_processes/images/sphx_glr_plot_random_walk_process_003.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 75-76 2-d random walk and continuous distribution .. GENERATED FROM PYTHON SOURCE LINES 76-84 .. 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 = otv.View(graph) .. image-sg:: /auto_stochastic_processes/images/sphx_glr_plot_random_walk_process_004.svg :alt: 2D Random Walk with continuous steps :srcset: /auto_stochastic_processes/images/sphx_glr_plot_random_walk_process_004.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 85-86 Display all figures .. GENERATED FROM PYTHON SOURCE LINES 86-87 .. code-block:: Python otv.View.ShowAll() .. _sphx_glr_download_auto_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 ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_random_walk_process.zip `