.. 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_box_cox_transform.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_box_cox_transform.py: Use the Box-Cox transformation ============================== .. GENERATED FROM PYTHON SOURCE LINES 7-54 The objective of this Use Case is to estimate a Box Cox transformation from a field which all values are positive (eventually after a shift to satisfy the positiveness) and to apply it on the field. The object :class:`~openturns.BoxCoxFactory` enables to create a factory of Box Cox transformation. Then, we estimate the Box Cox transformation :math:`h_{\vect{\lambda}}` from the initial field values :math:`(\vect{x}_0, \dots, \vect{x}_{N-1})` thanks to the method `build` of the object :class:`~openturns.BoxCoxFactory`, which produces an object of type :class:`~openturns.BoxCoxTransform`. If the field values :math:`(\vect{x}_0, \dots, \vect{x}_{N-1})` have some negative values, it is possible to translate the values with respect a given shift :math:`\vect{\alpha}` which has to be mentioned either at the creation of the object :class:`~openturns.BoxCoxFactory` or when using the method `build`. Then the Box Cox transformation is the composition of :math:`h_{\vect{\lambda}}` and this translation. The object :class:`~openturns.BoxCoxTransform` enables to: - transform the field values :math:`(\vect{x}_{0}, \dots,\vect{x}_{N-1})` of dimension :math:`d` into the values :math:`(\vect{y}_{0}, \dots, \vect{y}_{N-1})` with stabilized variance, such that for each vertex :math:`\vect{t}_i` we have: :math:`\vect{y}_{i} = h_{\vect{\lambda}}(\vect{x}_{i})` or :math:`\vect{y}_{i} = h_{\vect{\lambda}}(\vect{x}_{i} + \vect{\alpha})` thanks to the operand (). The field based on the values :math:`\vect{y}_{i}` shares the same mesh than the initial field. - create the inverse Box Cox transformation such that : :math:`\vect{x}_{i}= h^{-1}_{\vect{\lambda}}(\vect{y}_{i})` or :math:`\vect{x}_{i} = h^{-1}_{\vect{\lambda}}(\vect{y}_{i}) - \vect{\alpha}` thanks to the method `getInverse()` which produces an object of type :class:`~openturns.InverseBoxCoxTransform` that can be evaluated on a field. The new field based shares the same mesh than the initial field. .. GENERATED FROM PYTHON SOURCE LINES 57-62 .. code-block:: Python import openturns as ot import openturns.viewer as viewer from matplotlib import pyplot as plt .. GENERATED FROM PYTHON SOURCE LINES 63-64 Define a process .. GENERATED FROM PYTHON SOURCE LINES 64-76 .. code-block:: Python myIndices = [10, 5] myMesher = ot.IntervalMesher(myIndices) myInterval = ot.Interval([0.0, 0.0], [2.0, 1.0]) myMesh = myMesher.build(myInterval) amplitude = [1.0] scale = [0.2, 0.2] myCovModel = ot.ExponentialModel(scale, amplitude) myXproc = ot.GaussianProcess(myCovModel, myMesh) g = ot.SymbolicFunction(["x1"], ["exp(x1)"]) myDynTransform = ot.ValueFunction(g, myMesh) myXtProcess = ot.CompositeProcess(myDynTransform, myXproc) .. GENERATED FROM PYTHON SOURCE LINES 77-78 Draw a field .. GENERATED FROM PYTHON SOURCE LINES 78-82 .. code-block:: Python field = myXtProcess.getRealization() graph = field.drawMarginal(0) view = viewer.View(graph) .. image-sg:: /auto_probabilistic_modeling/stochastic_processes/images/sphx_glr_plot_box_cox_transform_001.svg :alt: Unnamed - 0 marginal :srcset: /auto_probabilistic_modeling/stochastic_processes/images/sphx_glr_plot_box_cox_transform_001.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 83-84 Draw values .. GENERATED FROM PYTHON SOURCE LINES 84-88 .. code-block:: Python marginal = ot.HistogramFactory().build(field.getValues()) graph = marginal.drawPDF() view = viewer.View(graph) .. image-sg:: /auto_probabilistic_modeling/stochastic_processes/images/sphx_glr_plot_box_cox_transform_002.svg :alt: y0 PDF :srcset: /auto_probabilistic_modeling/stochastic_processes/images/sphx_glr_plot_box_cox_transform_002.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 89-90 Build the transformed field through Box-Cox .. GENERATED FROM PYTHON SOURCE LINES 90-93 .. code-block:: Python myModelTransform = ot.BoxCoxFactory().build(field) myStabilizedField = myModelTransform(field) .. GENERATED FROM PYTHON SOURCE LINES 94-95 Draw values .. GENERATED FROM PYTHON SOURCE LINES 95-99 .. code-block:: Python marginal = ot.HistogramFactory().build(myStabilizedField.getValues()) graph = marginal.drawPDF() view = viewer.View(graph) plt.show() .. image-sg:: /auto_probabilistic_modeling/stochastic_processes/images/sphx_glr_plot_box_cox_transform_003.svg :alt: y0 PDF :srcset: /auto_probabilistic_modeling/stochastic_processes/images/sphx_glr_plot_box_cox_transform_003.svg :class: sphx-glr-single-img .. _sphx_glr_download_auto_probabilistic_modeling_stochastic_processes_plot_box_cox_transform.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_box_cox_transform.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_box_cox_transform.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_box_cox_transform.zip `