Functions

nested Namespace Reference

Functions

def getMevForNested
 Implements the MEV generating function for the nested logit model.
def nested
 Implements the nested logit model as a MEV model.
def nestedMevMu
 Implements the nested logit model as a MEV model, where mu is also a parameter, if the user wants to test different normalization schemes.

Function Documentation

def nested::getMevForNested (   V,
  availability,
  nests 
)

Implements the MEV generating function for the nested logit model.

Parameters:
VA dictionary mapping each alternative id with the expression of the utility function.
availabilityA dictionary mapping each alternative id with its availability condition.
nestsA tuple containing as many items as nests. Each item is also a tuple containing two items:

  • An expression representing the nest parameter.
  • A list containing the list of identifiers of the alternatives belonging to the nest. Example:
      nesta = MUA , [1,2,3]
      nestb = MUB , [4,5,6]
      nests = nesta, nestb
    
Returns:
A dictionary mapping each alternative id with the function

\[ \frac{\partial G}{\partial y_i}(e^{V_1},\ldots,e^{V_J}) = e^{(\mu_m-1)V_i} \left(\sum_{i=1}^{J_m} e^{\mu_m V_i}\right)^{\frac{1}{\mu_m}-1} \]

where $m$ is the (only) nest containing alternative $i$, and $G$ is the MEV generating function.
 def getMevForNested(V,availability,nests) :
 
     y = {}
     for i,v in V.items() :
         y[i] = exp(v)
     
     Gi = {}
     for m in nests:
         sum = 0.0
         for i in m[1]:
             sum += Elem({0:0,1: y[i] ** m[0]},availability[i]!=0) 
         for i in m[1]:
             Gi[i] = Elem({0:0,1:y[i]**(m[0]-1.0) * sum ** (1.0/m[0] - 1.0)},availability[i]!=0)
     return Gi
def nested::nested (   V,
  availability,
  nests,
  choice 
)

Implements the nested logit model as a MEV model.

Parameters:
VA dictionary mapping each alternative id with the expression of the utility function.
availabilityA dictionary mapping each alternative id with its availability condition.
nestsA tuple containing as many items as nests. Each item is also a tuple containing two items:

  • An expression representing the nest parameter.
  • A list containing the list of identifiers of the alternatives belonging to the nest. Example:
      nesta = MUA , [1,2,3]
      nestb = MUB , [4,5,6]
      nests = nesta, nestb
    
choiceexpression producing the id of the chosen alternative.
Returns:
Choice probability for the nested logit model, based on the derivatives of the MEV generating function produced by the function nested::getMevForNested
 def nested(V,availability,nests,choice) :
     Gi = getMevForNested(V,availability,nests)
     P = mev(V,Gi,availability,choice) 
     return P
def nested::nestedMevMu (   V,
  availability,
  nests,
  choice,
  mu 
)

Implements the nested logit model as a MEV model, where mu is also a parameter, if the user wants to test different normalization schemes.

Parameters:
VA dictionary mapping each alternative id with the expression of the utility function.
availabilityA dictionary mapping each alternative id with its availability condition.
nestsA tuple containing as many items as nests. Each item is also a tuple containing two items:

  • An expression representing the nest parameter.
  • A list containing the list of identifiers of the alternatives belonging to the nest. Example:
      nesta = MUA , [1,2,3]
      nestb = MUB , [4,5,6]
      nests = nesta, nestb
    
choiceexpression producing the id of the chosen alternative.
muexpression producing the value of the top-level scale parameter.
Returns:
The nested logit choice probability based on the following derivatives of the MEV generating function:

\[ \frac{\partial G}{\partial y_i}(e^{V_1},\ldots,e^{V_J}) = \mu e^{(\mu_m-1)V_i} \left(\sum_{i=1}^{J_m} e^{\mu_m V_i}\right)^{\frac{\mu}{\mu_m}-1} \]

where $m$ is the (only) nest containing alternative $i$, and $G$ is the MEV generating function.
 def nestedMevMu(V,availability,nests,choice,mu) :
 
     y = {}
     for i,v in V.items() :
         y[i] = exp(v)
     
     Gi = {}
     for m in nests:
         sum = 0.0
         for i in m[1]:
             sum += Elem({0:0,1: y[i] ** m[0]},availability[i]!=0) 
         for i in m[1]:
             Gi[i] = Elem({0:0,1:mu * y[i]**(m[0]-1.0) * sum ** (mu/m[0] - 1.0)},availability[i]!=0)
     P = mev(V,Gi,availability,choice) 
     return P
 All Classes Namespaces Files Functions Variables