Biogeme: Python Library  2.5
mev.py
Go to the documentation of this file.
1 ## @file
2 # Functions for the MEV model
3 
4 from biogeme import *
5 
6 ## Choice probability for a MEV model.
7 # @ingroup models
8 # \param V A <a
9 # href="http://docs.python.org/py3k/tutorial/datastructures.html#dictionaries"
10 # target="_blank">dictionary</a> mapping each alternative id with the
11 # expression of the utility function.
12 # @param Gi A <a
13 # href="http://docs.python.org/py3k/tutorial/datastructures.html#dictionaries"
14 # target="_blank">dictionary</a> mapping each alternative id with the function
15 # \f[
16 # \frac{\partial G}{\partial y_i}(e^{V_1},\ldots,e^{V_J})
17 #\f]
18 # where \f$G\f$ is the MEV generating function. If an alternative \f$i\f$ is not available, then \f$G_i = 0\f$.
19 # @param av A <a
20 # href="http://docs.python.org/py3k/tutorial/datastructures.html#dictionaries"
21 # target="_blank">dictionary</a> mapping each alternative id with its
22 # availability condition.
23 # @param choice Expression producing the id of the chosen alternative.
24 # @return Choice probability of the MEV model, given by
25 # \f[
26 # \frac{e^{V_i + \ln G_i(e^{V_1},\ldots,e^{V_J})}}{\sum_j e^{V_j + \ln G_j(e^{V_1},\ldots,e^{V_J})}}
27 # \f]
28 #
29 # \code
30 # def mev(V,Gi,av,choice) :
31 # H = {}
32 # for i,v in V.items() :
33 # H[i] = Elem({0:0, 1: v + log(Gi[i])},Gi[i]!=0)
34 # P = bioLogit(H,av,choice)
35 # return P
36 # \endcode
37 def mev(V,Gi,av,choice) :
38  H = {}
39  for i,v in V.items() :
40  H[i] = Elem({0:0, 1: v + log(Gi[i])},av[i]!=0)
41  P = bioLogit(H,av,choice)
42  return P
43 
44 ## Log of the choice probability for a MEV model.
45 # @ingroup models
46 # \param V A <a
47 # href="http://docs.python.org/py3k/tutorial/datastructures.html#dictionaries"
48 # target="_blank">dictionary</a> mapping each alternative id with the
49 # expression of the utility function.
50 # @param Gi A <a
51 # href="http://docs.python.org/py3k/tutorial/datastructures.html#dictionaries"
52 # target="_blank">dictionary</a> mapping each alternative id with the function
53 # \f[
54 # \frac{\partial G}{\partial y_i}(e^{V_1},\ldots,e^{V_J})
55 #\f]
56 # where \f$G\f$ is the MEV generating function. If an alternative \f$i\f$ is not available, then \f$G_i = 0\f$.
57 # @param av A <a
58 # href="http://docs.python.org/py3k/tutorial/datastructures.html#dictionaries"
59 # target="_blank">dictionary</a> mapping each alternative id with its
60 # availability condition.
61 # @param choice Expression producing the id of the chosen alternative.
62 # @return Log of the choice probability of the MEV model, given by
63 # \f[
64 # V_i + \ln G_i(e^{V_1},\ldots,e^{V_J}) - \log\left(\sum_j e^{V_j + \ln G_j(e^{V_1},\ldots,e^{V_J})}\right)
65 # \f]
66 #
67 # \code
68 # def logmev(V,Gi,av,choice) :
69 # H = {}
70 # for i,v in V.items() :
71 # H[i] = Elem({0:0, 1: v + log(Gi[i])},Gi[i]!=0)
72 # P = bioLogLogit(H,av,choice)
73 # return P
74 # \endcode
75 def logmev(V,Gi,av,choice) :
76  H = {}
77  for i,v in V.items() :
78  H[i] = Elem({0:0, 1: v + log(Gi[i])},av[i]!=0)
79  logP = bioLogLogit(H,av,choice)
80  return logP
81 
82 
83 
84 ## Choice probability for a MEV model, including the correction for endogenous sampling as proposed by <a href="http://dx.doi.org/10.1016/j.trb.2007.09.003" taret="_blank">Bierlaire, Bolduc and McFadden (2008)</a>.
85 # @ingroup biogeme
86 # @ingroup models
87 # @param V A <a
88 # href="http://docs.python.org/py3k/tutorial/datastructures.html#dictionaries"
89 # target="_blank">dictionary</a> mapping each alternative id with the
90 # expression of the utility function.
91 # @param Gi A <a
92 # href="http://docs.python.org/py3k/tutorial/datastructures.html#dictionaries"
93 # target="_blank">dictionary</a> mapping each alternative id with the function
94 # \f[
95 # \frac{\partial G}{\partial y_i}(e^{V_1},\ldots,e^{V_J})
96 #\f]
97 # where \f$G\f$ is the MEV generating function.
98 # @param av A <a
99 # href="http://docs.python.org/py3k/tutorial/datastructures.html#dictionaries"
100 # target="_blank">dictionary</a> mapping each alternative id with its
101 # availability condition.
102 # @param correction A <a
103 # href="http://docs.python.org/py3k/tutorial/datastructures.html#dictionaries"
104 # target="_blank">dictionary</a> mapping each alternative id with the
105 # expression of the correction. Typically, it is a value, or a
106 # parameter to be estimated.
107 # @param choice Expression producing the id of the chosen alternative.
108 # @return Choice probability of the MEV model, given by
109 # \f[
110 # \frac{e^{V_i + \ln G_i(e^{V_1},\ldots,e^{V_J})}}{\sum_j e^{V_j + \ln G_j(e^{V_1},\ldots,e^{V_J})}}
111 # \f]
112 #
113 # \code
114 # def mev_selectionBias(V,Gi,av,correction,choice) :
115 # H = {}
116 # for i,v in V.items() :
117 # H[i] = v + log(Gi[i]) + correction[i]
118 # P = bioLogit(H,av,choice)
119 # return P
120 # \endcode
121 def mev_selectionBias(V,Gi,av,correction,choice) :
122  H = {}
123  for i,v in V.items() :
124  H[i] = v + log(Gi[i]) + correction[i]
125 
126  P = bioLogit(H,av,choice)
127 
128  return P
129 
130 
131 
132 ## Log of choice probability for a MEV model, including the correction for endogenous sampling as proposed by <a href="http://dx.doi.org/10.1016/j.trb.2007.09.003" taret="_blank">Bierlaire, Bolduc and McFadden (2008)</a>.
133 # @ingroup biogeme
134 # @ingroup models
135 # @param V A <a
136 # href="http://docs.python.org/py3k/tutorial/datastructures.html#dictionaries"
137 # target="_blank">dictionary</a> mapping each alternative id with the
138 # expression of the utility function.
139 # @param Gi A <a
140 # href="http://docs.python.org/py3k/tutorial/datastructures.html#dictionaries"
141 # target="_blank">dictionary</a> mapping each alternative id with the function
142 # \f[
143 # \frac{\partial G}{\partial y_i}(e^{V_1},\ldots,e^{V_J})
144 #\f]
145 # where \f$G\f$ is the MEV generating function.
146 # @param av A <a
147 # href="http://docs.python.org/py3k/tutorial/datastructures.html#dictionaries"
148 # target="_blank">dictionary</a> mapping each alternative id with its
149 # availability condition.
150 # @param correction A <a
151 # href="http://docs.python.org/py3k/tutorial/datastructures.html#dictionaries"
152 # target="_blank">dictionary</a> mapping each alternative id with the
153 # expression of the correction. Typically, it is a value, or a
154 # parameter to be estimated.
155 # @param choice Expression producing the id of the chosen alternative.
156 # @return Log of choice probability of the MEV model, given by
157 # \f[
158 # V_i + \ln G_i(e^{V_1},\ldots,e^{V_J}) - \log\left(\sum_j e^{V_j + \ln G_j(e^{V_1},\ldots,e^{V_J})}\right)
159 # \f]
160 #
161 # \code
162 # def logmev_selectionBias(V,Gi,av,correction,choice) :
163 # H = {}
164 # for i,v in V.items() :
165 # H[i] = v + log(Gi[i]) + correction[i]
166 # P = bioLogLogit(H,av,choice)
167 # return P
168 # \endcode
169 def logmev_selectionBias(V,Gi,av,correction,choice) :
170  H = {}
171  for i,v in V.items() :
172  H[i] = v + log(Gi[i]) + correction[i]
173 
174  P = bioLogLogit(H,av,choice)
175 
176  return P
177 
178 
179 
180 
181 
def logmev(V, Gi, av, choice)
Log of the choice probability for a MEV model.
Definition: mev.py:75
def mev_selectionBias(V, Gi, av, correction, choice)
Choice probability for a MEV model, including the correction for endogenous sampling as proposed by B...
Definition: mev.py:121
def logmev_selectionBias(V, Gi, av, correction, choice)
Log of choice probability for a MEV model, including the correction for endogenous sampling as propos...
Definition: mev.py:169
def mev(V, Gi, av, choice)
Choice probability for a MEV model.
Definition: mev.py:37
Copyright 2016 Michel Bierlaire