Skip to content

Commit

Permalink
workaround for loading existing preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
rakow committed Jul 20, 2024
1 parent 505ef45 commit adf4e00
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -257,6 +257,7 @@ public ScoringParameters getScoringParameters(Person person) {
Object2DoubleMap<String> 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);
Expand Down Expand Up @@ -285,7 +286,7 @@ public ScoringParameters getScoringParameters(Person person) {
});
}

private void loadPreferences(String mode, DistanceGroupModeUtilityParameters.DeltaBuilder delta, Person person, Object2DoubleMap<String> existing) {
private void loadPreferences(String mode, DistanceGroupModeUtilityParameters.DeltaBuilder delta, Person person, Object2DoubleMap<String> existing, ModeUtilityParameters params) {

boolean isRefPerson = person.getAttributes().getAttribute(TripAnalysis.ATTR_REF_ID) != null;

Expand All @@ -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;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/main/python/choicemodels/estimate_biogeme_plan_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down

0 comments on commit adf4e00

Please sign in to comment.