Biogeme: Python Library  4.6a
statistics.py
Go to the documentation of this file.
1 
3 
4 from biogeme import *
5 
6 
13 def nullLoglikelihood(availability,iterator):
14  terms = {}
15  for i,a in availability.items() :
16  terms[i] = ( a!=0 )
17 
18  total = bioMultSum(terms)
19  nl = -Sum(log(total),iterator)
20  BIOGEME_OBJECT.STATISTICS['Null loglikelihood'] = nl
21  return nl
22 
23 
30 def choiceStatistics(choiceSet,choice,iterator):
31  n = {}
32  for i in choiceSet:
33  n[i] = Sum(choice == i,iterator)
34  for i in choiceSet:
35  s = 'Alt. %d chosen' % (i)
36  BIOGEME_OBJECT.STATISTICS[s] = n[i]
37  return n
38 
39 
44 def availabilityStatistics(availability,iterator):
45  n = {}
46  for i,a in availability.items():
47  n[i] = Sum((a != 0),iterator)
48  for i,a in availability.items():
49  s = 'Alt. %d available' % (i)
50  BIOGEME_OBJECT.STATISTICS[s] = n[i]
51  return n
52 
53 
60 def cteLoglikelihood(choiceSet,choice,iterator):
61  n = choiceStatistics(choiceSet,choice,iterator)
62  terms_l = {}
63  terms_tot = {}
64  for i in n:
65  terms_l[i] = n[i] * log(n[i])
66  terms_tot[i] = n[i]
67  total = bioMultSum(terms_tot)
68  l = bioMultSum(terms_l)
69  l -= total * log(total)
70 
71  BIOGEME_OBJECT.STATISTICS['Cte loglikelihood (only for full choice sets)'] = l
72  return l
73 
def choiceStatistics(choiceSet, choice, iterator)
Computes the number of times each alternative is chosen in the data set and ask Biogeme to include it...
Definition: statistics.py:30
def cteLoglikelihood(choiceSet, choice, iterator)
Computes the constant loglikelihood from the sample and ask Biogeme to include it in the output file...
Definition: statistics.py:60
def nullLoglikelihood(availability, iterator)
Computes the null log likelihood from the sample and ask Biogeme to include it in the output file...
Definition: statistics.py:13
def availabilityStatistics(availability, iterator)
Computes the number of times each alternative is declared available in the data set and ask Biogeme t...
Definition: statistics.py:44
Copyright 2017 Michel Bierlaire