Re: Questions on Biogeme

1,048 views
Skip to first unread message

Michel Bierlaire

unread,
Oct 8, 2018, 2:41:14 AM10/8/18
to Wenjian Jia, Michel Bierlaire, noreply-spamdigest via Biogeme
Dear Wenjian,


On 8 Oct 2018, at 02:54, Wenjian Jia <wj...@virginia.edu> wrote:

Dear Prof. Bierlaire,

I am a PhD student at the University of Virginia. Currently I am learning discrete choice models for my research on household vehicle choice behavior. I am new to logit models and Biogeme, I was wondering if you can help me for several questions.

First, I sent email to bio...@googlegroups.com, hoping to post my questions on biogeme google groups. But it says this email address does not exist. Could you please suggest a way to be added to this group?

The address does exist. The URL of the group is https://groups.google.com/forum/#!forum/biogeme


Second,  I downloaded the Windows executable installer and ran several logit models using the Swissmetro dataset. They worked well. However, when I revised the "01logit.py" file for my own dataset, I got the following errors:
Warning: [19:44:36]bioMain.cc:108  pythonbiogeme mnl.py vehiclechoice.dat
[19:44:36]bioParameters.cc:399  Parameter documentation generated: pythonparam.html
[19:44:36]bioModelParser.cc:109  mnl.py exists
Warning: [19:44:36]bioModelParser.cc:142  Error: Failed to load mnl
Warning: [19:44:36]bioMain.cc:169  Error: Failed to load mnl

You probably have made a syntax error. It seems that the Windows version does not report the exact row where the syntax is happening. If you are using Biogeme for research, I strongly advise to use it on Mac or Linux. You can run a Linux environment on Windows using msys2 or cygwin. 

Basically, I only changed the parameters to be estimated and utility functions in your "01logit.py" example (I have four alternatives).  I also converted my .csv file to tab separated .dat file. I was stuck here for two days and could not figure out where is going wrong. It would be great if you could give me some suggestion. (Attached is my .py file)

Lastly, I believe you have mentioned that Windows executable installer is not very convenient to debug since it does not point out the error line in Python script. So I also tried installing from sources. I followed each step from the website, and got errors at the "compile to code" step: make -j 8 install. So I could not find the files such as biogeme, pybiogeme, biosim etc. in /usr/local/bin. 

What was the output of the “./configure”? 
Michel



make  install-exec-hook
make[3]: Entering directory '/home/Wenjian Jia/tools/prepareData'
make[3]: Nothing to be done for 'install-exec-hook'.
make[3]: Leaving directory '/home/Wenjian Jia/tools/prepareData'
make[2]: Leaving directory '/home/Wenjian Jia/tools/prepareData'
make[1]: Leaving directory '/home/Wenjian Jia/tools/prepareData'
Making install in biogeme
make[1]: Entering directory '/home/Wenjian Jia/biogeme'
make[1]: *** No rule to make target '/home/Wenjian', needed by 'biogeme.exe'.  Stop.
make[1]: Leaving directory '/home/Wenjian Jia/biogeme'
make: *** [Makefile:450: install-recursive] Error 1


Best,
Wenjian
--
Wenjian Jia, PhD student
Department of Civil and Environmental Engineering 
University of Virginia


<mnl.py>

Michel Bierlaire

unread,
Oct 9, 2018, 2:44:20 AM10/9/18
to Wenjian Jia, Michel Bierlaire, noreply-spamdigest via Biogeme
I think that I have found the problem…

The name of the directory contains a blank space “Wenjian Jia” and Windows cannot deal with it. 
As you can see, the error says 
*** No rule to make target '/home/Wenjian’,

Install it from a path that does not contain any space. Typically, /tmp. 





On 9 Oct 2018, at 01:53, Wenjian Jia <wj...@virginia.edu> wrote:

Hi  Prof. Bierlaire,

Thanks so much for your quick response!!

When I installed from sources, the ./configure got the outputs:
<image.png>

