.. 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. :author: Michel Bierlaire :date: Fri Nov 17 08:27:24 2023 .. GENERATED FROM PYTHON SOURCE LINES 13-20 .. code-block:: default import biogeme.version as ver import biogeme.distributions as dist from biogeme.expressions import Beta print(ver.getText()) .. rst-class:: sphx-glr-script-out .. code-block:: none biogeme 3.2.13 [2023-12-23] 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 21-26 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 28-29 Calculated for a numeric value. .. GENERATED FROM PYTHON SOURCE LINES 29-32 .. code-block:: default resulting_expression = dist.normalpdf(0) 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 33-35 .. code-block:: default resulting_expression.getValue() .. rst-class:: sphx-glr-script-out .. code-block:: none 0.39894228034270457 .. GENERATED FROM PYTHON SOURCE LINES 36-37 Calculated for an expression. .. GENERATED FROM PYTHON SOURCE LINES 37-41 .. code-block:: default 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 42-45 .. code-block:: default resulting_expression = dist.normalpdf(a_parameter, mu=mu, s=sigma) resulting_expression .. rst-class:: sphx-glr-script-out .. code-block:: none (exp((((-(Beta('a_parameter', 0, -1.3407807929942596e+154, 1.3407807929942596e+154, 1) - Beta('mu', 0, -1.3407807929942596e+154, 1.3407807929942596e+154, 1))) * (Beta('a_parameter', 0, -1.3407807929942596e+154, 1.3407807929942596e+154, 1) - Beta('mu', 0, -1.3407807929942596e+154, 1.3407807929942596e+154, 1))) / ((`2.0` * Beta('sigma', 1, -1.3407807929942596e+154, 1.3407807929942596e+154, 1)) * Beta('sigma', 1, -1.3407807929942596e+154, 1.3407807929942596e+154, 1)))) / (Beta('sigma', 1, -1.3407807929942596e+154, 1.3407807929942596e+154, 1) * `2.506628275`)) .. GENERATED FROM PYTHON SOURCE LINES 46-48 .. code-block:: default resulting_expression.getValue() .. rst-class:: sphx-glr-script-out .. code-block:: none 0.39894228034270457 .. GENERATED FROM PYTHON SOURCE LINES 49-54 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 56-57 Calculated for a numeric value. .. GENERATED FROM PYTHON SOURCE LINES 57-60 .. code-block:: default resulting_expression = dist.lognormalpdf(1) 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 61-63 .. code-block:: default resulting_expression.getValue() .. rst-class:: sphx-glr-script-out .. code-block:: none 0.39894228034270457 .. GENERATED FROM PYTHON SOURCE LINES 64-65 Calculated for an expression. .. GENERATED FROM PYTHON SOURCE LINES 65-69 .. code-block:: default 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 70-73 .. code-block:: default resulting_expression = dist.lognormalpdf(a_parameter, mu=mu, s=sigma) resulting_expression .. rst-class:: sphx-glr-script-out .. code-block:: none (((Beta('a_parameter', 1, -1.3407807929942596e+154, 1.3407807929942596e+154, 1) > `0.0`) * exp((((-(log(Beta('a_parameter', 1, -1.3407807929942596e+154, 1.3407807929942596e+154, 1)) - Beta('mu', 0, -1.3407807929942596e+154, 1.3407807929942596e+154, 1))) * (log(Beta('a_parameter', 1, -1.3407807929942596e+154, 1.3407807929942596e+154, 1)) - Beta('mu', 0, -1.3407807929942596e+154, 1.3407807929942596e+154, 1))) / ((`2.0` * Beta('sigma', 1, -1.3407807929942596e+154, 1.3407807929942596e+154, 1)) * Beta('sigma', 1, -1.3407807929942596e+154, 1.3407807929942596e+154, 1))))) / ((Beta('a_parameter', 1, -1.3407807929942596e+154, 1.3407807929942596e+154, 1) * Beta('sigma', 1, -1.3407807929942596e+154, 1.3407807929942596e+154, 1)) * `2.506628275`)) .. GENERATED FROM PYTHON SOURCE LINES 74-76 .. code-block:: default resulting_expression.getValue() .. rst-class:: sphx-glr-script-out .. code-block:: none 0.39894228034270457 .. GENERATED FROM PYTHON SOURCE LINES 77-83 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 85-86 Calculated for a numeric value .. GENERATED FROM PYTHON SOURCE LINES 86-89 .. code-block:: default resulting_expression = dist.uniformpdf(0) 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 90-92 .. code-block:: default resulting_expression.getValue() .. rst-class:: sphx-glr-script-out .. code-block:: none 0.5 .. GENERATED FROM PYTHON SOURCE LINES 93-94 Calculated for an expression .. GENERATED FROM PYTHON SOURCE LINES 94-98 .. code-block:: default 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 99-102 .. code-block:: default resulting_expression = dist.uniformpdf(a_parameter, a=a, b=b) resulting_expression .. rst-class:: sphx-glr-script-out .. code-block:: none ((((Beta('a_parameter', 0, -1.3407807929942596e+154, 1.3407807929942596e+154, 1) < Beta('a', -1, -1.3407807929942596e+154, 1.3407807929942596e+154, 1)) * `0.0`) + ((Beta('a_parameter', 0, -1.3407807929942596e+154, 1.3407807929942596e+154, 1) > Beta('b', 1, -1.3407807929942596e+154, 1.3407807929942596e+154, 1)) * `0.0`)) + (((Beta('a_parameter', 0, -1.3407807929942596e+154, 1.3407807929942596e+154, 1) >= Beta('a', -1, -1.3407807929942596e+154, 1.3407807929942596e+154, 1)) * (Beta('a_parameter', 0, -1.3407807929942596e+154, 1.3407807929942596e+154, 1) <= Beta('b', 1, -1.3407807929942596e+154, 1.3407807929942596e+154, 1))) / (Beta('b', 1, -1.3407807929942596e+154, 1.3407807929942596e+154, 1) - Beta('a', -1, -1.3407807929942596e+154, 1.3407807929942596e+154, 1)))) .. GENERATED FROM PYTHON SOURCE LINES 103-105 .. code-block:: default resulting_expression.getValue() .. rst-class:: sphx-glr-script-out .. code-block:: none 0.5 .. GENERATED FROM PYTHON SOURCE LINES 106-117 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 119-120 Calculated for a numeric value. .. GENERATED FROM PYTHON SOURCE LINES 120-123 .. code-block:: default resulting_expression = dist.triangularpdf(0) resulting_expression .. rst-class:: sphx-glr-script-out .. code-block:: none bioMultSum(((`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 124-126 .. code-block:: default resulting_expression.getValue() .. rst-class:: sphx-glr-script-out .. code-block:: none 1.0 .. GENERATED FROM PYTHON SOURCE LINES 127-128 Calculated for an expression. .. GENERATED FROM PYTHON SOURCE LINES 128-133 .. code-block:: default 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 134-137 .. code-block:: default resulting_expression = dist.triangularpdf(a_parameter, a=a, b=b, c=c) resulting_expression .. rst-class:: sphx-glr-script-out .. code-block:: none bioMultSum(((Beta('a_parameter', 0, -1.3407807929942596e+154, 1.3407807929942596e+154, 1) < Beta('a', -1, -1.3407807929942596e+154, 1.3407807929942596e+154, 1)) * `0.0`), ((((Beta('a_parameter', 0, -1.3407807929942596e+154, 1.3407807929942596e+154, 1) >= Beta('a', -1, -1.3407807929942596e+154, 1.3407807929942596e+154, 1)) * (Beta('a_parameter', 0, -1.3407807929942596e+154, 1.3407807929942596e+154, 1) < Beta('c', 0, -1.3407807929942596e+154, 1.3407807929942596e+154, 1))) * `2.0`) * ((Beta('a_parameter', 0, -1.3407807929942596e+154, 1.3407807929942596e+154, 1) - Beta('a', -1, -1.3407807929942596e+154, 1.3407807929942596e+154, 1)) / ((Beta('b', 1, -1.3407807929942596e+154, 1.3407807929942596e+154, 1) - Beta('a', -1, -1.3407807929942596e+154, 1.3407807929942596e+154, 1)) * (Beta('c', 0, -1.3407807929942596e+154, 1.3407807929942596e+154, 1) - Beta('a', -1, -1.3407807929942596e+154, 1.3407807929942596e+154, 1))))), (((Beta('a_parameter', 0, -1.3407807929942596e+154, 1.3407807929942596e+154, 1) == Beta('c', 0, -1.3407807929942596e+154, 1.3407807929942596e+154, 1)) * `2.0`) / (Beta('b', 1, -1.3407807929942596e+154, 1.3407807929942596e+154, 1) - Beta('a', -1, -1.3407807929942596e+154, 1.3407807929942596e+154, 1))), (((((Beta('a_parameter', 0, -1.3407807929942596e+154, 1.3407807929942596e+154, 1) > Beta('c', 0, -1.3407807929942596e+154, 1.3407807929942596e+154, 1)) * (Beta('a_parameter', 0, -1.3407807929942596e+154, 1.3407807929942596e+154, 1) <= Beta('b', 1, -1.3407807929942596e+154, 1.3407807929942596e+154, 1))) * `2.0`) * (Beta('b', 1, -1.3407807929942596e+154, 1.3407807929942596e+154, 1) - Beta('a_parameter', 0, -1.3407807929942596e+154, 1.3407807929942596e+154, 1))) / ((Beta('b', 1, -1.3407807929942596e+154, 1.3407807929942596e+154, 1) - Beta('a', -1, -1.3407807929942596e+154, 1.3407807929942596e+154, 1)) * (Beta('b', 1, -1.3407807929942596e+154, 1.3407807929942596e+154, 1) - Beta('c', 0, -1.3407807929942596e+154, 1.3407807929942596e+154, 1)))), ((Beta('a_parameter', 0, -1.3407807929942596e+154, 1.3407807929942596e+154, 1) > Beta('b', 1, -1.3407807929942596e+154, 1.3407807929942596e+154, 1)) * `0.0`)) .. GENERATED FROM PYTHON SOURCE LINES 138-140 .. code-block:: default resulting_expression.getValue() .. rst-class:: sphx-glr-script-out .. code-block:: none 1.0 .. GENERATED FROM PYTHON SOURCE LINES 141-148 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 150-151 Calculated for a numeric value .. GENERATED FROM PYTHON SOURCE LINES 151-154 .. code-block:: default resulting_expression = dist.logisticcdf(0) 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 155-157 .. code-block:: default resulting_expression.getValue() .. rst-class:: sphx-glr-script-out .. code-block:: none 0.5 .. GENERATED FROM PYTHON SOURCE LINES 158-159 Calculated for an expression .. GENERATED FROM PYTHON SOURCE LINES 159-163 .. code-block:: default 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 164-167 .. code-block:: default resulting_expression = dist.logisticcdf(a_parameter, mu=mu, s=sigma) resulting_expression .. rst-class:: sphx-glr-script-out .. code-block:: none (`1.0` / (`1.0` + exp(((-(Beta('a_parameter', 0, -1.3407807929942596e+154, 1.3407807929942596e+154, 1) - Beta('mu', 0, -1.3407807929942596e+154, 1.3407807929942596e+154, 1))) / Beta('sigma', 1, -1.3407807929942596e+154, 1.3407807929942596e+154, 1))))) .. GENERATED FROM PYTHON SOURCE LINES 168-169 .. code-block:: default resulting_expression.getValue() .. rst-class:: sphx-glr-script-out .. code-block:: none 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-python :download:`Download Python source code: plot_distributions.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_distributions.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_