Skip to content

Commit

Permalink
updating estimation checks to allow for non-zero household_sample_size
Browse files Browse the repository at this point in the history
  • Loading branch information
dhensle committed Dec 5, 2024
1 parent 1fb41a8 commit 87b414f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
5 changes: 4 additions & 1 deletion activitysim/abm/models/joint_tour_frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,16 +192,19 @@ def joint_tour_frequency(
print(f"len(joint_tours) {len(joint_tours)}")

different = False
# need to check households as well because the full survey sample may not be used
# (e.g. if we set household_sample_size in settings.yaml)
survey_tours_not_in_tours = survey_tours[
~survey_tours.index.isin(joint_tours.index)
& survey_tours.household_id.isin(households.index)
]
if len(survey_tours_not_in_tours) > 0:
print(f"survey_tours_not_in_tours\n{survey_tours_not_in_tours}")
different = True
tours_not_in_survey_tours = joint_tours[
~joint_tours.index.isin(survey_tours.index)
]
if len(survey_tours_not_in_tours) > 0:
if len(tours_not_in_survey_tours) > 0:
print(f"tours_not_in_survey_tours\n{tours_not_in_survey_tours}")
different = True
assert not different
4 changes: 3 additions & 1 deletion activitysim/abm/models/non_mandatory_tour_frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,10 @@ def non_mandatory_tour_frequency(
if estimator:
# make sure they created the right tours
survey_tours = estimation.manager.get_survey_table("tours").sort_index()
# need the household_id check below incase household_sample_size != 0
non_mandatory_survey_tours = survey_tours[
survey_tours.tour_category == "non_mandatory"
(survey_tours.tour_category == "non_mandatory")
& survey_tours.household_id.isin(persons.household_id)
]
# need to remove the pure-escort tours from the survey tours table for comparison below
if state.is_table("school_escort_tours"):
Expand Down
6 changes: 5 additions & 1 deletion activitysim/abm/models/stop_frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,11 @@ def stop_frequency(

survey_trips = estimation.manager.get_survey_table(table_name="trips")
different = False
survey_trips_not_in_trips = survey_trips[~survey_trips.index.isin(trips.index)]
# need the check below on household_id incase household_sample_size != 0
survey_trips_not_in_trips = survey_trips[
~survey_trips.index.isin(trips.index)
& survey_trips.household_id.isin(trips.household_id)
]
if len(survey_trips_not_in_trips) > 0:
print(f"survey_trips_not_in_trips\n{survey_trips_not_in_trips}")
different = True
Expand Down
2 changes: 2 additions & 0 deletions activitysim/abm/models/trip_destination.py
Original file line number Diff line number Diff line change
Expand Up @@ -1362,6 +1362,8 @@ def run_trip_destination(

# expect all the same trips
survey_trips = estimator.get_survey_table("trips").sort_index()
# need to check household_id incase household_sample_size != 0
survey_trips = survey_trips[survey_trips.household_id.isin(trips.household_id)]
assert survey_trips.index.equals(trips.index)

first = survey_trips.trip_num == 1
Expand Down
2 changes: 1 addition & 1 deletion activitysim/core/estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ def initialize_settings(self, state):
if state.settings.multiprocess:
pipeline_hh_ids = state.get_table("households").index
if table_name == "households":
df = df[df.index.isin(pipeline_hh_ids)]
df = df.reindex(pipeline_hh_ids)
assert pipeline_hh_ids.equals(
df.index
), "household_ids not equal between survey and pipeline"
Expand Down

0 comments on commit 87b414f

Please sign in to comment.