From 92bf60da0069e4bc9f39cbad1a583d44a2bed16d Mon Sep 17 00:00:00 2001 From: JoeJimFlood Date: Thu, 28 Mar 2024 09:49:03 -0700 Subject: [PATCH 1/6] Made code changes to get categorical vehicle types to work --- activitysim/abm/models/vehicle_type_choice.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/activitysim/abm/models/vehicle_type_choice.py b/activitysim/abm/models/vehicle_type_choice.py index 95d4087aa..de723602f 100644 --- a/activitysim/abm/models/vehicle_type_choice.py +++ b/activitysim/abm/models/vehicle_type_choice.py @@ -347,6 +347,17 @@ def iterate_vehicle_type_choice( model_settings, alts_cats_dict, vehicle_type_data ) + # alts preprocessor + alts_preprocessor_settings = model_settings.alts_preprocessor + if alts_preprocessor_settings: + expressions.assign_columns( + state, + df=alts_wide, + model_settings=alts_preprocessor_settings, + locals_dict=locals_dict, + trace_label=trace_label, + ) + # - preparing choosers for iterating vehicles_merged = vehicles_merged.to_frame() vehicles_merged["already_owned_veh"] = "" @@ -380,6 +391,12 @@ def iterate_vehicle_type_choice( len(choosers), ) + # filter columns of alts and choosers + if len(model_settings.COLS_TO_INCLUDE_IN_CHOOSER_TABLE) > 0: + choosers = choosers[model_settings.COLS_TO_INCLUDE_IN_CHOOSER_TABLE] + if len(model_settings.COLS_TO_INCLUDE_IN_ALTS_TABLE) > 0: + alts_wide = alts_wide[model_settings.COLS_TO_INCLUDE_IN_ALTS_TABLE] + # if there were so many alts that they had to be created programmatically, # by combining categorical variables, then the utility expressions should make # use of interaction terms to accommodate alt-specific coefficients and constants From f1bdd88ecb95794576445e238579e89c717db565 Mon Sep 17 00:00:00 2001 From: JoeJimFlood Date: Thu, 28 Mar 2024 09:52:12 -0700 Subject: [PATCH 2/6] Changed settings call to old format --- activitysim/abm/models/vehicle_type_choice.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/activitysim/abm/models/vehicle_type_choice.py b/activitysim/abm/models/vehicle_type_choice.py index de723602f..faef05e65 100644 --- a/activitysim/abm/models/vehicle_type_choice.py +++ b/activitysim/abm/models/vehicle_type_choice.py @@ -393,9 +393,9 @@ def iterate_vehicle_type_choice( # filter columns of alts and choosers if len(model_settings.COLS_TO_INCLUDE_IN_CHOOSER_TABLE) > 0: - choosers = choosers[model_settings.COLS_TO_INCLUDE_IN_CHOOSER_TABLE] + choosers = choosers[model_settings.get("COLS_TO_INCLUDE_IN_CHOOSER_TABLE")] if len(model_settings.COLS_TO_INCLUDE_IN_ALTS_TABLE) > 0: - alts_wide = alts_wide[model_settings.COLS_TO_INCLUDE_IN_ALTS_TABLE] + alts_wide = alts_wide[model_settings.get("COLS_TO_INCLUDE_IN_ALTS_TABLE")] # if there were so many alts that they had to be created programmatically, # by combining categorical variables, then the utility expressions should make From b0061bc4fec193836d56d6b43c42427fdfc7e4e0 Mon Sep 17 00:00:00 2001 From: JoeJimFlood Date: Thu, 28 Mar 2024 09:55:59 -0700 Subject: [PATCH 3/6] Fixed a couple more model settings calls --- activitysim/abm/models/vehicle_type_choice.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/activitysim/abm/models/vehicle_type_choice.py b/activitysim/abm/models/vehicle_type_choice.py index faef05e65..ae7a679a9 100644 --- a/activitysim/abm/models/vehicle_type_choice.py +++ b/activitysim/abm/models/vehicle_type_choice.py @@ -392,9 +392,9 @@ def iterate_vehicle_type_choice( ) # filter columns of alts and choosers - if len(model_settings.COLS_TO_INCLUDE_IN_CHOOSER_TABLE) > 0: + if len(model_settings.get("COLS_TO_INCLUDE_IN_CHOOSER_TABLE")) > 0: choosers = choosers[model_settings.get("COLS_TO_INCLUDE_IN_CHOOSER_TABLE")] - if len(model_settings.COLS_TO_INCLUDE_IN_ALTS_TABLE) > 0: + if len(model_settings.get("COLS_TO_INCLUDE_IN_ALTS_TABLE")) > 0: alts_wide = alts_wide[model_settings.get("COLS_TO_INCLUDE_IN_ALTS_TABLE")] # if there were so many alts that they had to be created programmatically, From a3f6056c065ffaecb95e8683ff270decd28cfbf7 Mon Sep 17 00:00:00 2001 From: JoeJimFlood Date: Thu, 28 Mar 2024 10:01:49 -0700 Subject: [PATCH 4/6] Removed state variable from function call and added default empty arrays for model settings --- activitysim/abm/models/vehicle_type_choice.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/activitysim/abm/models/vehicle_type_choice.py b/activitysim/abm/models/vehicle_type_choice.py index ae7a679a9..c853f173a 100644 --- a/activitysim/abm/models/vehicle_type_choice.py +++ b/activitysim/abm/models/vehicle_type_choice.py @@ -351,7 +351,6 @@ def iterate_vehicle_type_choice( alts_preprocessor_settings = model_settings.alts_preprocessor if alts_preprocessor_settings: expressions.assign_columns( - state, df=alts_wide, model_settings=alts_preprocessor_settings, locals_dict=locals_dict, @@ -392,10 +391,10 @@ def iterate_vehicle_type_choice( ) # filter columns of alts and choosers - if len(model_settings.get("COLS_TO_INCLUDE_IN_CHOOSER_TABLE")) > 0: - choosers = choosers[model_settings.get("COLS_TO_INCLUDE_IN_CHOOSER_TABLE")] - if len(model_settings.get("COLS_TO_INCLUDE_IN_ALTS_TABLE")) > 0: - alts_wide = alts_wide[model_settings.get("COLS_TO_INCLUDE_IN_ALTS_TABLE")] + if len(model_settings.get("COLS_TO_INCLUDE_IN_CHOOSER_TABLE", [])) > 0: + choosers = choosers[model_settings.get("COLS_TO_INCLUDE_IN_CHOOSER_TABLE", [])] + if len(model_settings.get("COLS_TO_INCLUDE_IN_ALTS_TABLE", [])) > 0: + alts_wide = alts_wide[model_settings.get("COLS_TO_INCLUDE_IN_ALTS_TABLE"l [])] # if there were so many alts that they had to be created programmatically, # by combining categorical variables, then the utility expressions should make From 7449923c2ffc23d06a48ef3958bb7bd69d1de5cc Mon Sep 17 00:00:00 2001 From: JoeJimFlood Date: Thu, 28 Mar 2024 10:57:24 -0700 Subject: [PATCH 5/6] Fixed call of reading in alts preprocessor --- activitysim/abm/models/vehicle_type_choice.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activitysim/abm/models/vehicle_type_choice.py b/activitysim/abm/models/vehicle_type_choice.py index c853f173a..13b6ca5f7 100644 --- a/activitysim/abm/models/vehicle_type_choice.py +++ b/activitysim/abm/models/vehicle_type_choice.py @@ -348,7 +348,7 @@ def iterate_vehicle_type_choice( ) # alts preprocessor - alts_preprocessor_settings = model_settings.alts_preprocessor + alts_preprocessor_settings = model_settings.get("alts_preprocessor", None) if alts_preprocessor_settings: expressions.assign_columns( df=alts_wide, From 74833cbf1ac935520b34da963d2104a16ef222cd Mon Sep 17 00:00:00 2001 From: JoeJimFlood Date: Thu, 28 Mar 2024 16:38:48 -0700 Subject: [PATCH 6/6] Replaced l with , in vehicle_type_choice.py --- activitysim/abm/models/vehicle_type_choice.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activitysim/abm/models/vehicle_type_choice.py b/activitysim/abm/models/vehicle_type_choice.py index 13b6ca5f7..efc4ef19b 100644 --- a/activitysim/abm/models/vehicle_type_choice.py +++ b/activitysim/abm/models/vehicle_type_choice.py @@ -394,7 +394,7 @@ def iterate_vehicle_type_choice( if len(model_settings.get("COLS_TO_INCLUDE_IN_CHOOSER_TABLE", [])) > 0: choosers = choosers[model_settings.get("COLS_TO_INCLUDE_IN_CHOOSER_TABLE", [])] if len(model_settings.get("COLS_TO_INCLUDE_IN_ALTS_TABLE", [])) > 0: - alts_wide = alts_wide[model_settings.get("COLS_TO_INCLUDE_IN_ALTS_TABLE"l [])] + alts_wide = alts_wide[model_settings.get("COLS_TO_INCLUDE_IN_ALTS_TABLE", [])] # if there were so many alts that they had to be created programmatically, # by combining categorical variables, then the utility expressions should make