Note
Go to the end to download the full example code.
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
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())
biogeme 3.3.1 [2025-09-03]
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)
pdf of the normal distributio: returns the biogeme expression of the probability density function of the normal distribution:
Calculated for a numeric value.
resulting_expression = normalpdf(0)
display(resulting_expression)
(exp((((-(`0.0` - `0.0`)) * (`0.0` - `0.0`)) / ((`2.0` * `1.0`) * `1.0`))) / (`1.0` * `2.506628275`))
resulting_expression.get_value()
np.float64(0.39894228034270457)
Calculated for an expression.
a_parameter = Beta('a_parameter', 0, None, None, 1)
mu = Beta('mu', 0, None, None, 1)
sigma = Beta('sigma', 1, None, None, 1)
resulting_expression = normalpdf(a_parameter, mu=mu, s=sigma)
display(resulting_expression)
(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`))
resulting_expression.get_value()
np.float64(0.39894228034270457)
pdf of the lognormal distribution: returns the biogeme expression of the probability density function of the lognormal distribution
Calculated for a numeric value.
resulting_expression = lognormalpdf(1)
display(resulting_expression)
(((`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`))
resulting_expression.get_value()
np.float64(0.39894228034270457)
Calculated for an expression.
a_parameter = Beta('a_parameter', 1, None, None, 1)
mu = Beta('mu', 0, None, None, 1)
sigma = Beta('sigma', 1, None, None, 1)
resulting_expression = lognormalpdf(a_parameter, mu=mu, s=sigma)
display(resulting_expression)
(((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`))
resulting_expression.get_value()
np.float64(0.39894228034270457)
pdf of the uniform distribution: returns the biogeme expression of the probability density function of the uniform distribution
Calculated for a numeric value
resulting_expression = uniformpdf(0)
display(resulting_expression)
((((`0.0` < `-1.0`) * `0.0`) + ((`0.0` > `1.0`) * `0.0`)) + (((`0.0` >= `-1.0`) * (`0.0` <= `1.0`)) / (`1.0` - `-1.0`)))
resulting_expression.get_value()
0.5
Calculated for an expression
a_parameter = Beta('a_parameter', 0, None, None, 1)
a = Beta('a', -1, None, None, 1)
b = Beta('b', 1, None, None, 1)
resulting_expression = uniformpdf(a_parameter, a=a, b=b)
display(resulting_expression)
((((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))))
resulting_expression.get_value()
0.5
pdf of the triangular distribution: returns the biogeme expression of the probability density function of the triangular distribution
It is assumed that \(a < c < b\). It is not verified.
Calculated for a numeric value.
resulting_expression = triangularpdf(0)
display(resulting_expression)
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`))
resulting_expression.get_value()
1.0
Calculated for an expression.
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)
resulting_expression = triangularpdf(a_parameter, a=a, b=b, c=c)
display(resulting_expression)
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`))
resulting_expression.get_value()
1.0
CDF of the logistic distribution: returns the biogeme expression of the cumulative distribution function of the logistic distribution
Calculated for a numeric value
resulting_expression = logisticcdf(0)
display(resulting_expression)
(`1.0` / (`1.0` + exp(((-(`0.0` - `0.0`)) / `1.0`))))
resulting_expression.get_value()
np.float64(0.5)
Calculated for an expression
a_parameter = Beta('a_parameter', 0, None, None, 1)
mu = Beta('mu', 0, None, None, 1)
sigma = Beta('sigma', 1, None, None, 1)
resulting_expression = logisticcdf(a_parameter, mu=mu, s=sigma)
display(resulting_expression)
(`1.0` / (`1.0` + exp(((-(Beta('a_parameter', 0, None, None, 1) - Beta('mu', 0, None, None, 1))) / Beta('sigma', 1, None, None, 1)))))
resulting_expression.get_value()
np.float64(0.5)
Total running time of the script: (0 minutes 0.003 seconds)