From adf4e00af26fb6fd677bd3a42705377dad9837e5 Mon Sep 17 00:00:00 2001 From: rakow Date: Sat, 20 Jul 2024 21:10:08 +0200 Subject: [PATCH] workaround for loading existing preferences --- .../scoring/IndividualPersonScoringParameters.java | 12 +++++++----- .../choicemodels/estimate_biogeme_plan_choice.py | 6 +++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/matsim/run/scoring/IndividualPersonScoringParameters.java b/src/main/java/org/matsim/run/scoring/IndividualPersonScoringParameters.java index 4d7714bc..fa4a971e 100644 --- a/src/main/java/org/matsim/run/scoring/IndividualPersonScoringParameters.java +++ b/src/main/java/org/matsim/run/scoring/IndividualPersonScoringParameters.java @@ -248,7 +248,7 @@ public ScoringParameters getScoringParameters(Person person) { DistanceGroup[] groups = distGroups.computeIfAbsent(delta.getPerDistGroup(), k -> calcDistanceGroups(scoring.distGroups, k)); // This may overwrite the preferences with the one stored - loadPreferences(mode.getKey(), delta, person, existing); + loadPreferences(mode.getKey(), delta, person, existing, params); DistanceGroupModeUtilityParameters p = new DistanceGroupModeUtilityParameters(params, delta, groups); builder.setModeParameters(mode.getKey(), p); @@ -257,6 +257,7 @@ public ScoringParameters getScoringParameters(Person person) { Object2DoubleMap values = info.computeIfAbsent(person.getId(), k -> new Object2DoubleOpenHashMap<>()); // Write the overall constants, but only if they are different to the base values + // TODO: store delta and not params if (delta.constant != 0) { values.put(mode.getKey() + "_constant", p.constant); existing.put(mode.getKey() + "_constant", p.constant); @@ -285,7 +286,7 @@ public ScoringParameters getScoringParameters(Person person) { }); } - private void loadPreferences(String mode, DistanceGroupModeUtilityParameters.DeltaBuilder delta, Person person, Object2DoubleMap existing) { + private void loadPreferences(String mode, DistanceGroupModeUtilityParameters.DeltaBuilder delta, Person person, Object2DoubleMap existing, ModeUtilityParameters params) { boolean isRefPerson = person.getAttributes().getAttribute(TripAnalysis.ATTR_REF_ID) != null; @@ -295,19 +296,20 @@ private void loadPreferences(String mode, DistanceGroupModeUtilityParameters.Del } // Else, require that the attributes are present - if (!existing.containsKey(mode + "constant") && scoring.loadPreferences == AdvancedScoringConfigGroup.LoadPreferences.requireAttribute) { + if (!existing.containsKey(mode + "_constant") && scoring.loadPreferences == AdvancedScoringConfigGroup.LoadPreferences.requireAttribute) { throw new IllegalArgumentException("Person " + person.getId() + " does not have attribute " + mode + "_constant"); } if (!existing.containsKey(mode + "_dailyConstant") && scoring.loadPreferences == AdvancedScoringConfigGroup.LoadPreferences.requireAttribute) { throw new IllegalArgumentException("Person " + person.getId() + " does not have attribute " + mode + "_dailyConstant"); } + // TODO: remove params, as only the delta is needed // Use attributes if they are present if (existing.containsKey(mode + "_constant")) - delta.constant = existing.getDouble(mode + "_constant"); + delta.constant = existing.getDouble(mode + "_constant") - params.constant; if (existing.containsKey(mode + "_dailyConstant")) - delta.dailyUtilityConstant = existing.getDouble(mode + "_dailyConstant"); + delta.dailyUtilityConstant = existing.getDouble(mode + "_dailyConstant") - params.dailyUtilityConstant; } /** diff --git a/src/main/python/choicemodels/estimate_biogeme_plan_choice.py b/src/main/python/choicemodels/estimate_biogeme_plan_choice.py index 490e2531..612d87f1 100644 --- a/src/main/python/choicemodels/estimate_biogeme_plan_choice.py +++ b/src/main/python/choicemodels/estimate_biogeme_plan_choice.py @@ -81,13 +81,13 @@ if args.car_util: print("Using fixed utility for car", args.car_util) - B_UTIL = Beta('B_CAR_UTIL', 10 if not args.car_util else args.car_util, - 0, 15, FIXED if args.car_util else ESTIMATE) + 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) if args.no_mxl: B_CAR = B_UTIL else: - B_UTIL_S = Beta('B_CAR_UTIL_SD', 1, 0, 15, ESTIMATE) + B_UTIL_S = Beta('B_CAR_UTIL_SD', 1, 0, None, ESTIMATE) B_CAR = B_UTIL + B_UTIL_S * bioDraws('B_CAR_UTIL_RND', 'TN') U = {}