I believe it is the same as the outputs on the website. But I got stuck at the last step: make -j 8 install. I am confused as I have tried many times but it always report the same error. Thank you for your help!

Best,
Wenjian

Michel Bierlaire

unread,
Apr 6, 2019, 3:32:16 AM4/6/19
to Wenjian Jia, Michel Bierlaire, Biogeme
Pls send your questions to the users’ group <bio...@googlegroups.com>

It seems that there is a problem with your Jupyter notebook. Try to restart it. Or run the script from the terminal. 

On 6 Apr 2019, at 01:14, Wenjian Jia <wj...@virginia.edu> wrote:

Hi Prof. Bierlaire,

I have a question about  "15panelDiscrete.py" in the Swissmetro example. Here, I would like to include socio-demographics into the class membership model. However, I got the error " The kernel appears to have died. It will restart automatically". Is it not possible to estimate a latent class model (include socio-demographics) for panel dataset? 

import pandas as pd
import biogeme.database as db
import biogeme.biogeme as bio
import biogeme.models as models

pandas = pd.read_table("swissmetro.dat")
database = db.Database("swissmetro",pandas)
database.panel("ID")

# The Pandas data structure is available as database.data. Use all the
# Pandas functions to invesigate the database
#print(database.data.describe())

from headers import *

# Removing some observations can be done directly using pandas.
#remove = (((database.data.PURPOSE != 1) & (database.data.PURPOSE != 3)) | (database.data.CHOICE == 0))
#database.data.drop(database.data[remove].index,inplace=True)

# Here we use the "biogeme" way for backward compatibility
exclude = (( PURPOSE != 1 ) * (  PURPOSE   !=  3  ) +  ( CHOICE == 0 )) > 0
database.remove(exclude)



ASC_CAR = Beta('ASC_CAR',0.136,None,None,0)
ASC_TRAIN = Beta('ASC_TRAIN',-1,None,None,0)
ASC_SM = Beta('ASC_SM',0,None,None,1)
B_TIME = Beta('B_TIME',-6.3,None,0,0)
B_COST = Beta('B_COST',-3.29,None,0,0)


SM_COST =  SM_CO   * (  GA   ==  0  ) 
TRAIN_COST =  TRAIN_CO   * (  GA   ==  0  )

TRAIN_TT_SCALED = DefineVariable('TRAIN_TT_SCALED',\
                                 TRAIN_TT / 100.0,database)
TRAIN_COST_SCALED = DefineVariable('TRAIN_COST_SCALED',\
                                   TRAIN_COST / 100,database)
SM_TT_SCALED = DefineVariable('SM_TT_SCALED', SM_TT / 100.0,database)
SM_COST_SCALED = DefineVariable('SM_COST_SCALED', SM_COST / 100,database)
CAR_TT_SCALED = DefineVariable('CAR_TT_SCALED', CAR_TT / 100,database)
CAR_CO_SCALED = DefineVariable('CAR_CO_SCALED', CAR_CO / 100,database)

# For latent class 1, whete the time coefficient is zero
V11 = ASC_TRAIN + B_COST * TRAIN_COST_SCALED  
V12 = ASC_SM + B_COST * SM_COST_SCALED 
V13 = ASC_CAR + B_COST * CAR_CO_SCALED 

V1 = {1: V11,
      2: V12,
      3: V13}

# For latent class 2, whete the time coefficient is estimated
V21 = ASC_TRAIN + B_TIME * TRAIN_TT_SCALED + B_COST * TRAIN_COST_SCALED 
V22 = ASC_SM + B_TIME * SM_TT_SCALED + B_COST * SM_COST_SCALED 
V23 = ASC_CAR + B_TIME * CAR_TT_SCALED + B_COST * CAR_CO_SCALED 

V2 = {1: V21,
      2: V22,
      3: V23}


# Associate the availability conditions with the alternatives

CAR_AV_SP =  DefineVariable('CAR_AV_SP',CAR_AV  * (  SP   !=  0  ),database)
TRAIN_AV_SP =  DefineVariable('TRAIN_AV_SP',TRAIN_AV  * (  SP   !=  0  ),database)

