From cf7a3dbf14891fbe683360059ea5b2029f0de42d Mon Sep 17 00:00:00 2001 From: rakow Date: Tue, 3 Sep 2024 13:10:56 +0200 Subject: [PATCH] update matsim and estimated new baseline model --- input/v6.3/params/baseline_v2.yaml | 33 +++++++++++++++++++ pom.xml | 2 +- .../estimate_biogeme_plan_choice.py | 22 ++++++++----- src/main/python/choicemodels/prepare.py | 9 +++-- 4 files changed, 54 insertions(+), 12 deletions(-) create mode 100644 input/v6.3/params/baseline_v2.yaml diff --git a/input/v6.3/params/baseline_v2.yaml b/input/v6.3/params/baseline_v2.yaml new file mode 100644 index 00000000..18574a55 --- /dev/null +++ b/input/v6.3/params/baseline_v2.yaml @@ -0,0 +1,33 @@ +#Modes: ['walk', 'pt', 'car', 'bike', 'ride'] +#Number of plans: 8259 +#Number of choices for plan: 70 +#Number of choices: 8259 +# Using fixed utility for car 0.0 +# Estimating car asc, instead of daily utility +# Using MXL modes ['car'] +# Results for model plan-choices-subtour_70_exp_income_price_perception_car_price_perception_pt +#Nbr of parameters: 7 +#Sample size: 8259 +#Excluded data: 0 +#Null log likelihood: -24858.3 +#Final log likelihood: -20794.22 +#Likelihood ratio test (null): 8128.154 +#Rho square (null): 0.163 +#Rho bar square (null): 0.163 +#Akaike Information Criterion: 41602.44 +#Bayesian Information Criterion: 41651.57 + +scoring: + scoringParameters: + - performing: 7.547802 + modeParams: + - mode: walk + constant: 0 + - mode: car + constant: 0 + dailyMonetaryConstant: -1.1224785 + - mode: pt + constant: 0 + dailyMonetaryConstant: -0.876558 +advancedScoring: + incomeExponent: 0.144114 \ No newline at end of file diff --git a/pom.xml b/pom.xml index c1ea3f8f..04bc7d26 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ matsim-all - 2025.0-PR3410 + 2025.0-PR3444 diff --git a/src/main/python/choicemodels/estimate_biogeme_plan_choice.py b/src/main/python/choicemodels/estimate_biogeme_plan_choice.py index bdebc5fd..69c446cc 100644 --- a/src/main/python/choicemodels/estimate_biogeme_plan_choice.py +++ b/src/main/python/choicemodels/estimate_biogeme_plan_choice.py @@ -25,7 +25,8 @@ parser.add_argument("--est-exp-income", help="Estimate exponent for income", action="store_true") parser.add_argument("--exp-income", help="Exponent for income", type=float, default=1) parser.add_argument("--est-util-money", help="Estimate utility of money", action="store_true") - parser.add_argument("--est-price-perception", help="Estimate price perception", action="store_true") + parser.add_argument("--est-price-perception-car", help="Estimate price perception", action="store_true") + parser.add_argument("--est-price-perception-pt", help="Estimate price perception", action="store_true") parser.add_argument("--ascs", help="Predefined ASCs", nargs="+", action='append', default=[]) parser.add_argument("--car-util", help="Fixed utility for car", type=float, default=None) parser.add_argument("--no-mxl", help="Disable mixed logit", action="store_true") @@ -64,7 +65,8 @@ UTIL_MONEY = Beta('UTIL_MONEY', 1, 0, 2, ESTIMATE if args.est_util_money else FIXED) BETA_PERFORMING = Beta('BETA_PERFORMING', args.performing, 1, 15, ESTIMATE if args.est_performing else FIXED) - BETA_PRICE_PERCEPTION = Beta('BETA_CAR_PRICE_PERCEPTION', 1, 0, 1, ESTIMATE if args.est_price_perception else FIXED) + BETA_CAR_PRICE_PERCEPTION = Beta('BETA_CAR_PRICE_PERCEPTION', 1, 0, 1, ESTIMATE if args.est_price_perception_car else FIXED) + BETA_PT_PRICE_PERCEPTION = Beta('BETA_PT_PRICE_PERCEPTION', 1, 0, 1, ESTIMATE if args.est_price_perception_pt else FIXED) is_est_car = "car" in args.mxl_modes @@ -84,11 +86,11 @@ SD[mode] = Beta(f"ASC_{mode}_s", 1, None, None, ESTIMATE) ASC[mode] = asc + SD[mode] * bioDraws(f"{mode}_RND", "NORMAL_ANTI") - if args.car_util: + if args.car_util is not None: print("Using fixed utility for car", args.car_util) - B_UTIL = Beta('B_CAR_UTIL', 8 if not args.car_util else args.car_util, - 0, None, FIXED if args.car_util else ESTIMATE) + B_UTIL = Beta('B_CAR_UTIL', 8 if args.car_util is None else args.car_util, + 0, None, ESTIMATE if args.car_util is None else FIXED) if args.no_mxl: B_CAR = B_UTIL @@ -108,7 +110,9 @@ for i in range(1, ds.k + 1): # Price is already negative - perceived_price = BETA_PRICE_PERCEPTION * v[f"plan_{i}_car_price"] + v[f"plan_{i}_non_car_price"] + perceived_price = (BETA_CAR_PRICE_PERCEPTION * v[f"plan_{i}_car_price"] + + BETA_PT_PRICE_PERCEPTION * v[f"plan_{i}_pt_price"] + + v[f"plan_{i}_other_price"]) u = perceived_price * UTIL_MONEY * (1 if args.no_income else (ds.global_income / v["income"]) ** EXP_INCOME) u -= v[f"plan_{i}_pt_n_switches"] @@ -141,8 +145,10 @@ modelName += "_fixed_ascs" if args.no_income: modelName += "_no_income" - if args.est_price_perception: - modelName += "_price_perception" + if args.est_price_perception_car: + modelName += "_price_perception_car" + if args.est_price_perception_pt: + modelName += "_price_perception_pt" biogeme.modelName = modelName biogeme.weight = v["weight"] diff --git a/src/main/python/choicemodels/prepare.py b/src/main/python/choicemodels/prepare.py index 749d4c6c..8bb261b6 100644 --- a/src/main/python/choicemodels/prepare.py +++ b/src/main/python/choicemodels/prepare.py @@ -84,7 +84,8 @@ def calc_plan_variables(df, k, modes, use_util_money=False, add_util_performing= # Price is only monetary costs df[f"plan_{i}_price"] = 0 df[f"plan_{i}_car_price"] = 0 - df[f"plan_{i}_non_car_price"] = 0 + df[f"plan_{i}_pt_price"] = 0 + df[f"plan_{i}_other_price"] = 0 # Costs will also include time costs df[f"plan_{i}_utils"] = 0 @@ -101,10 +102,12 @@ def calc_plan_variables(df, k, modes, use_util_money=False, add_util_performing= if mode == "car": df[f"plan_{i}_car_price"] += fixed_costs + elif mode == "pt": + df[f"plan_{i}_pt_price"] += fixed_costs else: - df[f"plan_{i}_non_car_price"] += fixed_costs + df[f"plan_{i}_other_price"] += fixed_costs - df[f"plan_{i}_non_car_price"] += distance_costs + df[f"plan_{i}_other_price"] += distance_costs df[f"plan_{i}_{mode}_used"] = (df[f"plan_{i}_{mode}_usage"] > 0) * 1 df[f"plan_{i}_tt_hours"] -= df[f"plan_{i}_{mode}_hours"]