Skip to content

Commit

Permalink
additional baseline version
Browse files Browse the repository at this point in the history
  • Loading branch information
rakow committed Sep 9, 2024
1 parent 8d8a745 commit 10d3114
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 5 deletions.
39 changes: 39 additions & 0 deletions input/v6.3/params/baseline_v4.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#Modes: ['walk', 'pt', 'car', 'bike', 'ride']
#Number of choices: 27235
#Varying: ['km', 'hours', 'walking_km', 'switches', 'valid']
# Results for model trip_choice_performing_exp_income_util_money_fixed_price_perception
#Nbr of parameters: 8
#Sample size: 27235
#Excluded data: 0
#Null log likelihood: -40155.25
#Final log likelihood: -31522.25
#Likelihood ratio test (null): 17266
#Rho square (null): 0.215
#Rho bar square (null): 0.215
#Akaike Information Criterion: 63060.49
#Bayesian Information Criterion: 63126.19
# Value Rob. Std err Rob. t-test Rob. p-value
# ASC_bike -1.689491 0.032510 -51.968167 0.000000e+00
# ASC_car -1.920529 0.046183 -41.584864 0.000000e+00
# ASC_pt -0.866749 0.029893 -28.995219 0.000000e+00
# ASC_ride -2.401215 0.033845 -70.946824 0.000000e+00
# BETA_PERFORMING 5.677002 0.166151 34.167734 0.000000e+00
# BETA_PRICE_PERCEPTION 0.216186 0.027424 7.883173 3.108624e-15
# EXP_INCOME 0.197429 0.036124 5.465322 4.620660e-08
# UTIL_MONEY 0.534645 0.028387 18.834091 0.000000e+00

scoring:
scoringParameters:
- performing: 5.677002
marginalUtilityOfMoney: 0.534645
modeParams:
- mode: walk
constant: 0
- mode: car
constant: 0
dailyMonetaryConstant: -3.0914598
- mode: pt
constant: 0
dailyMonetaryConstant: -0.648558
advancedScoring:
incomeExponent: 0.197429
14 changes: 9 additions & 5 deletions src/main/python/choicemodels/estimate_biogeme_trip_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
# -*- coding: utf-8 -*-

import argparse
from collections import defaultdict

import biogeme.biogeme as bio
import biogeme.database as db
import biogeme.models as models
from biogeme.expressions import Beta, bioDraws, PanelLikelihoodTrajectory, log, MonteCarlo

from prepare import read_trip_choices
from prepare import read_trip_choices, daily_costs, km_costs

ESTIMATE = 0
FIXED = 1
Expand All @@ -22,6 +20,9 @@
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-fixed-price-perception", help="Estimate price perception of daily costs",
action="store_true")

parser.add_argument("--no-income", help="Don't consider the income", action="store_true")

args = parser.parse_args()
Expand All @@ -34,8 +35,6 @@
database = db.Database("data/choices", df)
v = database.variables

km_costs = defaultdict(lambda: 0.0, car=-0.149, ride=-0.149)

ASC = {}
for mode in ds.modes:
# Base asc
Expand All @@ -51,11 +50,14 @@
EXP_INCOME = Beta('EXP_INCOME', 1, 0, 1.5, ESTIMATE if args.est_exp_income else FIXED)
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_PRICE_PERCEPTION', 0, 0, 1,
ESTIMATE if args.est_fixed_price_perception else FIXED)

for i, mode in enumerate(ds.modes, 1):
u = ASC[mode] - BETA_PERFORMING * v[f"{mode}_hours"] * (2 if mode == "ride" else 1)

price = km_costs[mode] * v[f"{mode}_km"]
price += daily_costs[mode] * v["dist_weight"] * BETA_PRICE_PERCEPTION
u += price * UTIL_MONEY * (1 if args.no_income else (ds.global_income / v["income"]) ** EXP_INCOME)

if mode == "pt":
Expand Down Expand Up @@ -83,6 +85,8 @@
modelName += "_exp_income"
if args.est_util_money:
modelName += "_util_money"
if args.est_fixed_price_perception:
modelName += "_fixed_price_perception"

biogeme.modelName = modelName
biogeme.weight = v["weight"]
Expand Down
6 changes: 6 additions & 0 deletions src/main/python/choicemodels/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,10 @@ def read_trip_choices(input_file: str) -> TripChoice:

print("Varying:", varying)

dists = df.groupby("person").agg(dist=("beelineDist", "sum"))

# Trips weighted by distance during the whole day
dist_weight = df.beelineDist / dists.loc[df.person].dist.to_numpy()
df["dist_weight"] = dist_weight

return TripChoice(df, modes, varying, read_global_income(input_file))

0 comments on commit 10d3114

Please sign in to comment.