Skip to content

Commit

Permalink
changes supporting sandag abm3 estimation mode
Browse files Browse the repository at this point in the history
  • Loading branch information
dhensle committed Oct 21, 2024
1 parent 23ba662 commit 0a1bd5c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion activitysim/abm/models/cdap.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def cdap_simulate(
spec = cdap.get_cached_spec(state, hhsize)
estimator.write_table(spec, "spec_%s" % hhsize, append=False)
if add_joint_tour_utility:
joint_spec = cdap.get_cached_joint_spec(hhsize)
joint_spec = cdap.get_cached_joint_spec(state, hhsize)
estimator.write_table(
joint_spec, "joint_spec_%s" % hhsize, append=False
)
Expand Down
11 changes: 6 additions & 5 deletions activitysim/abm/models/disaggregate_accessibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,11 +753,12 @@ def get_disaggregate_logsums(
state.filesystem, model_name + ".yaml"
)
model_settings.SAMPLE_SIZE = disagg_model_settings.DESTINATION_SAMPLE_SIZE
estimator = estimation.manager.begin_estimation(state, trace_label)
if estimator:
location_choice.write_estimation_specs(
state, estimator, model_settings, model_name + ".yaml"
)
# estimator = estimation.manager.begin_estimation(state, trace_label)
# if estimator:
# location_choice.write_estimation_specs(
# state, estimator, model_settings, model_name + ".yaml"
# )
estimator = None

# Append table references in settings with "proto_"
# This avoids having to make duplicate copies of config files for disagg accessibilities
Expand Down
4 changes: 3 additions & 1 deletion activitysim/abm/models/util/tour_destination.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,9 @@ def choose_MAZ_for_TAZ(state: workflow.State, taz_sample, MAZ_size_terms, trace_

# taz_choices index values should be contiguous
assert (
taz_choices[chooser_id_col] == np.repeat(chooser_df.index, taz_sample_size)
(taz_choices[chooser_id_col] == np.repeat(chooser_df.index, taz_sample_size))
# can get one extra if sampling in estimation mode
| (taz_choices[chooser_id_col] == np.repeat(chooser_df.index, taz_sample_size + 1))
).all()

# we need to choose a MAZ for each DEST_TAZ choice
Expand Down
5 changes: 5 additions & 0 deletions activitysim/core/estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,7 @@ def __init__(self):
self.model_estimation_table_types = {}
self.estimating = {}
self.settings = None
self.enabled = False

def initialize_settings(self, state):
# FIXME - can't we just initialize in init and handle no-presence of settings file as not enabled
Expand Down Expand Up @@ -949,6 +950,10 @@ def get_survey_destination_chocies(self, state, choosers, trace_label):
-------
pd.Series : The survey choices for the destination choice model.
"""
if "accessibilities" in trace_label:
# accessibilities models to not have survey values
return None

model = trace_label.split(".")[0]
if model == "school_location":
survey_choices = manager.get_survey_values(
Expand Down
6 changes: 3 additions & 3 deletions activitysim/core/interaction_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,10 +537,10 @@ def _interaction_sample(
on=[choosers.index.name, alt_col_name],
how="left",
)
assert (
missing_choices.prob.isna().sum() == 0
), f"survey choices with no probs: {missing_choices[missing_choices.prob.isna()]}"
if missing_choices.prob.isna().sum() > 0:
logger.warning(f"Survey choices with no probs:\n {missing_choices[missing_choices.prob.isna()]}")
del probs_df
missing_choices['prob'].fillna(0, inplace=True)
# random number is not important, filling with 0
missing_choices["rand"] = 0
# merge survey choices back into choices_df and sort by chooser
Expand Down

0 comments on commit 0a1bd5c

Please sign in to comment.