.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/programmers/plot_distributions.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_examples_programmers_plot_distributions.py: biogeme.distributions ===================== Example of usage of the `distributions` module. This is for programmers who need examples of use of the functions of the class. The examples are designed to illustrate the syntax. Michel Bierlaire Sun Jun 29 2025, 07:12:12 .. GENERATED FROM PYTHON SOURCE LINES 13-28 .. code-block:: Python from IPython.core.display_functions import display from biogeme.distributions import ( logisticcdf, lognormalpdf, normalpdf, triangularpdf, uniformpdf, ) from biogeme.expressions import Beta from biogeme.version import get_text print(get_text()) .. rst-class:: sphx-glr-script-out .. code-block:: none biogeme 3.3.3a0 [2025-12-25] Home page: http://biogeme.epfl.ch Submit questions to https://groups.google.com/d/forum/biogeme Michel Bierlaire, Transport and Mobility Laboratory, Ecole Polytechnique Fédérale de Lausanne (EPFL) .. GENERATED FROM PYTHON SOURCE LINES 29-34 pdf of the normal distributio: returns the biogeme expression of the probability density function of the normal distribution: .. math:: f(x;\mu, \sigma) = \frac{1}{\sigma \sqrt{2\pi}} \exp{-\frac{(x-\mu)^2}{2\sigma^2}}. .. GENERATED FROM PYTHON SOURCE LINES 36-37 Calculated for a numeric value. .. GENERATED FROM PYTHON SOURCE LINES 37-40 .. code-block:: Python resulting_expression = normalpdf(0) display(resulting_expression) .. rst-class:: sphx-glr-script-out .. code-block:: none (exp((((-(`0.0` - `0.0`)) * (`0.0` - `0.0`)) / ((`2.0` * `1.0`) * `1.0`))) / (`1.0` * `2.506628275`)) .. GENERATED FROM PYTHON SOURCE LINES 41-43 .. code-block:: Python resulting_expression.get_value() .. rst-class:: sphx-glr-script-out .. code-block:: none np.float64(0.39894228034270457) .. GENERATED FROM PYTHON SOURCE LINES 44-45 Calculated for an expression. .. GENERATED FROM PYTHON SOURCE LINES 45-49 .. code-block:: Python a_parameter = Beta('a_parameter', 0, None, None, 1) mu = Beta('mu', 0, None, None, 1) sigma = Beta('sigma', 1, None, None, 1) .. GENERATED FROM PYTHON SOURCE LINES 50-53 .. code-block:: Python resulting_expression = normalpdf(a_parameter, mu=mu, s=sigma) display(resulting_expression) .. rst-class:: sphx-glr-script-out .. code-block:: none (exp((((-(Beta('a_parameter', 0, None, None, 1) - Beta('mu', 0, None, None, 1))) * (Beta('a_parameter', 0, None, None, 1) - Beta('mu', 0, None, None, 1))) / ((`2.0` * Beta('sigma', 1, None, None, 1)) * Beta('sigma', 1, None, None, 1)))) / (Beta('sigma', 1, None, None, 1) * `2.506628275`)) .. GENERATED FROM PYTHON SOURCE LINES 54-56 .. code-block:: Python resulting_expression.get_value() .. rst-class:: sphx-glr-script-out .. code-block:: none np.float64(0.39894228034270457) .. GENERATED FROM PYTHON SOURCE LINES 57-62 pdf of the lognormal distribution: returns the biogeme expression of the probability density function of the lognormal distribution .. math:: f(x;\mu, \sigma) = \frac{1}{x\sigma \sqrt{2\pi}} \exp{-\frac{(\ln x-\mu)^2}{2\sigma^2}} .. GENERATED FROM PYTHON SOURCE LINES 64-65 Calculated for a numeric value. .. GENERATED FROM PYTHON SOURCE LINES 65-68 .. code-block:: Python resulting_expression = lognormalpdf(1) display(resulting_expression) .. rst-class:: sphx-glr-script-out .. code-block:: none (((`1.0` > `0.0`) * exp((((-(log(`1.0`) - `0.0`)) * (log(`1.0`) - `0.0`)) / ((`2.0` * `1.0`) * `1.0`)))) / ((`1.0` * `1.0`) * `2.506628275`)) .. GENERATED FROM PYTHON SOURCE LINES 69-71 .. code-block:: Python resulting_expression.get_value() .. rst-class:: sphx-glr-script-out .. code-block:: none np.float64(0.39894228034270457) .. GENERATED FROM PYTHON SOURCE LINES 72-73 Calculated for an expression. .. GENERATED FROM PYTHON SOURCE LINES 73-77 .. code-block:: Python a_parameter = Beta('a_parameter', 1, None, None, 1) mu = Beta('mu', 0, None, None, 1) sigma = Beta('sigma', 1, None, None, 1) .. GENERATED FROM PYTHON SOURCE LINES 78-81 .. code-block:: Python resulting_expression = lognormalpdf(a_parameter, mu=mu, s=sigma) display(resulting_expression) .. rst-class:: sphx-glr-script-out .. code-block:: none (((Beta('a_parameter', 1, None, None, 1) > `0.0`) * exp((((-(log(Beta('a_parameter', 1, None, None, 1)) - Beta('mu', 0, None, None, 1))) * (log(Beta('a_parameter', 1, None, None, 1)) - Beta('mu', 0, None, None, 1))) / ((`2.0` * Beta('sigma', 1, None, None, 1)) * Beta('sigma', 1, None, None, 1))))) / ((Beta('a_parameter', 1, None, None, 1) * Beta('sigma', 1, None, None, 1)) * `2.506628275`)) .. GENERATED FROM PYTHON SOURCE LINES 82-84 .. code-block:: Python resulting_expression.get_value() .. rst-class:: sphx-glr-script-out .. code-block:: none np.float64(0.39894228034270457) .. GENERATED FROM PYTHON SOURCE LINES 85-91 pdf of the uniform distribution: returns the biogeme expression of the probability density function of the uniform distribution .. math:: f(x; a, b) = \left\{ \begin{array}{ll} \frac{1}{b-a} & \mbox{for } x \in [a, b] \\ 0 & \mbox{otherwise}\end{array} \right. .. GENERATED FROM PYTHON SOURCE LINES 93-94 Calculated for a numeric value .. GENERATED FROM PYTHON SOURCE LINES 94-97 .. code-block:: Python resulting_expression = uniformpdf(0) display(resulting_expression) .. rst-class:: sphx-glr-script-out .. code-block:: none ((((`0.0` < `-1.0`) * `0.0`) + ((`0.0` > `1.0`) * `0.0`)) + (((`0.0` >= `-1.0`) * (`0.0` <= `1.0`)) / (`1.0` - `-1.0`))) .. GENERATED FROM PYTHON SOURCE LINES 98-100 .. code-block:: Python resulting_expression.get_value() .. rst-class:: sphx-glr-script-out .. code-block:: none 0.5 .. GENERATED FROM PYTHON SOURCE LINES 101-102 Calculated for an expression .. GENERATED FROM PYTHON SOURCE LINES 102-106 .. code-block:: Python a_parameter = Beta('a_parameter', 0, None, None, 1) a = Beta('a', -1, None, None, 1) b = Beta('b', 1, None, None, 1) .. GENERATED FROM PYTHON SOURCE LINES 107-110 .. code-block:: Python resulting_expression = uniformpdf(a_parameter, a=a, b=b) display(resulting_expression) .. rst-class:: sphx-glr-script-out .. code-block:: none ((((Beta('a_parameter', 0, None, None, 1) < Beta('a', -1, None, None, 1)) * `0.0`) + ((Beta('a_parameter', 0, None, None, 1) > Beta('b', 1, None, None, 1)) * `0.0`)) + (((Beta('a_parameter', 0, None, None, 1) >= Beta('a', -1, None, None, 1)) * (Beta('a_parameter', 0, None, None, 1) <= Beta('b', 1, None, None, 1))) / (Beta('b', 1, None, None, 1) - Beta('a', -1, None, None, 1)))) .. GENERATED FROM PYTHON SOURCE LINES 111-113 .. code-block:: Python resulting_expression.get_value() .. rst-class:: sphx-glr-script-out .. code-block:: none 0.5 .. GENERATED FROM PYTHON SOURCE LINES 114-125 pdf of the triangular distribution: returns the biogeme expression of the probability density function of the triangular distribution .. math:: f(x;a, b, c) = \left\{ \begin{array}{ll} 0 & \text{if } x < a \\\frac{2(x-a)}{(b-a)(c-a)} & \text{if } a \leq x < c \\\frac{2(b-x)}{(b-a)(b-c)} & \text{if } c \leq x < b \\0 & \text{if } x \geq b. \end{array} \right. It is assumed that :math:`a < c < b`. It is not verified. .. GENERATED FROM PYTHON SOURCE LINES 127-128 Calculated for a numeric value. .. GENERATED FROM PYTHON SOURCE LINES 128-131 .. code-block:: Python resulting_expression = triangularpdf(0) display(resulting_expression) .. rst-class:: sphx-glr-script-out .. code-block:: none MultipleSum(((`0.0` < `-1.0`) * `0.0`), ((((`0.0` >= `-1.0`) * (`0.0` < `0.0`)) * `2.0`) * ((`0.0` - `-1.0`) / ((`1.0` - `-1.0`) * (`0.0` - `-1.0`)))), (((`0.0` == `0.0`) * `2.0`) / (`1.0` - `-1.0`)), (((((`0.0` > `0.0`) * (`0.0` <= `1.0`)) * `2.0`) * (`1.0` - `0.0`)) / ((`1.0` - `-1.0`) * (`1.0` - `0.0`))), ((`0.0` > `1.0`) * `0.0`)) .. GENERATED FROM PYTHON SOURCE LINES 132-134 .. code-block:: Python resulting_expression.get_value() .. rst-class:: sphx-glr-script-out .. code-block:: none 1.0 .. GENERATED FROM PYTHON SOURCE LINES 135-136 Calculated for an expression. .. GENERATED FROM PYTHON SOURCE LINES 136-141 .. code-block:: Python a_parameter = Beta('a_parameter', 0, None, None, 1) a = Beta('a', -1, None, None, 1) b = Beta('b', 1, None, None, 1) c = Beta('c', 0, None, None, 1) .. GENERATED FROM PYTHON SOURCE LINES 142-145 .. code-block:: Python resulting_expression = triangularpdf(a_parameter, a=a, b=b, c=c) display(resulting_expression) .. rst-class:: sphx-glr-script-out .. code-block:: none MultipleSum(((Beta('a_parameter', 0, None, None, 1) < Beta('a', -1, None, None, 1)) * `0.0`), ((((Beta('a_parameter', 0, None, None, 1) >= Beta('a', -1, None, None, 1)) * (Beta('a_parameter', 0, None, None, 1) < Beta('c', 0, None, None, 1))) * `2.0`) * ((Beta('a_parameter', 0, None, None, 1) - Beta('a', -1, None, None, 1)) / ((Beta('b', 1, None, None, 1) - Beta('a', -1, None, None, 1)) * (Beta('c', 0, None, None, 1) - Beta('a', -1, None, None, 1))))), (((Beta('a_parameter', 0, None, None, 1) == Beta('c', 0, None, None, 1)) * `2.0`) / (Beta('b', 1, None, None, 1) - Beta('a', -1, None, None, 1))), (((((Beta('a_parameter', 0, None, None, 1) > Beta('c', 0, None, None, 1)) * (Beta('a_parameter', 0, None, None, 1) <= Beta('b', 1, None, None, 1))) * `2.0`) * (Beta('b', 1, None, None, 1) - Beta('a_parameter', 0, None, None, 1))) / ((Beta('b', 1, None, None, 1) - Beta('a', -1, None, None, 1)) * (Beta('b', 1, None, None, 1) - Beta('c', 0, None, None, 1)))), ((Beta('a_parameter', 0, None, None, 1) > Beta('b', 1, None, None, 1)) * `0.0`)) .. GENERATED FROM PYTHON SOURCE LINES 146-148 .. code-block:: Python resulting_expression.get_value() .. rst-class:: sphx-glr-script-out .. code-block:: none 1.0 .. GENERATED FROM PYTHON SOURCE LINES 149-156 CDF of the logistic distribution: returns the biogeme expression of the cumulative distribution function of the logistic distribution .. math:: f(x;\mu, \sigma) = \frac{1}{1+\exp\left(-\frac{x-\mu}{\sigma} \right)} .. GENERATED FROM PYTHON SOURCE LINES 158-159 Calculated for a numeric value .. GENERATED FROM PYTHON SOURCE LINES 159-162 .. code-block:: Python resulting_expression = logisticcdf(0) display(resulting_expression) .. rst-class:: sphx-glr-script-out .. code-block:: none (`1.0` / (`1.0` + exp(((-(`0.0` - `0.0`)) / `1.0`)))) .. GENERATED FROM PYTHON SOURCE LINES 163-165 .. code-block:: Python resulting_expression.get_value() .. rst-class:: sphx-glr-script-out .. code-block:: none np.float64(0.5) .. GENERATED FROM PYTHON SOURCE LINES 166-167 Calculated for an expression .. GENERATED FROM PYTHON SOURCE LINES 167-171 .. code-block:: Python a_parameter = Beta('a_parameter', 0, None, None, 1) mu = Beta('mu', 0, None, None, 1) sigma = Beta('sigma', 1, None, None, 1) .. GENERATED FROM PYTHON SOURCE LINES 172-175 .. code-block:: Python resulting_expression = logisticcdf(a_parameter, mu=mu, s=sigma) display(resulting_expression) .. rst-class:: sphx-glr-script-out .. code-block:: none (`1.0` / (`1.0` + exp(((-(Beta('a_parameter', 0, None, None, 1) - Beta('mu', 0, None, None, 1))) / Beta('sigma', 1, None, None, 1))))) .. GENERATED FROM PYTHON SOURCE LINES 176-177 .. code-block:: Python resulting_expression.get_value() .. rst-class:: sphx-glr-script-out .. code-block:: none np.float64(0.5) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.003 seconds) .. _sphx_glr_download_auto_examples_programmers_plot_distributions.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_distributions.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_distributions.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_distributions.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_