Skip to content

Commit

Permalink
adding parameter for price perception
Browse files Browse the repository at this point in the history
  • Loading branch information
rakow committed Jul 25, 2024
1 parent 315fab3 commit ee25196
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/main/python/choicemodels/estimate_biogeme_plan_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
parser.add_argument("--est-performing", help="Estimate the beta for performing", action="store_true")
parser.add_argument("--est-exp-income", help="Estimate exponent for income", action="store_true")
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("--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 @@ -61,6 +62,7 @@
UTIL_MONEY = Beta('UTIL_MONEY', 1, 0, 2, ESTIMATE if args.est_util_money else FIXED)

BETA_PERFORMING = Beta('BETA_PERFORMING', 6.88, 1, 15, ESTIMATE if args.est_performing else FIXED)
BETA_PRICE_PERCEPTION = Beta('BETA_FIXED_PRICE_PERCEPTION', 1, 0, 1, ESTIMATE if args.est_price_perception else FIXED)

for mode in ds.modes:

Expand Down Expand Up @@ -95,12 +97,14 @@

for i in range(1, ds.k + 1):
# Price is already negative
u = v[f"plan_{i}_price"] * UTIL_MONEY * (1 if args.no_income else (ds.global_income / v["income"]) ** EXP_INCOME)

perceived_price = BETA_PRICE_PERCEPTION * v[f"plan_{i}_fixed_price"] + v[f"plan_{i}_distance_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"]

for mode in ds.modes:
u += ASC[mode] * v[f"plan_{i}_{mode}_usage"]

u += -BETA_PERFORMING * v[f"plan_{i}_{mode}_hours"] * (2 if mode == "ride" else 1)

u += v[f"plan_{i}_car_used"] * B_CAR
Expand All @@ -127,6 +131,8 @@
modelName += "_fixed_ascs"
if args.no_income:
modelName += "_no_income"
if args.est_price_perception:
modelName += "_price_perception"

biogeme.modelName = modelName
biogeme.weight = v["weight"]
Expand Down
5 changes: 4 additions & 1 deletion src/main/python/choicemodels/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def read_plan_choices(input_file: str, sample: float = 1, seed: int = 42) -> Pla
if sample < 1:
df_wide = df_wide.sample(frac=sample, random_state=seed)

print("Modes:", modes)
print("Number of choices:", len(df_wide))

df_wide['custom_id'] = np.arange(len(df_wide)) # Add unique identifier
Expand Down Expand Up @@ -84,6 +83,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}_fixed_price"] = 0
df[f"plan_{i}_distance_price"] = 0

# Costs will also include time costs
df[f"plan_{i}_utils"] = 0
Expand All @@ -97,6 +98,8 @@ def calc_plan_variables(df, k, modes, use_util_money=False, add_util_performing=

df[f"plan_{i}_{mode}_fixed_cost"] = fixed_costs
df[f"plan_{i}_price"] += fixed_costs + distance_costs
df[f"plan_{i}_fixed_price"] += fixed_costs
df[f"plan_{i}_distance_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 ee25196

Please sign in to comment.