Skip to content

Commit

Permalink
update matsim and estimated new baseline model
Browse files Browse the repository at this point in the history
  • Loading branch information
rakow committed Sep 3, 2024
1 parent d8e7806 commit cf7a3db
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 12 deletions.
33 changes: 33 additions & 0 deletions input/v6.3/params/baseline_v2.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<artifactId>matsim-all</artifactId>

<!-- PR-labelled release -->
<version>2025.0-PR3410</version>
<version>2025.0-PR3444</version>

<!-- snapshot == not recommended: rather use PR-labelled release!-->
<!-- <version>2025.0-SNAPSHOT</version>-->
Expand Down
22 changes: 14 additions & 8 deletions src/main/python/choicemodels/estimate_biogeme_plan_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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"]
Expand Down Expand Up @@ -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"]
Expand Down
9 changes: 6 additions & 3 deletions src/main/python/choicemodels/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"]
Expand Down

0 comments on commit cf7a3db

Please sign in to comment.