Including Travel time matrix and Number of Jobs using CrossVariable for destination choice models

30 views
Skip to first unread message

Rohan Menezes

unread,
Jul 16, 2024, 11:47:28 AM (6 days ago) Jul 16
to Biogeme
Dear Michel and Biogeme Team,

I have the following questions:
1.  How to use CrossVariable Tuple to include travel time from origin to destination for the sample destination alternatives  
2. Does number of Jobs also need to be combined variables? if so,

Do I need to put 2 arguments for the combined variable parameters of the SamplingContext: like this

from biogeme.sampling_of_alternatives import SamplingContext

context =  SamplingContext(
    the_partition = partition_uniform
    sample_sizes = segment_sizes,
    individuals=work_biogeme_data
    choice_column= 'work_pc4'
    alternatives= alternatives,
    id_column=ID_COLUMN,
    biogeme_file_name='Simple Gravity Model MNL intial run'
    utility_function= V_work
    combined_variables= combined_variables_Jobs, combined_variables_TT

) 
I am trying to estimate a destination choice model  at PC4 (4 digit postal code)  level

But I am not able to figure out how to use CrossVariable Tuple to include travel time from origin to destination for the sample destination alternatives  

the information is stored in a dataframe called alternatives which has rows and index as pc4 codes

I followed the restaurant sampling example and created a dataframe called alternatives where the 
the rows are the alternatives (pc4 destinations)
and the columns (column names are pc4 codes too) are the travel times to other pc4 codes from that destination, 

i have also merged the total number of jobs at each destination in this dataframe, since it is advised in the document to include all the attributes of the alternatives

I have tried this

from biogeme.expressions import Beta, Variable, log
from biogeme.sampling_of_alternatives import CrossVariableTuple


combined_variables_TT = [
   CrossVariableTuple(
       'log_TT',
       log(alternatives[str(home_pc4)])
   )]

#KeyError: 'home_pc4'


where home_pc4 is the residential pc4 of the traveler in the observed choice dataframe 
(in the document also known as 'individuals' parameter in SamplingContext function)


I have tried to looking at various sources (examples, previous questions, ChatGPT Biogeme assistant etc.) but couldn't find the solution

I have attached a the pdf excerpt from my jupyter file





travel time matrix in sampled choice set.pdf

Rohan Menezes

unread,
Jul 18, 2024, 4:04:40 AM (5 days ago) Jul 18
to Biogeme
Dear Michel and Biogeme team/community,
I am currently stuck at this
Any inputs or suggestions regarding this would be well appreciated 
Reply all
Reply to author
Forward
0 new messages