Dear professor Bierlaire,
I hope you are doing well. I tried to run a mixed logit model with panel data to predict ML choice by using a normal distribution with a random coefficient. However, there was NaN issue in the norm of the gradient: "The norm of the gradient at asc_ML=0, asc_ML_s=1, b_time=0, b_toll=0 is nan: g=nan, nan, nan, nan
Numerical problems in calculating the analytical hessian. Finite differences is tried instead."
I tried to use a uniform distribution instead of a normal distribution, but I still got the same issue. Could you please guide me for this issue? I have attached my code as follows:
df_train = pd.read_csv(DDIR+'trainregular.csv')
df_test = pd.read_csv(DDIR+'testregular.csv')
database_train = Database('RUMmix', df_train)
database_test = Database('RUMmix', df_test)
database_train.panel('randid')
# dependent variable
choice = Variable('choice12')
#generic variable
time1 = Variable('time1')
time2 = Variable('time2')
toll1 = Variable('toll1')
toll2 = Variable('toll2')
#Beta 1=ML 2=GPL
#GPL is base choice
asc_ML = Beta('asc_ML', 0, None, None, 0)
b_time = Beta('b_time', 0, None, None, 0)
b_toll = Beta('b_toll', 0, None, None, 0)
np.random.seed(seed=90267)
asc_ML_s = Beta('asc_ML_s', 1, -10, 10, 0)
asc_ML_rnd = asc_ML + asc_ML_s * bioDraws('asc_ML_rnd', 'NORMAL_ANTI')
utility_ML = asc_ML_rnd + b_time*time1 + b_toll*toll1
utility_GPL = b_time*time2 + b_toll*toll2
utilities = {1: utility_ML, 2: utility_GPL}
obsprob = logit(utilities, None, choice)
condprobIndiv = PanelLikelihoodTrajectory(obsprob)
log_choice_probability = log(MonteCarlo(condprobIndiv))
biogeme_train = BIOGEME(database_train, log_choice_probability, number_of_draws=1500, seed=1223)
biogeme_train.modelName = 'RUMmix'
results = biogeme_train.estimate()
Best regards,
Natchaphon Leungbootnak