av = {1: TRAIN_AV_SP,
      2: SM_AV,
      3: CAR_AV_SP}


# Class membership model
W_OTHER = Beta('W_OTHER',0.1,None,None,0)
BETA_MALE = Beta('BETA_MALE',0.1,None,None,0)

probClass2 = exp(W_OTHER + BETA_MALE * MALE) / (1 + exp(W_OTHER + BETA_MALE * MALE))
probClass1 = 1 - probClass2

# The choice model is a discrete mixture of logit, with availability conditions
prob1 = PanelLikelihoodTrajectory(models.logit(V1,av,CHOICE))
prob2 = PanelLikelihoodTrajectory(models.logit(V2,av,CHOICE))
probIndiv = probClass1 * prob1 + probClass2 * prob2
logprob = log(probIndiv)

biogeme  = bio.BIOGEME(database,logprob)
biogeme.modelName = "15panelDiscrete"
results = biogeme.estimate()
print("Results=",results)


Best,
Wenjian

On Wed, Oct 10, 2018 at 9:53 PM Wenjian Jia <wj...@virginia.edu> wrote:
Thank you prof. Bierlaire! This is exactly the problem. Now I installed it successfully!

Best,
Wenjian

José Ignacio Hernández

unread,
Aug 6, 2019, 5:57:02 AM8/6/19
to Biogeme
Hello,

I would like to revisit this question. I've used this code to include sociodemographic variables in the class membership function.

However, I receive the following error:

Biogeme exception: Null pointer: row index

The problem is generated at the moment I include the sociodemographic variable to the class membership function. Perhaps PandasBiogeme is not recognizing it.

Is there any solution or trick for this?

Thanks a lot!

Jose Ignacio Hernandez

Michel Bierlaire

unread,
Aug 6, 2019, 12:38:18 PM8/6/19
to joseignaci...@gmail.com, Michel Bierlaire, Biogeme
Jose, 

Can you please send me the files that generate that error? My guess is that the variable is misspelled, as python is case sensitive. But even if it is the case, the error message needs to be improved…

Thanks,

Michel


-- 
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 view this discussion on the web visit https://groups.google.com/d/msgid/biogeme/93dda482-2a33-4163-84c8-e5bfa001ab2e%40googlegroups.com.

José Ignacio Hernández

unread,
Aug 7, 2019, 2:57:00 AM8/7/19
to Biogeme
Hello,

I attach the script file + swissmetro dat file.

The issue is platform-independent (I've tested the file in both my Mac and Windows machine, following your suggestion of the other post 😊). And I've checked on variable mispecifications.

I appreciate your support with my question.

Best regards,

Jose Ignacio Hernandez
To unsubscribe from this group and stop receiving emails from it, send an email to bio...@googlegroups.com.
swissmetro.dat
test_swissmetro.py

Michel Bierlaire

unread,
Aug 7, 2019, 3:19:08 AM8/7/19
to joseignaci...@gmail.com, Michel Bierlaire, Biogeme
José,
The reason is that you are using two times the expression PanelLikelihoodTrajectory. Biogeme does not allow to use more than one. 
If you need more than one, you need to re-organize your data so that all data for each individual appears on the same row.
The next version of biogeme will trigger a more useful error essage. 
Thanks for catching that.
Michel


To unsubscribe from this group and stop receiving emails from it, send an email to biogeme+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/biogeme/6aa2e63f-bc75-4b4e-bec2-0658a5fa7863%40googlegroups.com.
<swissmetro.dat><test_swissmetro.py>

Michel Bierlaire

unread,
Aug 12, 2019, 1:53:10 AM8/12/19
to joseignaci...@gmail.com, Michel Bierlaire, Biogeme
José,
My mistake. The real reason is that it is currently not possible in biogeme to access data outside of the “trajectory” loop. I need to fix this in a future version. 
Michel
Reply all
Reply to author
Forward
0 new messages