Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Biogeme 3.2.14 - piecewise_variables raises when expression is not of type Variable

20 views
Skip to first unread message

Luca Bataillard

unread,
Nov 18, 2024, 3:48:16 AM11/18/24
to Biogeme
Hello everyone,

I was completing this notebook from the Selected topics on Discrete Choice MOOC and ran into an issue with the models.piecewise_variables function crashing. Since the TRAIN_COST_SCALED variable is a composite Expression (runtime type of Division), it is not of type Variable and fails the check on line 75 of models/piecewise.py and raises an exception.

However, this notebook worked and produced correct results in version 3.2.13, and also works if we change the line in 3.2.14's models/piecewise.py from:
if not isinstance(variable, Variable):
to
if not isinstance(variable, Expression):

I can't find any information on this in the docs, is it intentional? If so, how can we solve the problem in the notebook and can we improve the type hints for this function?

Thanks,
Luca

Michel Bierlaire

unread,
Nov 19, 2024, 3:13:49 AM11/19/24
to luca.ba...@gmail.com, Michel Bierlaire, Biogeme
Hi Luca,

I decided to restrict the use to variables in order to avoid meaningless specifications when the expression is general.
The way to go is to define TRAIN_COST_SCALED as a new variable in the database, using pandas, or using define_variable.
https://biogeme.epfl.ch/sphinx/code/biogeme/database.html#biogeme.database.Database.define_variable

It is indeed not properly documented. I'll fix that...

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 visit https://groups.google.com/d/msgid/biogeme/22718338-41a7-44c5-b826-5134256e3716n%40googlegroups.com.

Michel Bierlaire
Transport and Mobility Laboratory
School of Architecture, Civil and Environmental Engineering
EPFL - Ecole Polytechnique Fédérale de Lausanne
http://transp-or.epfl.ch
http://people.epfl.ch/michel.bierlaire

Reply all
Reply to author
Forward
0 new messages