Initial log-likelihood is too low

302 views
Skip to first unread message

mdmosab...@gmail.com

unread,
Jul 18, 2018, 1:00:12 PM7/18/18
to Biogeme
Hi all,

I am a novice in PythonBiogeme. Just started to use it a couple of days back.

My problem is, I have run a multinomial logit model with a set of data, however, when I am using the same data set to estimate a nested logit model it stops and shows the error: "There is a numerical problem with the intial log likelihood.......". I don't understand why this is happening because it is the same data set I was using to estimate MNL. Could you please explain why this may happen?

After following some other questions on the same topic I tried to run a simulation and getting "nan" for all probabilities. I also have no idea how to find the solution from simulation results.

Thanks in advance.

Best,
Pasha

This is the code for simulation:

*******************************************************************************************************************************************************************************************************************************************************************************************************************************
from biogeme import *
from headers import *
from nested import *
from loglikelihood import *
from statistics import *

for i in range(1,7):
  
    status = 1 if (i==3) else 0

    vars()['ASC_'+str(i)] = Beta('ASC_'+str(i),0,-1000,1000,status)
B_TIME = Beta('B_TIME',0,-10000,10000,0,'Travel time')
B_COST = Beta('B_COST',0,-10000,10000,0,'Travel cost')
MU = Beta('MU',0,-10000,10000,0)


V1 = ASC_1 + B_TIME * BUS_TT_Minutes + B_COST * BUS_COST_AUD 
V2 = ASC_2 + B_TIME * TRAIN_TT_Minutes + B_COST * TRAIN_COST_AUD 
V3 = ASC_3 + B_TIME * CAR_TT_Minutes + B_COST * CAR_COST_AUD 
V4 = ASC_4 + B_TIME * SHUTTLE_TT_Minutes + B_COST * SHUTTLE_COST_AUD 
V5 = ASC_5 + B_TIME * TAXI_TT_Minutes + B_COST * TAXI_COST_AUD 
V6 = ASC_6 + B_TIME * UBER_TT_Minutes + B_COST * UBER_COST_AUD 

# Associate utility functions with the numbering of alternatives
V= {1: V1,
2: V2,
3: V3,
4:V4,
5:V5,
6:V6}

# Associate the availability conditions with the alternatives

av= {1: SP,
2: SP,
3: SP,
4:SP,
5:SP,
6:SP}

Public = MU , [1,2,3,4,5]
Private = 1.0 , [6]
nests = Public,Private

prob1 = lognested(V,av, nests,1)
prob2 = lognested(V,av, nests,2)
prob3 = lognested(V,av, nests,3)
prob4 = lognested(V,av, nests,4)
prob5 = lognested(V,av, nests,5)
prob6 = lognested(V,av, nests,6)

genelas1 = Derive(prob1,'BUS_TT_Minutes') * BUS_TT_Minutes / prob1
genelas2 = Derive(prob2,'TRAIN_TT_Minutes') * TRAIN_TT_Minutes / prob2
genelas3 = Derive(prob3,'CAR_TT_Minutes') * CAR_TT_Minutes / prob3
genelas4 = Derive(prob4,'SHUTTLE_TT_Minutes') * SHUTTLE_TT_Minutes / prob4
genelas5 = Derive(prob5,'TAXI_TT_Minutes') * TAXI_TT_Minutes / prob5
genelas6 = Derive(prob6,'UBER_TT_Minutes') * UBER_TT_Minutes / prob6

# Second, the elasticity of logit models. See Ben-Akiva and Lerman for
# the formula

#logitelas1 = TRAIN_AV_SP * (1.0 - prob1) * TRAIN_TT_SCALED * B_TIME
#logitelas2 = SM_AV * (1.0 - prob2) * SM_TT_SCALED * B_TIME
#logitelas3 = CAR_AV_SP * (1.0 - prob3) * CAR_TT_SCALED * B_TIME

# Defines an itertor on the data
rowIterator('obsIter') 

simulate = {'Prob. BUS': prob1,
            'Prob. TRAIN': prob2,
            'Prob. CAR':prob3,
'Prob. SHUTTLE': prob4,
            'Prob. TAXI': prob5,
            'Prob. UBER':prob6,
            'generic elas. 1':genelas1,
            'generic elas. 2':genelas2,
            'generic elas. 3':genelas3,
            'generic elas. 4':genelas4,
            'generic elas. 5':genelas5,
            'generic elas. 6':genelas6}


# DEfine the likelihood function for the estimation
BIOGEME_OBJECT.SIMULATE = Enumerate(simulate,'obsIter')

BIOGEME_OBJECT.ESTIMATE = Sum(logprob,'obsIter')

nullLoglikelihood(av,'obsIter')
choiceSet = [1,2,3,4,5,6]
cteLoglikelihood(choiceSet,CHOICE,'obsIter')
availabilityStatistics(av,'obsIter')


#BIOGEME_OBJECT.PARAMETERS['optimizationAlgorithm'] = "BIO"

BIOGEME_OBJECT.PARAMETERS['DumpSensitivityAnalysis'] = "1"
BIOGEME_OBJECT.PARAMETERS['simulateReportForEveryObservation'] = "1"
BIOGEME_OBJECT.PARAMETERS['includeDataWhenSimulate'] = "1"

BIOGEME_OBJECT.FORMULAS['Bus utility'] = V1
BIOGEME_OBJECT.FORMULAS['Train utility'] = V2
BIOGEME_OBJECT.FORMULAS['Car utility'] = V3
BIOGEME_OBJECT.FORMULAS['Shuttle Utility'] = V4
BIOGEME_OBJECT.FORMULAS['Taxi utility'] = V5
BIOGEME_OBJECT.FORMULAS['Uber utility'] = V6

BIOGEME_OBJECT.PARAMETERS['biogemeDisplay'] = "3"

Bierlaire Michel

unread,
Jul 18, 2018, 1:22:43 PM7/18/18
to mdmosab...@gmail.com, Bierlaire Michel, Biogeme
You are mixing code for estimation and simulation. I did not find the definition of logprob. 
Also, MU must be 1.0 or higher, and certainly not negative. Therefore, you should write
MU = Beta('MU’,1,1,10000,0)


--
You received this message because you are subscribed to the Google Groups "Biogeme" group.
To unsubscribe from this group and stop receiving emails from it, send an email to biogeme+u...@googlegroups.com.
To post to this group, send email to bio...@googlegroups.com.
Visit this group at https://groups.google.com/group/biogeme.
For more options, visit https://groups.google.com/d/optout.

mdmosab...@gmail.com

unread,
Jul 20, 2018, 5:09:10 PM7/20/18
to Biogeme
Thanks a lot Michel. Much appreciated.

Pasha
Reply all
Reply to author
Forward
0 new messages