Biogeme: Python Library  2.5
loglikelihood.py
Go to the documentation of this file.
1 ## \file
2 # Functions to calculate the log likelihood
3 
4 from biogeme import *
5 
6 ## Simply computes the log of the probability
7 # \ingroup likelihood
8 # \param prob An <a
9 # href="http://biogeme.epfl.ch/expressions.html">expression</a>
10 # providing the value of the probability.
11 # \return The logarithm of the probability.
12 #
13 def loglikelihood(prob):
14  loglikelihood = log(prob)
15  return loglikelihood
16 
17 ## Compute a simulated loglikelihood function
18 # \ingroup likelihood
19 # \param prob An <a
20 # href="http://biogeme.epfl.ch/expressions.html">expression</a>
21 # providing the value of the probability. Although it is not formally
22 # necessary, the expression should contain one or more <a
23 # href="http://biogeme.epfl.ch/expressions.php#draws"
24 # target="_blank">random variables</a> of a given distribution, and
25 # therefore write \f[ P(i|\xi_1,\ldots,\xi_L)\f]
26 # \return The simulated
27 # loglikelihood, given by
28 # \f[ \ln\left(\sum_{r=1}^R P(i|\xi^r_1,\ldots,\xi^r_L) \right)\f]
29 # where \f$R\f$ is the number of draws, and \f$\xi_j^r\f$ is the
30 # <em>r</em>th draw of the random variable \f$\xi_j\f$.
31 #
32 def mixedloglikelihood(prob):
33  l = MonteCarlo(prob)
34  return log(l)
35 
36 ## Computes likelihood function of a regression model.
37 # \ingroup likelihood
38 # \param meas An <a href="http://biogeme.epfl.ch/expressions.html">expression</a> providing the value \f$y\f$ of the measure for the current observation.
39 # \param model An <a href="http://biogeme.epfl.ch/expressions.html">expression</a> providing the output \f$m\f$ of the model for the current observation.
40 # \param sigma An <a href="http://biogeme.epfl.ch/expressions.html">expression</a>
41 # (typically, a <a href="http://biogeme.epfl.ch/expressions.php#parameter">parameter</a>)
42 # providing the standard error \f$\sigma\f$ of the error term.
43 # \return The likelihood of the regression, assuming a normal
44 # distribution, that is
45 # \f[
46 # \frac{1}{\sigma} \phi\left( \frac{y-m}{\sigma} \right)
47 # \f]
48 # where \f$ \phi(\cdot)\f$ is the pdf of the normal distribution.
49 #
50 def likelihoodregression(meas,model,sigma):
51  t = (meas - model) / sigma
52  f = bioNormalPdf(t) / sigma
53  return f
54 
55 
56 ## Computes log likelihood function of a regression model.
57 # \ingroup likelihood
58 # \param meas An <a href="http://biogeme.epfl.ch/expressions.html">expression</a> providing the value \f$y\f$ of the measure for the current observation.
59 # \param model An <a href="http://biogeme.epfl.ch/expressions.html">expression</a> providing the output \f$m\f$ of the model for the current observation.
60 # \param sigma An <a href="http://biogeme.epfl.ch/expressions.html">expression</a>
61 # (typically, a <a href="http://biogeme.epfl.ch/expressions.php#parameter">parameter</a>)
62 # providing the standard error \f$\sigma\f$ of the error term.
63 # \return The likelihood of the regression, assuming a normal
64 # distribution, that is
65 # \f[
66 # -\left( \frac{(y-m)^2}{2\sigma^2} \right) - \log(\sigma) - \frac{1}{2}\log(2\pi)
67 # \f]
68 #
69 #
70 def loglikelihoodregression(meas,model,sigma):
71  t = (meas - model) / sigma
72  f = - t * t / 2 - log(sigma) -0.9189385332
73  return f
74 
75 
def loglikelihood(prob)
Simply computes the log of the probability.
def loglikelihoodregression(meas, model, sigma)
Computes log likelihood function of a regression model.
def likelihoodregression(meas, model, sigma)
Computes likelihood function of a regression model.
def mixedloglikelihood(prob)
Compute a simulated loglikelihood function.
Copyright 2016 Michel Bierlaire