diff --git a/.github/workflows/core_tests.yml b/.github/workflows/core_tests.yml index 222527c46..1cc35874f 100644 --- a/.github/workflows/core_tests.yml +++ b/.github/workflows/core_tests.yml @@ -141,6 +141,7 @@ jobs: matrix: region: - prototype_mtc + - prototype_arc - placeholder_psrc - prototype_marin - prototype_mtc_extended diff --git a/activitysim/abm/models/joint_tour_participation.py b/activitysim/abm/models/joint_tour_participation.py index 68a8a3b9b..e6dbee8b6 100644 --- a/activitysim/abm/models/joint_tour_participation.py +++ b/activitysim/abm/models/joint_tour_participation.py @@ -429,9 +429,8 @@ def joint_tour_participation( if i not in model_settings.compute_settings.protect_columns: model_settings.compute_settings.protect_columns.append(i) - # TODO EET: this is related to the difference in nested logit and logit choice as per comment in - # make_choices_utility_based. As soon as alt_order_array is removed from arguments to - # make_choices_explicit_error_term_nl this guard can be removed + # This is related to the difference in nested logit and logit choice. As soon as alt_order_array + # is removed from arguments to make_choices_explicit_error_term_nl this guard can be removed. if state.settings.use_explicit_error_terms: assert ( nest_spec is None diff --git a/activitysim/abm/models/location_choice.py b/activitysim/abm/models/location_choice.py index 7f032a8ae..dfe110878 100644 --- a/activitysim/abm/models/location_choice.py +++ b/activitysim/abm/models/location_choice.py @@ -15,10 +15,11 @@ TourLocationComponentSettings, TourModeComponentSettings, ) +from activitysim.core.exceptions import DuplicateWorkflowTableError from activitysim.core.interaction_sample import interaction_sample from activitysim.core.interaction_sample_simulate import interaction_sample_simulate +from activitysim.core.logit import AltsContext from activitysim.core.util import reindex -from activitysim.core.exceptions import DuplicateWorkflowTableError """ The school/workplace location model predicts the zones in which various people will @@ -603,6 +604,7 @@ def run_location_simulate( chunk_tag, trace_label, skip_choice=False, + alts_context: AltsContext | None = None, ): """ run location model on location_sample annotated with mode_choice logsum @@ -712,6 +714,7 @@ def run_location_simulate( compute_settings=model_settings.compute_settings.subcomponent_settings( "simulate" ), + alts_context=alts_context, ) if not want_logsums: @@ -737,6 +740,7 @@ def run_location_choice( chunk_tag, trace_label, skip_choice=False, + alts_context: AltsContext | None = None, ): """ Run the three-part location choice algorithm to generate a location choice for each chooser @@ -756,6 +760,8 @@ def run_location_choice( model_settings : dict chunk_size : int trace_label : str + skip_choice : bool + alts_context : AltsContext or None Returns ------- @@ -788,6 +794,9 @@ def run_location_choice( if choosers.shape[0] == 0: logger.info(f"{trace_label} skipping segment {segment_name}: no choosers") continue + # dest_size_terms contains 0-attraction zones so using this directly here, important for stable error terms + # when a zone goes from 0 base -> nonzero project + alts_context = AltsContext.from_series(dest_size_terms.index) # - location_sample location_sample_df = run_location_sample( @@ -841,6 +850,7 @@ def run_location_choice( trace_label, "simulate.%s" % segment_name ), skip_choice=skip_choice, + alts_context=alts_context, ) if estimator: @@ -1031,6 +1041,17 @@ def iterate_location_choice( ] persons_merged_df_ = persons_merged_df_.sort_index() + # reset rng offsets to identical state on each iteration. This ensures that the same set of random numbers is + # used on each iteration. Note this has to happen AFTER updating shadow prices because the simulation method + # draws random numbers. + # Only applying when using EET for now because this will need changes to integration + # tests, but it's probably a good idea for MC simulation as well. + if state.settings.use_explicit_error_terms and iteration > 1: + logger.debug( + f"{trace_label} resetting random number generator offsets for iteration {iteration}" + ) + state.get_rn_generator().reset_offsets_for_step(state.current_model_name) + choices_df_, save_sample_df = run_location_choice( state, persons_merged_df_, diff --git a/activitysim/abm/models/parking_location_choice.py b/activitysim/abm/models/parking_location_choice.py index 32f3aabee..b07ec5b87 100644 --- a/activitysim/abm/models/parking_location_choice.py +++ b/activitysim/abm/models/parking_location_choice.py @@ -21,6 +21,7 @@ from activitysim.core.configuration.base import PreprocessorSettings from activitysim.core.configuration.logit import LogitComponentSettings from activitysim.core.interaction_sample_simulate import interaction_sample_simulate +from activitysim.core.logit import AltsContext from activitysim.core.tracing import print_elapsed_time from activitysim.core.util import assign_in_place, drop_unused_columns from activitysim.core.exceptions import DuplicateWorkflowTableError @@ -112,6 +113,7 @@ def parking_destination_simulate( chunk_size, trace_hh_id, trace_label, + alts_context: AltsContext | None = None, ): """ Chose destination from destination_sample (with od_logsum and dp_logsum columns added) @@ -150,6 +152,7 @@ def parking_destination_simulate( trace_label=trace_label, trace_choice_name="parking_loc", explicit_chunk_size=model_settings.explicit_chunk, + alts_context=alts_context, ) # drop any failed zero_prob destinations @@ -211,6 +214,9 @@ def choose_parking_location( ) destination_sample.index = np.repeat(trips.index.values, len(alternatives)) destination_sample.index.name = trips.index.name + # use full land_use index to ensure AltsContext spans full range of potential zones + land_use = state.get_dataframe("land_use") + alts_context = AltsContext.from_series(land_use.index) destinations = parking_destination_simulate( state, @@ -223,6 +229,7 @@ def choose_parking_location( chunk_size=chunk_size, trace_hh_id=trace_hh_id, trace_label=trace_label, + alts_context=alts_context, ) if want_sample_table: diff --git a/activitysim/abm/models/trip_destination.py b/activitysim/abm/models/trip_destination.py index 853cfc35e..df1694148 100644 --- a/activitysim/abm/models/trip_destination.py +++ b/activitysim/abm/models/trip_destination.py @@ -32,6 +32,7 @@ from activitysim.core.configuration.logit import LocationComponentSettings from activitysim.core.interaction_sample import interaction_sample from activitysim.core.interaction_sample_simulate import interaction_sample_simulate +from activitysim.core.logit import AltsContext from activitysim.core.skim_dictionary import DataFrameMatrix from activitysim.core.tracing import print_elapsed_time from activitysim.core.util import assign_in_place, reindex @@ -950,6 +951,7 @@ def trip_destination_simulate( skim_hotel, estimator, trace_label, + alts_context: AltsContext | None = None, ): """ Chose destination from destination_sample (with od_logsum and dp_logsum columns added) @@ -1036,6 +1038,7 @@ def trip_destination_simulate( trace_choice_name="trip_dest", estimator=estimator, explicit_chunk_size=model_settings.explicit_chunk, + alts_context=alts_context, ) if not want_logsums: @@ -1080,6 +1083,10 @@ def choose_trip_destination( t0 = print_elapsed_time() + # use full index (including zero-size zones) to ensure stable random results + # fetch alts_context early so we don't worry about mutating alternatives first + alts_context = AltsContext.from_series(alternatives.index) + # - trip_destination_sample destination_sample = trip_destination_sample( state, @@ -1126,7 +1133,6 @@ def choose_trip_destination( destination_sample["dp_logsum"] = 0.0 t0 = print_elapsed_time("%s.compute_logsums" % trace_label, t0, debug=True) - destinations = trip_destination_simulate( state, primary_purpose=primary_purpose, @@ -1138,6 +1144,7 @@ def choose_trip_destination( skim_hotel=skim_hotel, estimator=estimator, trace_label=trace_label, + alts_context=alts_context, ) dropped_trips = ~trips.index.isin(destinations.index) diff --git a/activitysim/abm/models/trip_scheduling_choice.py b/activitysim/abm/models/trip_scheduling_choice.py index 81d908ef1..a5e17eb41 100644 --- a/activitysim/abm/models/trip_scheduling_choice.py +++ b/activitysim/abm/models/trip_scheduling_choice.py @@ -279,6 +279,15 @@ def run_trip_scheduling_choice( ) in chunk.adaptive_chunked_choosers(state, indirect_tours, trace_label): # Sort the choosers and get the schedule alternatives choosers = choosers.sort_index() + # FIXME-EET: For explicit error term choices, we need a stable alternative ID. Currently, we use + # SCHEDULE_ID, which justs enumerates all schedule alternatives, of which there are choosers times + # alternative, in the order they are processed, which depends on if there stops on outward/return leg. + # We might want to change SCHEDULE_ID to a fixed pattern of all possible combinations of + # (outbound, main, inbound) duration for the maximum possible tour duration (max time window). For + # 30min intervals, this leads to 1225 alternatives and therefore reasonable memory-wise for random numbers. + # It looks like all that would need to change for this is the generation of the schedule alternatives and + # the lookup of choices as elements in schedule after simulation because choosers are indexed by tour_id. + schedules = generate_schedule_alternatives(choosers).sort_index() # preprocessing alternatives diff --git a/activitysim/abm/models/util/test/test_cdap.py b/activitysim/abm/models/util/test/test_cdap.py index 20dc6b241..20d68f2dd 100644 --- a/activitysim/abm/models/util/test/test_cdap.py +++ b/activitysim/abm/models/util/test/test_cdap.py @@ -5,6 +5,7 @@ import os.path +import numpy as np import pandas as pd import pandas.testing as pdt import pytest @@ -176,3 +177,84 @@ def test_build_cdap_spec_hhsize2(people, model_settings): ).astype("float") pdt.assert_frame_equal(utils, expected, check_names=False) + + +def test_cdap_explicit_error_terms_parity(people, model_settings): + person_type_map = model_settings.get("PERSON_TYPE_MAP", {}) + + # Increase population to get more stable distribution for parity check + # We'll just duplicate the existing people a few times + large_people = pd.concat([people] * 500).reset_index(drop=True) + large_people.index.name = "person_id" + + assert people.household_id.is_monotonic_increasing + large_people["hhid_diff"] = large_people.household_id.diff().fillna(0).astype(int) + large_people.loc[large_people["hhid_diff"] < 0, "hhid_diff"] = 1 + large_people["household_id"] = large_people.hhid_diff.cumsum() + + assert large_people["household_id"].is_monotonic_increasing + + # Run without explicit error terms + state_no_eet = workflow.State.make_default(__file__) + cdap_indiv_spec = state_no_eet.filesystem.read_model_spec( + file_name="cdap_indiv_and_hhsize1.csv" + ) + interaction_coefficients = pd.read_csv( + state_no_eet.filesystem.get_config_file_path( + "cdap_interaction_coefficients.csv" + ), + comment="#", + ) + interaction_coefficients = cdap.preprocess_interaction_coefficients( + interaction_coefficients + ) + cdap_fixed_relative_proportions = pd.DataFrame( + {"activity": ["M", "N", "H"], "coefficient": [0.33, 0.33, 0.34]} + ) + + state_no_eet.settings.use_explicit_error_terms = False + state_no_eet.rng().set_base_seed(42) + state_no_eet.rng().begin_step("test_no_eet") + state_no_eet.rng().add_channel("person_id", large_people) + state_no_eet.rng().add_channel( + "household_id", + large_people.drop_duplicates("household_id").set_index("household_id"), + ) + + choices_no_eet = cdap.run_cdap( + state_no_eet, + large_people, + person_type_map, + cdap_indiv_spec, + interaction_coefficients, + cdap_fixed_relative_proportions, + locals_d=None, + ) + + # Run with explicit error terms + state_eet = workflow.State.make_default(__file__) + state_eet.settings.use_explicit_error_terms = True + state_eet.rng().set_base_seed(42) + state_eet.rng().begin_step("test_eet") + state_eet.rng().add_channel("person_id", large_people) + state_eet.rng().add_channel( + "household_id", + large_people.drop_duplicates("household_id").set_index("household_id"), + ) + + choices_eet = cdap.run_cdap( + state_eet, + large_people, + person_type_map, + cdap_indiv_spec, + interaction_coefficients, + cdap_fixed_relative_proportions, + locals_d=None, + ) + + # Compare distributions + dist_no_eet = choices_no_eet.value_counts(normalize=True).sort_index() + dist_eet = choices_eet.value_counts(normalize=True).sort_index() + + # Check that they are reasonably close + pdt.assert_series_equal(dist_no_eet, dist_eet, atol=0.05, check_names=False) diff --git a/activitysim/abm/models/util/tour_destination.py b/activitysim/abm/models/util/tour_destination.py index d99803bd7..0531a2cae 100644 --- a/activitysim/abm/models/util/tour_destination.py +++ b/activitysim/abm/models/util/tour_destination.py @@ -21,6 +21,7 @@ from activitysim.core.configuration.logit import TourLocationComponentSettings from activitysim.core.interaction_sample import interaction_sample from activitysim.core.interaction_sample_simulate import interaction_sample_simulate +from activitysim.core.logit import AltsContext from activitysim.core.util import reindex logger = logging.getLogger(__name__) @@ -873,6 +874,10 @@ def run_destination_simulate( state.tracing.dump_df(DUMP, choosers, trace_label, "choosers") log_alt_losers = state.settings.log_alt_losers + # use full land_use index to ensure AltsContext spans full range of potential destinations + # (maintains stable random number generation even if zones flip zero/non-zero size) + land_use = state.get_dataframe("land_use") + alts_context = AltsContext.from_series(land_use.index) choices = interaction_sample_simulate( state, @@ -891,6 +896,7 @@ def run_destination_simulate( estimator=estimator, skip_choice=skip_choice, compute_settings=model_settings.compute_settings, + alts_context=alts_context, ) if not want_logsums: diff --git a/activitysim/abm/models/util/vectorize_tour_scheduling.py b/activitysim/abm/models/util/vectorize_tour_scheduling.py index c199ef40d..0666bf2c8 100644 --- a/activitysim/abm/models/util/vectorize_tour_scheduling.py +++ b/activitysim/abm/models/util/vectorize_tour_scheduling.py @@ -17,6 +17,7 @@ from activitysim.core.configuration.base import ComputeSettings, PreprocessorSettings from activitysim.core.configuration.logit import LogitComponentSettings from activitysim.core.interaction_sample_simulate import interaction_sample_simulate +from activitysim.core.logit import AltsContext from activitysim.core.util import reindex logger = logging.getLogger(__name__) @@ -849,6 +850,9 @@ def _schedule_tours( estimator.write_interaction_sample_alternatives(alt_tdd) log_alt_losers = state.settings.log_alt_losers + # use full TDD alternatives index to ensure AltsContext spans full range of potential slots + tdd_alts = state.get_injectable("tdd_alts") + alts_context = AltsContext.from_series(tdd_alts.index) choices = interaction_sample_simulate( state, @@ -862,6 +866,7 @@ def _schedule_tours( trace_label=tour_trace_label, estimator=estimator, compute_settings=compute_settings, + alts_context=alts_context, ) chunk_sizer.log_df(tour_trace_label, "choices", choices) diff --git a/activitysim/abm/test/test_misc/configs_test_misc/joint_tour_participation.csv b/activitysim/abm/test/test_misc/configs_test_misc/joint_tour_participation.csv new file mode 100644 index 000000000..d81df1ab1 --- /dev/null +++ b/activitysim/abm/test/test_misc/configs_test_misc/joint_tour_participation.csv @@ -0,0 +1,2 @@ +Description,Expression,participate,not_participate +Adult participation,adult,0.5,-0.5 diff --git a/activitysim/abm/test/test_misc/configs_test_misc/joint_tour_participation.yaml b/activitysim/abm/test/test_misc/configs_test_misc/joint_tour_participation.yaml new file mode 100644 index 000000000..8db2410c0 --- /dev/null +++ b/activitysim/abm/test/test_misc/configs_test_misc/joint_tour_participation.yaml @@ -0,0 +1,5 @@ +SPEC: joint_tour_participation.csv +COEFFICIENTS: joint_tour_participation_coefficients.csv +participation_choice: participate +max_participation_choice_iterations: 100 +FORCE_PARTICIPATION: True diff --git a/activitysim/abm/test/test_misc/configs_test_misc/joint_tour_participation_coefficients.csv b/activitysim/abm/test/test_misc/configs_test_misc/joint_tour_participation_coefficients.csv new file mode 100644 index 000000000..237d51917 --- /dev/null +++ b/activitysim/abm/test/test_misc/configs_test_misc/joint_tour_participation_coefficients.csv @@ -0,0 +1,2 @@ +expression,coefficient +adult,1.0 diff --git a/activitysim/abm/test/test_misc/test_joint_tour_participation.py b/activitysim/abm/test/test_misc/test_joint_tour_participation.py new file mode 100644 index 000000000..5aa15c6e8 --- /dev/null +++ b/activitysim/abm/test/test_misc/test_joint_tour_participation.py @@ -0,0 +1,158 @@ +import numpy as np +import pandas as pd +import pandas.testing as pdt +import pytest + +from activitysim.abm.models import joint_tour_participation +from activitysim.core import logit, workflow + +from .test_trip_departure_choice import add_canonical_dirs + + +@pytest.fixture +def candidates(): + # Create synthetic candidates for Joint Tour Participation + # JTP chooses whether each candidate participates in a joint tour. + # We include varied compositions and preschoolers to exercise the + # get_tour_satisfaction logic properly. + num_tours_per_comp = 500 + compositions = ["MIXED", "ADULTS", "CHILDREN"] + num_candidates_per_tour = 4 + + total_tours = num_tours_per_comp * len(compositions) + num_candidates = total_tours * num_candidates_per_tour + + # Ensure reproducibility + rng = np.random.default_rng(42) + + tour_ids = np.repeat(np.arange(total_tours), num_candidates_per_tour) + comp_values = np.repeat(compositions, num_tours_per_comp * num_candidates_per_tour) + + df = pd.DataFrame( + { + "tour_id": tour_ids, + "household_id": tour_ids, # simplified for mock + "person_id": np.arange(num_candidates), + "composition": comp_values, + }, + index=pd.Index(np.arange(num_candidates), name="participant_id"), + ) + + # Assign adult and preschooler status based on composition + # MIXED: at least one adult and one child + # ADULTS: all adults + # CHILDREN: all children + df["adult"] = False + df["person_is_preschool"] = False + + for i, comp in enumerate(compositions): + mask = df.composition == comp + indices = df[mask].index + + if comp == "ADULTS": + df.loc[indices, "adult"] = True + elif comp == "CHILDREN": + df.loc[indices, "adult"] = False + # Some children are preschoolers + df.loc[ + rng.choice(indices, len(indices) // 4, replace=False), + "person_is_preschool", + ] = True + elif comp == "MIXED": + # For each tour, make the first person an adult, rest children + tour_start_indices = indices[::num_candidates_per_tour] + df.loc[tour_start_indices, "adult"] = True + # Other members are children, some might be preschoolers + other_indices = indices[~indices.isin(tour_start_indices)] + df.loc[ + rng.choice(other_indices, len(other_indices) // 3, replace=False), + "person_is_preschool", + ] = True + + return df + + +@pytest.fixture +def model_spec(): + # Simple spec with two alternatives: 'participate' and 'not_participate' + return pd.DataFrame( + {"participate": [0.8, -0.2], "not_participate": [0.0, 0.0]}, + index=pd.Index(["adult", "person_is_preschool"], name="Expression"), + ) + + +def test_jtp_explicit_error_terms_parity(candidates, model_spec): + """ + Test that joint tour participation results are statistically similar + between MNL and Explicit Error Terms (EET) using realistic candidate scenarios. + """ + # Create random utilities for the candidates that vary by attribute + rng = np.random.default_rng(42) + + # Base utility + some noise + base_util = (candidates.adult * 0.5) - (candidates.person_is_preschool * 1.0) + utils = pd.DataFrame( + { + "participate": base_util + rng.standard_normal(len(candidates)), + "not_participate": 0, + }, + index=candidates.index, + ) + + # Run without EET (MNL) + state_no_eet = add_canonical_dirs("configs_test_misc").default_settings() + state_no_eet.settings.use_explicit_error_terms = False + state_no_eet.rng().set_base_seed(42) + state_no_eet.rng().begin_step("test_no_eet") + state_no_eet.rng().add_channel("participant_id", candidates) + + # MNL path expects probabilities + probs_no_eet = logit.utils_to_probs(state_no_eet, utils, trace_label="test_no_eet") + choices_no_eet, _ = joint_tour_participation.participants_chooser( + state_no_eet, + probs_no_eet, + candidates, + model_spec, + trace_label="test_no_eet", + ) + + # Run with EET + state_eet = add_canonical_dirs("configs_test_misc").default_settings() + state_eet.settings.use_explicit_error_terms = True + state_eet.rng().set_base_seed(42) + state_eet.rng().begin_step("test_eet") + state_eet.rng().add_channel("participant_id", candidates) + + # EET path expects raw utilities + choices_eet, _ = joint_tour_participation.participants_chooser( + state_eet, + utils.copy(), + candidates, + model_spec, + trace_label="test_eet", + ) + + # Compare distributions of number of participants per tour + # Choice 0 is 'participate' + no_eet_participation_counts = ( + (choices_no_eet == 0).groupby(candidates.tour_id).sum() + ) + eet_participation_counts = (choices_eet == 0).groupby(candidates.tour_id).sum() + + dist_no_eet = no_eet_participation_counts.value_counts(normalize=True).sort_index() + dist_eet = eet_participation_counts.value_counts(normalize=True).sort_index() + + # Check that the distribution of participation counts is close + pdt.assert_series_equal(dist_no_eet, dist_eet, atol=0.05, check_names=False) + + # Also check average participation by composition for deeper parity check + comp_parity_no_eet = no_eet_participation_counts.groupby( + candidates.groupby("tour_id")["composition"].first() + ).mean() + comp_parity_eet = eet_participation_counts.groupby( + candidates.groupby("tour_id")["composition"].first() + ).mean() + + pdt.assert_series_equal( + comp_parity_no_eet, comp_parity_eet, atol=0.1, check_names=False + ) diff --git a/activitysim/abm/test/test_misc/test_trip_departure_choice.py b/activitysim/abm/test/test_misc/test_trip_departure_choice.py index 94d47f57a..d6645ce94 100644 --- a/activitysim/abm/test/test_misc/test_trip_departure_choice.py +++ b/activitysim/abm/test/test_misc/test_trip_departure_choice.py @@ -187,3 +187,60 @@ def test_apply_stage_two_model(model_spec, trips): pd.testing.assert_index_equal(departures.index, trips.index) departures = pd.concat([trips, departures], axis=1) + + +def test_tdc_explicit_error_terms_parity(model_spec, trips): + setup_dirs() + model_settings = tdc.TripDepartureChoiceSettings() + + # Increase population for statistical convergence + large_trips = pd.concat([trips] * 500).reset_index(drop=True) + large_trips.index.name = "trip_id" + # Ensure tour_ids are distinct for the expanded set + large_trips["tour_id"] = ( + large_trips.groupby("tour_id").cumcount() * 1000 + large_trips["tour_id"] + ) + + # Trip departure choice uses tour_leg_id as the random channel index + tour_legs = tdc.get_tour_legs(large_trips) + + # Run without explicit error terms + state_no_eet = add_canonical_dirs("configs_test_misc").default_settings() + state_no_eet.settings.use_explicit_error_terms = False + state_no_eet.rng().set_base_seed(42) + state_no_eet.rng().begin_step("test_no_eet") + state_no_eet.rng().add_channel("trip_id", large_trips) + state_no_eet.rng().add_channel("tour_leg_id", tour_legs) + + departures_no_eet = tdc.apply_stage_two_model( + state_no_eet, + model_spec, + large_trips, + 0, + "TEST Trip Departure No EET", + model_settings=model_settings, + ) + + # Run with explicit error terms + state_eet = add_canonical_dirs("configs_test_misc").default_settings() + state_eet.settings.use_explicit_error_terms = True + state_eet.rng().set_base_seed(42) + state_eet.rng().begin_step("test_eet") + state_eet.rng().add_channel("trip_id", large_trips) + state_eet.rng().add_channel("tour_leg_id", tour_legs) + + departures_eet = tdc.apply_stage_two_model( + state_eet, + model_spec, + large_trips, + 0, + "TEST Trip Departure EET", + model_settings=model_settings, + ) + + # Compare distributions + dist_no_eet = departures_no_eet.value_counts(normalize=True).sort_index() + dist_eet = departures_eet.value_counts(normalize=True).sort_index() + + # Check that they are reasonably close (within 5% for this sample size) + pd.testing.assert_series_equal(dist_no_eet, dist_eet, atol=0.05, check_names=False) diff --git a/activitysim/abm/test/test_misc/test_trip_scheduling_choice.py b/activitysim/abm/test/test_misc/test_trip_scheduling_choice.py index 6823a5b12..8401c785c 100644 --- a/activitysim/abm/test/test_misc/test_trip_scheduling_choice.py +++ b/activitysim/abm/test/test_misc/test_trip_scheduling_choice.py @@ -1,9 +1,11 @@ -import numpy as np -import pandas as pd -import pytest +from __future__ import annotations + import os from pathlib import Path +import numpy as np +import pandas as pd +import pytest from activitysim.abm.models import trip_scheduling_choice as tsc from activitysim.abm.tables.skims import skim_dict diff --git a/activitysim/core/interaction_sample.py b/activitysim/core/interaction_sample.py index 93834c690..4241fd693 100644 --- a/activitysim/core/interaction_sample.py +++ b/activitysim/core/interaction_sample.py @@ -58,33 +58,21 @@ def make_sample_choices_utility_based( utilities = utilities[~zero_probs] choosers = choosers[~zero_probs] - utils_array = utilities.to_numpy() - chunk_sizer.log_df(trace_label, "utils_array", utils_array) - chosen_destinations = [] - - rands = state.get_rn_generator().gumbel_for_df(utilities, n=alternative_count) + rands = state.get_rn_generator().gumbel_for_df( + utilities, n=alternative_count * sample_size + ) chunk_sizer.log_df(trace_label, "rands", rands) - # TODO-EET [janzill Jun2022]: using for-loop to keep memory usage low, an array of dimension - # (len(choosers), alternative_count, sample_size) can get very large. Probably better to - # use chunking for this. - for i in range(sample_size): - # created this once for memory logging - if i > 0: - rands = state.get_rn_generator().gumbel_for_df( - utilities, n=alternative_count - ) - chosen_destinations.append(np.argmax(utils_array + rands, axis=1)) - chosen_destinations = np.concatenate(chosen_destinations, axis=0) + rands = rands.reshape((utilities.shape[0], alternative_count, sample_size)) + rands += utilities.to_numpy()[:, :, np.newaxis] + # choose maximum along all alternatives (axis 1) for all choosers and samples + chosen_destinations = np.argmax(rands, axis=1).reshape(-1) chunk_sizer.log_df(trace_label, "chosen_destinations", chosen_destinations) - - del utils_array - chunk_sizer.log_df(trace_label, "utils_array", None) del rands chunk_sizer.log_df(trace_label, "rands", None) - chooser_idx = np.tile(np.arange(utilities.shape[0]), sample_size) + chooser_idx = np.repeat(np.arange(utilities.shape[0]), sample_size) chunk_sizer.log_df(trace_label, "chooser_idx", chooser_idx) probs = logit.utils_to_probs( diff --git a/activitysim/core/interaction_sample_simulate.py b/activitysim/core/interaction_sample_simulate.py index e73f64f4f..9c07fd6ef 100644 --- a/activitysim/core/interaction_sample_simulate.py +++ b/activitysim/core/interaction_sample_simulate.py @@ -9,8 +9,9 @@ from activitysim.core import chunk, interaction_simulate, logit, tracing, util, workflow from activitysim.core.configuration.base import ComputeSettings -from activitysim.core.simulate import set_skim_wrapper_targets from activitysim.core.exceptions import SegmentedSpecificationError +from activitysim.core.logit import AltsContext +from activitysim.core.simulate import set_skim_wrapper_targets logger = logging.getLogger(__name__) @@ -34,6 +35,7 @@ def _interaction_sample_simulate( *, chunk_sizer: chunk.ChunkSizer, compute_settings: ComputeSettings | None = None, + alts_context: AltsContext | None = None, ): """ Run a MNL simulation in the situation in which alternatives must @@ -220,9 +222,6 @@ def _interaction_sample_simulate( ) chunk_sizer.log_df(trace_label, "interaction_utilities", interaction_utilities) - del interaction_df - chunk_sizer.log_df(trace_label, "interaction_df", None) - if have_trace_targets: state.tracing.trace_interaction_eval_results( trace_eval_results, @@ -264,19 +263,29 @@ def _interaction_sample_simulate( # insert the zero-prob utilities to pad each alternative set to same size padded_utilities = np.insert(interaction_utilities.utility.values, inserts, -999) + padded_alt_nrs = np.insert(interaction_df[choice_column], inserts, -999) chunk_sizer.log_df(trace_label, "padded_utilities", padded_utilities) - del inserts - del interaction_utilities - chunk_sizer.log_df(trace_label, "interaction_utilities", None) + del interaction_df + chunk_sizer.log_df(trace_label, "interaction_df", None) + + del inserts # reshape to array with one row per chooser, one column per alternative padded_utilities = padded_utilities.reshape(-1, max_sample_count) + padded_alt_nrs = padded_alt_nrs.reshape(-1, max_sample_count) # convert to a dataframe with one row per chooser and one column per alternative utilities_df = pd.DataFrame(padded_utilities, index=choosers.index) chunk_sizer.log_df(trace_label, "utilities_df", utilities_df) + # alt_nrs_df has columns for each alt in the choice set, with values indicating which alt_id + # they correspond to (as opposed to the 0-n index implied by the column number). + if alts_context is not None: + alt_nrs_df = pd.DataFrame(padded_alt_nrs, index=choosers.index) + else: + alt_nrs_df = None # if we don't provide the number of dense alternatives, assume that we'll use the old approach + del padded_utilities chunk_sizer.log_df(trace_label, "padded_utilities", None) @@ -320,7 +329,12 @@ def _interaction_sample_simulate( # positions is series with the chosen alternative represented as a column index in utilities_df # which is an integer between zero and num alternatives in the alternative sample positions, rands = logit.make_choices_utility_based( - state, utilities_df, trace_label=trace_label, trace_choosers=choosers + state, + utilities_df, + trace_label=trace_label, + trace_choosers=choosers, + alts_context=alts_context, + alt_nrs_df=alt_nrs_df, ) del utilities_df @@ -451,6 +465,7 @@ def interaction_sample_simulate( skip_choice=False, explicit_chunk_size=0, *, + alts_context: AltsContext | None = None, compute_settings: ComputeSettings | None = None, ): """ @@ -496,6 +511,12 @@ def interaction_sample_simulate( explicit_chunk_size : float, optional If > 0, specifies the chunk size to use when chunking the interaction simulation. If < 1, specifies the fraction of the total number of choosers. + alts_context: AltsContext, optional + Representation of the full alternatives domain (min and max alternative id) + in the absence of sampling. + This is used with EET simulation to ensure consistent random numbers across the whole alternative set + ( as the sampled set may change between base and project). When not provided, + EET with integer-coded choice ids will raise an error. Returns ------- @@ -517,6 +538,18 @@ def interaction_sample_simulate( trace_label = tracing.extend_trace_label(trace_label, "interaction_sample_simulate") chunk_tag = chunk_tag or trace_label + if state.settings.use_explicit_error_terms: + choice_ids_are_int = pd.api.types.is_integer_dtype(alternatives[choice_column]) + if alts_context is None and choice_ids_are_int: + raise ValueError( + "alts_context is required for interaction_sample_simulate when " + "use_explicit_error_terms is True and choice_column is integer-coded" + ) + if alts_context is not None and not choice_ids_are_int: + raise ValueError( + "alts_context can only be used with integer-coded choice_column values" + ) + result_list = [] for ( i, @@ -551,6 +584,7 @@ def interaction_sample_simulate( skip_choice, chunk_sizer=chunk_sizer, compute_settings=compute_settings, + alts_context=alts_context, ) result_list.append(choices) diff --git a/activitysim/core/logit.py b/activitysim/core/logit.py index 0030168bb..2670d044f 100644 --- a/activitysim/core/logit.py +++ b/activitysim/core/logit.py @@ -4,6 +4,8 @@ import logging import warnings +from dataclasses import dataclass +from typing import Union import numpy as np import pandas as pd @@ -22,7 +24,6 @@ EXP_UTIL_MIN = 1e-300 EXP_UTIL_MAX = np.inf -# TODO-EET: Figure out what type we want UTIL_MIN to be, currently np.float64 UTIL_MIN = np.log(EXP_UTIL_MIN, dtype=np.float64) UTIL_UNAVAILABLE = 1000.0 * (UTIL_MIN - 1.0) @@ -31,6 +32,38 @@ PROB_MAX = 1.0 +@dataclass +class AltsContext: + """Representation of the alternatives without carrying around that full array.""" + + min_alt_id: int + max_alt_id: int + + def __post_init__(self): + # e.g. for zero based zones max_alt_id = n_alts - 1 + # but for 1 based zones, we don't need to add extra padding + self.n_rands_to_sample = max(self.max_alt_id, self.n_alts_to_cover_max_id) + + @classmethod + def from_series(cls, ser: Union[pd.Series, pd.Index]) -> "AltsContext": + min_alt_id = ser.min() + max_alt_id = ser.max() + return cls(min_alt_id, max_alt_id) + + @classmethod + def from_num_alts(cls, num_alts: int, zero_based: bool = True) -> "AltsContext": + if zero_based: + offset = -1 + else: + offset = 0 + return cls(min_alt_id=1 + offset, max_alt_id=num_alts + offset) + + @property + def n_alts_to_cover_max_id(self) -> int: + """If zones were non-consecutive, this could be a big over-estimate.""" + return self.max_alt_id + 1 + + def report_bad_choices( state: workflow.State, bad_row_map, @@ -344,12 +377,60 @@ def utils_to_probs( return probs -# TODO-EET: add doc string, tracing -def add_ev1_random(state: workflow.State, df: pd.DataFrame): +def add_ev1_random( + state: workflow.State, + df: pd.DataFrame, + alt_info: AltsContext | None = None, + alt_nrs_df: pd.DataFrame | None = None, +): + """ + Add iid EV1 (Gumbel) random error terms to utilities for EET choice. + + Parameters + ---------- + state : workflow.State + df : pandas.DataFrame + Utilities indexed by chooser and with alternatives as columns. + + Returns + ------- + pandas.DataFrame + Utilities with EV1 errors added. + """ nest_utils_for_choice = df.copy() - nest_utils_for_choice += state.get_rn_generator().gumbel_for_df( - nest_utils_for_choice, n=nest_utils_for_choice.shape[1] + assert (alt_info is None) == ( + alt_nrs_df is None + ), "alt_info and alt_nrs_df must both be provided or omitted together" + + if alt_info is None: + # Fallback behaviour for models where alt_info/alt_nrs_df are not provided (e.g. non-integer alts) + rands = state.get_rn_generator().gumbel_for_df( + nest_utils_for_choice, n=nest_utils_for_choice.shape[1] + ) + nest_utils_for_choice += rands + return nest_utils_for_choice + + idx_array = alt_nrs_df.values + mask = idx_array == -999 + safe_idx = np.where(mask, 1, idx_array) # replace -999 with a temp value inbounds + # generate random number for all alts - this is wasteful, but ensures that the same zone + # gets the same random number if the sampled choice set changes between base and project + # (alternatively, one could seed a channel for (persons x zones) and use the zone seed to ensure consistency. + # Trade off is needing to seed (persons x zones) rows and multiindex channels to + # avoid extra random numbers generated here. Quick benchmark suggests seeding per row is likely slower + rands_dense = state.get_rn_generator().gumbel_for_df( + nest_utils_for_choice, n=alt_info.n_alts_to_cover_max_id ) + # generate n=alt_info.max_alt_id+1 rather than n_alts so that indexing works + # (this is drawing a random number for a redundant zeroth zone in 1 based zoning systems) + # TODO deal with non 0->n-1 indexed land use more efficiently? ideally do where alt_nrs_df is constructed, + # not on the fly here. Potentially via state.get_injectable('network_los').get_skim_dict('taz').zone_ids + rands = np.take_along_axis(rands_dense, safe_idx, axis=1) + rands[ + mask + ] = 0 # zero out the masked zones so they don't have the util adjustment of alt 0 + + nest_utils_for_choice += rands return nest_utils_for_choice @@ -367,12 +448,44 @@ def choose_from_tree( raise ValueError("This should never happen - no alternative found") -# TODO-EET: add doc string, tracing def make_choices_explicit_error_term_nl( - state, nested_utilities, alt_order_array, nest_spec, trace_label + state, + nested_utilities, + alt_order_array, + nest_spec, + trace_label, + trace_choosers=None, + allow_bad_utils=False, + alts_context: AltsContext | None = None, + alt_nrs_df: pd.DataFrame | None = None, ): - """walk down the nesting tree and make choice at each level, which is the root of the next level choice.""" - nest_utils_for_choice = add_ev1_random(state, nested_utilities) + """ + Walk down the nesting tree and make a choice at each level using EET. + + Parameters + ---------- + state : workflow.State + nested_utilities : pandas.DataFrame + Utilities for nest and leaf nodes. + alt_order_array : numpy.ndarray + Leaf alternatives in the original ordering. + nest_spec : dict or LogitNestSpec + Nest specification for the choice model. + trace_label : str + Trace label for logging and tracing. + + Returns + ------- + pandas.Series + Choice indices aligned to `alt_order_array`. + """ + if trace_label: + state.tracing.trace_df( + nested_utilities, tracing.extend_trace_label(trace_label, "nested_utils") + ) + nest_utils_for_choice = add_ev1_random( + state, nested_utilities, alts_context, alt_nrs_df + ) all_alternatives = set(nest.name for nest in each_nest(nest_spec, type="leaf")) logit_nest_groups = group_nest_names_by_level(nest_spec) @@ -389,8 +502,17 @@ def make_choices_explicit_error_term_nl( ), axis=1, ) - # TODO-EET: reporting like for zero probs - assert not choices.isnull().any(), f"No choice for {trace_label}" + missing_choices = choices.isnull() # TODO: should we check for infs here too? + if missing_choices.any() and not allow_bad_utils: + report_bad_choices( + state, + missing_choices, + nested_utilities, + trace_label=tracing.extend_trace_label(trace_label, "bad_utils"), + msg="no alternative selected", + # raise_error=False, + trace_choosers=trace_choosers, + ) choices = pd.Series(choices, index=nest_utils_for_choice.index) # In order for choice indexing to be consistent with MNL and cumsum MC choices, we need to index in the order @@ -400,25 +522,90 @@ def make_choices_explicit_error_term_nl( return choices -# TODO-EET: add doc string, tracing -def make_choices_explicit_error_term_mnl(state, utilities, trace_label): - utilities_incl_unobs = add_ev1_random(state, utilities) +def make_choices_explicit_error_term_mnl( + state, + utilities, + trace_label, + trace_choosers=None, + allow_bad_utils=False, + alts_context: AltsContext | None = None, + alt_nrs_df: pd.DataFrame | None = None, +) -> pd.Series: + """ + Make EET choices for a multinomial logit model by adding EV1 errors. + + Parameters + ---------- + state : workflow.State + utilities : pandas.DataFrame + Utilities with choosers as rows and alternatives as columns. + trace_label : str + Trace label for logging and tracing. + + Returns + ------- + pandas.Series + Choice indices aligned to the utilities columns order. + """ + if trace_label: + state.tracing.trace_df( + utilities, tracing.extend_trace_label(trace_label, "utilities") + ) + utilities_incl_unobs = add_ev1_random(state, utilities, alts_context, alt_nrs_df) + if trace_label: + state.tracing.trace_df( + utilities_incl_unobs, + tracing.extend_trace_label(trace_label, "utilities_eet"), + ) choices = np.argmax(utilities_incl_unobs.to_numpy(), axis=1) - # TODO-EET: reporting like for zero probs - assert not np.isnan(choices).any(), f"No choice for {trace_label}" + missing_choices = np.isnan(choices) # TODO: should we check for infs here too? + if missing_choices.any() and not allow_bad_utils: + report_bad_choices( + state, + missing_choices, + utilities, + trace_label=tracing.extend_trace_label(trace_label, "bad_utils"), + msg="no alternative selected", + # raise_error=False, + trace_choosers=trace_choosers, + ) choices = pd.Series(choices, index=utilities_incl_unobs.index) return choices def make_choices_explicit_error_term( - state, utilities, alt_order_array, nest_spec=None, trace_label=None -): + state, + utilities, + alt_order_array, + nest_spec=None, + trace_label=None, + trace_choosers=None, + allow_bad_utils=False, + alts_context: AltsContext | None = None, + alt_nrs_df: pd.DataFrame | None = None, +) -> pd.Series: trace_label = tracing.extend_trace_label(trace_label, "make_choices_eet") if nest_spec is None: - choices = make_choices_explicit_error_term_mnl(state, utilities, trace_label) + choices = make_choices_explicit_error_term_mnl( + state, + utilities, + trace_label, + trace_choosers, + allow_bad_utils, + alts_context, + alt_nrs_df, + ) else: choices = make_choices_explicit_error_term_nl( - state, utilities, alt_order_array, nest_spec, trace_label + state, + utilities, + alt_order_array, + nest_spec, + trace_label, + trace_choosers, + allow_bad_utils, + alts_context, + alt_nrs_df, ) return choices @@ -430,17 +617,28 @@ def make_choices_utility_based( nest_spec=None, trace_label: str = None, trace_choosers=None, - allow_bad_probs=False, + allow_bad_utils=False, + alts_context: AltsContext | None = None, + alt_nrs_df: pd.DataFrame | None = None, ) -> tuple[pd.Series, pd.Series]: trace_label = tracing.extend_trace_label(trace_label, "make_choices_utility_based") - # TODO-EET: index of choices for nested utilities is different than unnested - this needs to be consistent for - # turning indexes into alternative names to keep code changes to minimum for now + # For nested models, choices are mapped to `name_mapping` ordering inside the + # EET helper. For MNL, choices already follow the utilities column order. choices = make_choices_explicit_error_term( - state, utilities, name_mapping, nest_spec, trace_label + state, + utilities, + name_mapping, + nest_spec, + trace_label, + trace_choosers=trace_choosers, + allow_bad_utils=allow_bad_utils, + alts_context=alts_context, + alt_nrs_df=alt_nrs_df, ) - # TODO-EET: rands - log all zeros for now + # EET does not expose per-row random draws; return zeros for compatibility. rands = pd.Series(np.zeros_like(utilities.index.values), index=utilities.index) + return choices, rands diff --git a/activitysim/core/random.py b/activitysim/core/random.py index 5541fcd41..ea42b2411 100644 --- a/activitysim/core/random.py +++ b/activitysim/core/random.py @@ -9,8 +9,8 @@ import numpy as np import pandas as pd -from activitysim.core.util import reindex from activitysim.core.exceptions import DuplicateLoadableObjectError, TableIndexError +from activitysim.core.util import reindex from .tracing import print_elapsed_time @@ -445,7 +445,38 @@ def get_channel_for_df(self, df): raise TableIndexError("No channel with index name '%s'" % df.index.name) return self.channels[channel_name] - # step handling + def reset_offsets_for_step(self, step_name): + """ + Reset offsets for all channels for a step + + Parameters + ---------- + step_name : str + pipeline step name for this step + """ + + assert self.step_name == step_name + + for c in self.channels: + self.channels[c].row_states["offset"] = 0 + + def reset_offsets_for_df(self, df): + """ + Reset offsets for all choosers in df if the channel for a step + + Parameters + ---------- + step_name : str + pipeline step name for this step + df : pandas.DataFrame + df with index name and values corresponding to a registered channel + """ + channel = self.get_channel_for_df(df) + channel.row_states.loc[df.index, "offset"] = 0 + logger.info( + f"RNG: resetting random number generator offsets for channel '{channel.channel_name}' for {len(df)} rows" + + f" with index name '{df.index.name}'. Total lenght df: {len(channel.row_states)}" + ) def begin_step(self, step_name): """ diff --git a/activitysim/core/simulate.py b/activitysim/core/simulate.py index ed0b34452..6268c5174 100644 --- a/activitysim/core/simulate.py +++ b/activitysim/core/simulate.py @@ -9,7 +9,7 @@ from collections.abc import Callable from datetime import timedelta from pathlib import Path -from typing import Any +from typing import TYPE_CHECKING, Any import numpy as np import pandas as pd @@ -32,7 +32,9 @@ LogitNestSpec, TemplatedLogitComponentSettings, ) -from activitysim.core.estimation import Estimator + +if TYPE_CHECKING: + from activitysim.core.estimation import Estimator from activitysim.core.fast_eval import fast_eval from activitysim.core.simulate_consts import ( ALT_LOSER_UTIL, @@ -1503,7 +1505,6 @@ def eval_nl( ) if state.settings.use_explicit_error_terms: - # TODO-EET: Nested utility zero choice probability raw_utilities = logit.validate_utils( state, raw_utilities, allow_zero_probs=True, trace_label=trace_label ) @@ -1512,21 +1513,13 @@ def eval_nl( nested_utilities = compute_nested_utilities(raw_utilities, nest_spec) chunk_sizer.log_df(trace_label, "nested_utilities", nested_utilities) - # TODO-EET: use nested_utiltites directly to compute logsums? if want_logsums: - # logsum of nest root - # exponentiated utilities of leaves and nests - nested_exp_utilities = compute_nested_exp_utilities( - raw_utilities, nest_spec - ) - chunk_sizer.log_df( - trace_label, "nested_exp_utilities", nested_exp_utilities - ) - logsums = pd.Series(np.log(nested_exp_utilities.root), index=choosers.index) + logsums = pd.Series(nested_utilities.root, index=choosers.index) chunk_sizer.log_df(trace_label, "logsums", logsums) - # TODO-EET: index of choices for nested utilities is different than unnested - this needs to be consistent for - # turning indexes into alternative names to keep code changes to minimum for now + # Index of choices for nested utilities is different than unnested - this needs to be consistent for + # turning indexes into alternative names to keep code changes to minimum for now. Might want to look + # into changing this in the future when revisiting nested logit EET code. name_mapping = raw_utilities.columns.values del raw_utilities diff --git a/activitysim/core/test/test_interaction_sample.py b/activitysim/core/test/test_interaction_sample.py new file mode 100644 index 000000000..623b1622f --- /dev/null +++ b/activitysim/core/test/test_interaction_sample.py @@ -0,0 +1,297 @@ +# ActivitySim +# See full license in LICENSE.txt. + +import numpy as np +import pandas as pd +import pytest + +from activitysim.core import interaction_sample, workflow + + +@pytest.fixture +def state() -> workflow.State: + state = workflow.State().default_settings() + state.settings.check_for_variability = False + return state + + +def test_interaction_sample_parity(state): + # Run interaction_sample with and without explicit error terms and check that results are similar. + + num_choosers = 100_000 + num_alts = 100 + sample_size = 10 + + # Create random choosers and alternatives + rng = np.random.default_rng(42) + choosers = pd.DataFrame( + {"chooser_attr": rng.random(num_choosers)}, + index=pd.Index(range(num_choosers), name="person_id"), + ) + + alternatives = pd.DataFrame( + {"alt_attr": rng.random(num_alts)}, + index=pd.Index(range(num_alts), name="alt_id"), + ) + + # Simple spec: utility = chooser_attr * alt_attr + spec = pd.DataFrame( + {"coefficient": [1.0]}, + index=pd.Index(["chooser_attr * alt_attr"], name="Expression"), + ) + + # Run _without_ explicit error terms + state.settings.use_explicit_error_terms = False + state.rng().set_base_seed(42) + state.rng().add_channel("person_id", choosers) + state.rng().begin_step("test_step_mnl") + + choices_mnl = interaction_sample.interaction_sample( + state, + choosers, + alternatives, + spec, + sample_size=sample_size, + alt_col_name="alt_id", + ) + + # Run _with_ explicit error terms + state.init_state() # reset the state to rerun with same seed + state.settings.use_explicit_error_terms = True + state.rng().set_base_seed(42) + state.rng().add_channel("person_id", choosers) + state.rng().begin_step("test_step_explicit") + + choices_explicit = interaction_sample.interaction_sample( + state, + choosers, + alternatives, + spec, + sample_size=sample_size, + alt_col_name="alt_id", + ) + + assert "alt_id" in choices_mnl.columns + assert "alt_id" in choices_explicit.columns + assert not choices_mnl["alt_id"].isna().any() + assert not choices_explicit["alt_id"].isna().any() + assert choices_mnl["alt_id"].isin(alternatives.index).all() + assert choices_explicit["alt_id"].isin(alternatives.index).all() + + # In interaction_sample, choices_explicit and choices_mnl are DataFrames with sampled alternatives. + # The statistics of chosen alternatives should be similar. + mnl_counts = choices_mnl["alt_id"].value_counts(normalize=True).sort_index() + explicit_counts = ( + choices_explicit["alt_id"].value_counts(normalize=True).sort_index() + ) + + # Check top choices overlap significantly or shares are close + all_alts = set(mnl_counts.index) | set(explicit_counts.index) + for alt in all_alts: + share_mnl = mnl_counts.get(alt, 0) + share_explicit = explicit_counts.get(alt, 0) + diff = abs(share_mnl - share_explicit) + assert diff < 0.01, ( + f"Large discrepancy at alt {alt}: " + f"mnl={share_mnl:.4f}, explicit={share_explicit:.4f}, diff={diff:.4f}" + ) + + +def test_interaction_sample_eet_unavailable_alternatives(state): + # Test that EET handles unavailable alternatives in sampling + num_choosers = 100 + num_alts = 10 + sample_size = 2 + choosers = pd.DataFrame( + {"chooser_attr": np.ones(num_choosers)}, + index=pd.Index(range(num_choosers), name="person_id"), + ) + + # Alt 0-4 are attractive, Alt 5-9 are "unavailable" + alternatives = pd.DataFrame( + {"alt_attr": [10.0] * 5 + [-1000.0] * 5}, + index=pd.Index(range(num_alts), name="alt_id"), + ) + + spec = pd.DataFrame( + {"coefficient": [1.0]}, + index=pd.Index(["alt_attr"], name="Expression"), + ) + + # Run with EET + state.settings.use_explicit_error_terms = True + state.rng().set_base_seed(42) + state.rng().add_channel("person_id", choosers) + state.rng().begin_step("test_unavailable_eet") + + choices_eet = interaction_sample.interaction_sample( + state, + choosers, + alternatives, + spec, + sample_size=sample_size, + alt_col_name="alt_id", + ) + + # Sampled alternatives should only be from Alt 0-4 + assert choices_eet["alt_id"].isin([0, 1, 2, 3, 4]).all() + assert not choices_eet["alt_id"].isin([5, 6, 7, 8, 9]).any() + + +def test_interaction_sample_parity_peaked_utilities(state): + # Stress parity under a highly peaked utility profile: + # one dominant alternative, one secondary, and many tiny utilities. + num_choosers = 20_000 + num_alts = 100 + sample_size = 5 + + choosers = pd.DataFrame( + {"chooser_attr": np.ones(num_choosers)}, + index=pd.Index(range(num_choosers), name="person_id"), + ) + + alt_utils = np.array([10.0, 1.0] + [0.0] * (num_alts - 2), dtype=np.float64) + alternatives = pd.DataFrame( + {"alt_attr": alt_utils}, + index=pd.Index(range(num_alts), name="alt_id"), + ) + + spec = pd.DataFrame( + {"coefficient": [1.0]}, + index=pd.Index(["alt_attr"], name="Expression"), + ) + + # Run non-EET path. + state.settings.use_explicit_error_terms = False + state.rng().set_base_seed(42) + state.rng().add_channel("person_id", choosers) + state.rng().begin_step("test_peaked_mnl") + choices_mnl = interaction_sample.interaction_sample( + state, + choosers, + alternatives, + spec, + sample_size=sample_size, + alt_col_name="alt_id", + ) + + # Run EET path with the same seed. + state.init_state() + state.settings.use_explicit_error_terms = True + state.rng().set_base_seed(42) + state.rng().add_channel("person_id", choosers) + state.rng().begin_step("test_peaked_explicit") + choices_explicit = interaction_sample.interaction_sample( + state, + choosers, + alternatives, + spec, + sample_size=sample_size, + alt_col_name="alt_id", + ) + + def weighted_shares(df: pd.DataFrame) -> pd.Series: + counts = df.groupby("alt_id")["pick_count"].sum() + return (counts / counts.sum()).sort_index() + + mnl_shares = weighted_shares(choices_mnl) + explicit_shares = weighted_shares(choices_explicit) + + all_alts = set(mnl_shares.index) | set(explicit_shares.index) + for alt in all_alts: + diff = abs(mnl_shares.get(alt, 0.0) - explicit_shares.get(alt, 0.0)) + assert diff < 0.005, ( + f"Peaked utility parity mismatch at alt {alt}: " + f"mnl={mnl_shares.get(alt, 0.0):.6f}, " + f"explicit={explicit_shares.get(alt, 0.0):.6f}, diff={diff:.6f}" + ) + + # The dominant alternative should absorb almost all mass in both paths. + assert mnl_shares.get(0, 0.0) > 0.99 + assert explicit_shares.get(0, 0.0) > 0.99 + + +class _DummyChunkSizer: + def log_df(self, *_args, **_kwargs): + return None + + +class _DummyState: + def __init__(self, rng): + self._rng = rng + + def get_rn_generator(self): + return self._rng + + +class _DummyRngUtilityBased: + def __init__(self, rands_3d): + self.rands_3d = rands_3d + + def gumbel_for_df(self, _utilities, n): + assert n == self.rands_3d.shape[1] * self.rands_3d.shape[2] + return self.rands_3d.reshape(-1) + + +def test_make_sample_choices_utility_based_repeat_alignment_chooser_dominant_heterogeneity(): + # Edge case: utilities are close across alternatives but vary strongly by chooser. + # This is where wrong chooser/sample alignment can hide in aggregate checks. + chooser_index = pd.Index([101, 102, 103, 104, 105, 106], name="person_id") + choosers = pd.DataFrame(index=chooser_index) + alternatives = pd.DataFrame(index=pd.Index([0, 1, 2, 3], name="alt_id")) + + n_choosers = len(choosers) + n_alts = len(alternatives) + sample_size = 3 + + # Very small alternative differences... + alt_signal = np.array([0.00, 0.01, 0.02, 0.03], dtype=np.float64) + # ...but very large chooser sensitivity differences. + chooser_scale = np.array([-500.0, -200.0, -50.0, 50.0, 200.0, 500.0]) + + utilities = pd.DataFrame( + chooser_scale[:, np.newaxis] * alt_signal[np.newaxis, :], + index=chooser_index, + ) + + # No random noise: chosen alternative is deterministic argmax of utilities. + rands_3d = np.zeros((n_choosers, n_alts, sample_size), dtype=np.float64) + state = _DummyState(_DummyRngUtilityBased(rands_3d)) + + out = interaction_sample.make_sample_choices_utility_based( + state=state, + choosers=choosers, + utilities=utilities, + alternatives=alternatives, + sample_size=sample_size, + alternative_count=n_alts, + alt_col_name="alt_id", + allow_zero_probs=False, + trace_label="test_repeat_alignment_chooser_heterogeneity", + chunk_sizer=_DummyChunkSizer(), + ) + + # Reconstruct expected indexing behavior. + chosen_2d = np.argmax( + rands_3d + utilities.to_numpy()[:, :, np.newaxis], + axis=1, + ) + chosen_flat = chosen_2d.reshape(-1) + + chooser_repeat = np.repeat(np.arange(n_choosers), sample_size) + chooser_tile = np.tile(np.arange(n_choosers), sample_size) + + probs = interaction_sample.logit.utils_to_probs( + state, + utilities, + allow_zero_probs=False, + trace_label="test_repeat_alignment_chooser_heterogeneity", + overflow_protection=True, + trace_choosers=choosers, + ).to_numpy() + + expected_prob_repeat = probs[chooser_repeat, chosen_flat] + wrong_prob_tile = probs[chooser_tile, chosen_flat] + + assert np.array_equal(out["prob"].to_numpy(), expected_prob_repeat) + assert not np.array_equal(out["prob"].to_numpy(), wrong_prob_tile) diff --git a/activitysim/core/test/test_interaction_sample_simulate.py b/activitysim/core/test/test_interaction_sample_simulate.py new file mode 100644 index 000000000..62a40825f --- /dev/null +++ b/activitysim/core/test/test_interaction_sample_simulate.py @@ -0,0 +1,255 @@ +# ActivitySim +# See full license in LICENSE.txt. + +import numpy as np +import pandas as pd +import pytest + +from activitysim.core import interaction_sample_simulate, workflow +from activitysim.core.logit import AltsContext + + +@pytest.fixture +def state() -> workflow.State: + state = workflow.State().default_settings() + state.settings.check_for_variability = False + return state + + +def test_interaction_sample_simulate_parity(state): + # Run interaction_sample_simulate with and without explicit error terms and check that results are similar. + + num_choosers = 100_000 + num_alts_per_chooser = 5 # small sample size to keep things simple + + # Create random choosers + rng = np.random.default_rng(42) + choosers = pd.DataFrame( + {"chooser_attr": rng.random(num_choosers)}, + index=pd.Index(range(num_choosers), name="person_id"), + ) + + # Create random alternatives for each chooser + # In interaction_sample_simulate, alternatives is typically a DataFrame with the same index as choosers + # but repeated for each alternative in the sample. + alt_ids = np.tile(np.arange(num_alts_per_chooser), num_choosers) + alternatives = pd.DataFrame( + { + "alt_attr": rng.random(num_choosers * num_alts_per_chooser), + "alt_id": alt_ids, + "tdd": alt_ids, + }, + index=np.repeat(choosers.index, num_alts_per_chooser), + ) + alternatives.index.name = "person_id" + + # Simple spec: utility = chooser_attr * alt_attr + spec = pd.DataFrame( + {"coefficient": [1.0]}, + index=pd.Index(["chooser_attr * alt_attr"], name="Expression"), + ) + + # Run _without_ explicit error terms + state.settings.use_explicit_error_terms = False + state.rng().set_base_seed(42) + state.rng().add_channel("person_id", choosers) + state.rng().begin_step("test_step_mnl") + + choices_mnl = interaction_sample_simulate.interaction_sample_simulate( + state, + choosers, + alternatives, + spec, + choice_column="tdd", + ) + + # Run _with_ explicit error terms + state.init_state() + state.settings.use_explicit_error_terms = True + state.rng().set_base_seed(42) + state.rng().add_channel("person_id", choosers) + state.rng().begin_step("test_step_explicit") + + choices_explicit = interaction_sample_simulate.interaction_sample_simulate( + state, + choosers, + alternatives, + spec, + choice_column="tdd", + alts_context=AltsContext.from_num_alts(num_alts_per_chooser, zero_based=True), + ) + + assert len(choices_mnl) == num_choosers + assert len(choices_explicit) == num_choosers + assert choices_mnl.index.equals(choosers.index) + assert choices_explicit.index.equals(choosers.index) + assert not choices_mnl.isna().any() + assert not choices_explicit.isna().any() + + # choices are series with the same index as choosers and containing the choice (from choice_column) + mnl_counts = choices_mnl.value_counts(normalize=True).sort_index() + explicit_counts = choices_explicit.value_counts(normalize=True).sort_index() + + for alt in range(num_alts_per_chooser): + share_mnl = mnl_counts.get(alt, 0) + share_explicit = explicit_counts.get(alt, 0) + diff = abs(share_mnl - share_explicit) + assert diff < 0.01, ( + f"Large discrepancy at alt {alt}: " + f"mnl={share_mnl:.4f}, explicit={share_explicit:.4f}, diff={diff:.4f}" + ) + + +def test_interaction_sample_simulate_eet_unavailable_alternatives(state): + # Test that EET handles unavailable alternatives in sample simulation + + num_choosers = 10 + num_alts_per_chooser = 5 + + choosers = pd.DataFrame( + {"chooser_attr": np.ones(num_choosers)}, + index=pd.Index(range(num_choosers), name="person_id"), + ) + + # For each chooser, 2 attractive alts, 3 unavailable + alt_attrs = [10.0, 10.0, -1000.0, -1000.0, -1000.0] * num_choosers + alt_ids = [0, 1, 2, 3, 4] * num_choosers + + alternatives = pd.DataFrame( + { + "alt_attr": alt_attrs, + "alt_id": alt_ids, + "tdd": alt_ids, + }, + index=np.repeat(choosers.index, num_alts_per_chooser), + ) + alternatives.index.name = "person_id" + + spec = pd.DataFrame( + {"coefficient": [1.0]}, + index=pd.Index(["alt_attr"], name="Expression"), + ) + + # Run with EET + state.settings.use_explicit_error_terms = True + state.rng().set_base_seed(42) + state.rng().add_channel("person_id", choosers) + state.rng().begin_step("test_unavailable_eet") + + choices_eet = interaction_sample_simulate.interaction_sample_simulate( + state, + choosers, + alternatives, + spec, + choice_column="tdd", + alts_context=AltsContext.from_num_alts(num_alts_per_chooser, zero_based=True), + ) + + assert len(choices_eet) == num_choosers + assert choices_eet.index.equals(choosers.index) + assert not choices_eet.isna().any() + + # Choices should only be 0 or 1 + assert choices_eet.isin([0, 1]).all() + assert not choices_eet.isin([2, 3, 4]).any() + + +def test_interaction_sample_simulate_passes_alts_context_and_alt_nrs_df( + state, monkeypatch +): + state.settings.use_explicit_error_terms = True + + choosers = pd.DataFrame( + {"chooser_attr": [1.0, 1.0]}, + index=pd.Index([100, 101], name="person_id"), + ) + alternatives = pd.DataFrame( + { + "alt_attr": [1.0, 0.5, 0.8, 1.2], + "tdd": [0, 2, 0, 2], + }, + index=pd.Index([100, 100, 101, 101], name="person_id"), + ) + spec = pd.DataFrame( + {"coefficient": [1.0]}, + index=pd.Index(["alt_attr"], name="Expression"), + ) + + captured = {} + + def fake_make_choices_utility_based( + _state, + utilities, + name_mapping=None, + nest_spec=None, + trace_label=None, + trace_choosers=None, + allow_bad_utils=False, + alts_context=None, + alt_nrs_df=None, + ): + captured["alts_context"] = alts_context + captured["alt_nrs_df"] = alt_nrs_df.copy() if alt_nrs_df is not None else None + return pd.Series([0, 0], index=utilities.index), pd.Series( + np.zeros(len(utilities.index)), index=utilities.index + ) + + monkeypatch.setattr( + interaction_sample_simulate.logit, + "make_choices_utility_based", + fake_make_choices_utility_based, + ) + + state.rng().set_base_seed(42) + state.rng().add_channel("person_id", choosers) + state.rng().begin_step("test_step_alts_context_forwarding") + + ctx = AltsContext.from_num_alts(3, zero_based=True) + choices = interaction_sample_simulate.interaction_sample_simulate( + state, + choosers, + alternatives, + spec, + choice_column="tdd", + alts_context=ctx, + ) + + assert len(choices) == len(choosers) + assert captured["alts_context"] == ctx + assert captured["alt_nrs_df"] is not None + expected_alt_nrs = pd.DataFrame( + [[0, 2], [0, 2]], + index=choosers.index, + ) + pd.testing.assert_frame_equal(captured["alt_nrs_df"], expected_alt_nrs) + + +def test_interaction_sample_simulate_requires_alts_context_for_eet_integer_choices( + state, +): + state.settings.use_explicit_error_terms = True + + choosers = pd.DataFrame( + {"chooser_attr": [1.0, 1.0]}, + index=pd.Index([200, 201], name="person_id"), + ) + alternatives = pd.DataFrame( + { + "alt_attr": [1.0, 0.5, 0.8, 1.2], + "tdd": [0, 2, 0, 2], + }, + index=pd.Index([200, 200, 201, 201], name="person_id"), + ) + spec = pd.DataFrame( + {"coefficient": [1.0]}, + index=pd.Index(["alt_attr"], name="Expression"), + ) + + with pytest.raises(ValueError, match="alts_context is required"): + interaction_sample_simulate.interaction_sample_simulate( + state, + choosers, + alternatives, + spec, + choice_column="tdd", + ) diff --git a/activitysim/core/test/test_interaction_simulate.py b/activitysim/core/test/test_interaction_simulate.py new file mode 100644 index 000000000..af9442e22 --- /dev/null +++ b/activitysim/core/test/test_interaction_simulate.py @@ -0,0 +1,174 @@ +# ActivitySim +# See full license in LICENSE.txt. + +import numpy as np +import pandas as pd +import pytest + +from activitysim.core import interaction_simulate, workflow + + +@pytest.fixture +def state() -> workflow.State: + state = workflow.State().default_settings() + state.settings.check_for_variability = False + return state + + +def test_interaction_simulate_explicit_error_terms_parity(state): + # Run interaction_simulate with and without explicit error terms and check that results are similar. + + # Keep this large enough for stable parity checks without overloading CI. + num_choosers = 100_000 + num_alts = 5 + sample_size = num_alts + + # Create random choosers and alternatives + rng = np.random.default_rng(42) + choosers = pd.DataFrame( + {"chooser_attr": rng.random(num_choosers)}, + index=pd.Index(range(num_choosers), name="person_id"), + ) + + alternatives = pd.DataFrame( + {"alt_attr": rng.random(num_alts)}, + index=pd.Index(range(num_alts), name="alt_id"), + ) + + spec = pd.DataFrame( + {"coefficient": [1.0]}, + index=pd.Index(["chooser_attr * alt_attr"], name="Expression"), + ) + + # Run _without_ explicit error terms + state.settings.use_explicit_error_terms = False + state.rng().set_base_seed(42) # Set seed BEFORE adding channels or steps + state.rng().add_channel("person_id", choosers) + state.rng().begin_step("test_step_mnl") + + choices_mnl = interaction_simulate.interaction_simulate( + state, + choosers, + alternatives, + spec, + sample_size=sample_size, + ) + + # Run _with_ explicit error terms + state.init_state() # reset the state to rerun with same seed + state.settings.use_explicit_error_terms = True + state.rng().set_base_seed(42) + state.rng().add_channel("person_id", choosers) + state.rng().begin_step("test_step_explicit") + + choices_explicit = interaction_simulate.interaction_simulate( + state, + choosers, + alternatives, + spec, + sample_size=sample_size, + ) + + assert len(choices_mnl) == num_choosers + assert len(choices_explicit) == num_choosers + assert choices_mnl.index.equals(choosers.index) + assert choices_explicit.index.equals(choosers.index) + assert not choices_mnl.isna().any() + assert not choices_explicit.isna().any() + + mnl_counts = choices_mnl.value_counts(normalize=True).sort_index() + explicit_counts = choices_explicit.value_counts(normalize=True).sort_index() + + # Check that they are close, relative to the number of draws + assert np.allclose( + mnl_counts.to_numpy(), explicit_counts.to_numpy(), atol=0.01, rtol=0.001 + ) + + +def test_interaction_simulate_eet_unavailable_alternatives(state): + # Test that EET handles unavailable alternatives (very low utilities) + # similarly to MNL (zero probabilities). + + num_choosers = 100 + num_alts = 5 + + choosers = pd.DataFrame( + {"chooser_attr": np.ones(num_choosers)}, + index=pd.Index(range(num_choosers), name="person_id"), + ) + + # Alt 0 and 1 are attractive, Alt 2, 3, 4 are "unavailable" (very low utility) + alternatives = pd.DataFrame( + {"alt_attr": [10.0, 10.0, -1000.0, -1000.0, -1000.0]}, + index=pd.Index(range(num_alts), name="alt_id"), + ) + + spec = pd.DataFrame( + {"coefficient": [1.0]}, + index=pd.Index(["alt_attr"], name="Expression"), + ) + + # Run with EET + state.settings.use_explicit_error_terms = True + state.rng().set_base_seed(42) + state.rng().add_channel("person_id", choosers) + state.rng().begin_step("test_unavailable_eet") + + choices_eet = interaction_simulate.interaction_simulate( + state, + choosers, + alternatives, + spec, + sample_size=num_alts, + ) + + assert len(choices_eet) == num_choosers + assert choices_eet.index.equals(choosers.index) + assert not choices_eet.isna().any() + + # Choices should only be from Alt 0 or 1 + assert choices_eet.isin( + [0, 1] + ).all(), f"EET picked an 'unavailable' alternative: {choices_eet[~choices_eet.isin([0, 1])]}" + + +def test_interaction_simulate_eet_large_utilities(state): + # Test that EET handles very large utilities without overflow issues + # that might occur in exp(util) calculations in standard MNL. + + num_choosers = 10 + num_alts = 2 + + choosers = pd.DataFrame( + {"chooser_attr": np.ones(num_choosers)}, + index=pd.Index(range(num_choosers), name="person_id"), + ) + + # Standard MNL might struggle with exp(700) or exp(800) depending on float precision + alternatives = pd.DataFrame( + {"alt_attr": [700.0, 800.0]}, + index=pd.Index(range(num_alts), name="alt_id"), + ) + + spec = pd.DataFrame( + {"coefficient": [1.0]}, + index=pd.Index(["alt_attr"], name="Expression"), + ) + + state.settings.use_explicit_error_terms = True + state.rng().set_base_seed(42) + state.rng().add_channel("person_id", choosers) + state.rng().begin_step("test_large_utils_eet") + + # This should run without crashing or returning NaNs + choices_eet = interaction_simulate.interaction_simulate( + state, + choosers, + alternatives, + spec, + sample_size=num_alts, + ) + + assert not choices_eet.isna().any() + # With such a large difference, Alt 1 should be the dominant choice + assert (choices_eet == 1).all() diff --git a/activitysim/core/test/test_logit.py b/activitysim/core/test/test_logit.py index c82606981..b5111e352 100644 --- a/activitysim/core/test/test_logit.py +++ b/activitysim/core/test/test_logit.py @@ -3,13 +3,16 @@ from __future__ import annotations import os.path +import re import numpy as np import pandas as pd import pandas.testing as pdt import pytest -from activitysim.core import logit, workflow +from activitysim.core import logit, random, simulate, workflow +from activitysim.core.exceptions import InvalidTravelError +from activitysim.core.logit import AltsContext, add_ev1_random from activitysim.core.simulate import eval_variables @@ -70,7 +73,122 @@ def utilities(choosers, spec, test_data): ) -# TODO-EET: Add tests here! +@pytest.fixture(scope="module") +def interaction_choosers(): + return pd.DataFrame({"attr": ["a", "b", "c", "b"]}, index=["w", "x", "y", "z"]) + + +@pytest.fixture(scope="module") +def interaction_alts(): + return pd.DataFrame({"prop": [10, 20, 30, 40]}, index=[1, 2, 3, 4]) + + +# +# Utility Validation Tests +# +def test_validate_utils_replaces_unavailable_values(): + state = workflow.State().default_settings() + utils = pd.DataFrame([[0.0, logit.UTIL_MIN - 1.0], [1.0, 2.0]]) + + validated = logit.validate_utils(state, utils, allow_zero_probs=False) + + assert validated.iloc[0, 0] == pytest.approx(0.0) + assert validated.iloc[0, 1] == pytest.approx(logit.UTIL_UNAVAILABLE) + assert validated.iloc[1, 0] == pytest.approx(1.0) + assert validated.iloc[1, 1] == pytest.approx(2.0) + + +def test_validate_utils_raises_when_all_unavailable(): + state = workflow.State().default_settings() + utils = pd.DataFrame([[logit.UTIL_MIN - 1.0, logit.UTIL_MIN - 2.0]]) + + with pytest.raises(InvalidTravelError) as excinfo: + logit.validate_utils(state, utils, allow_zero_probs=False) + + assert "all probabilities are zero" in str(excinfo.value) + + +def test_validate_utils_allows_zero_probs(): + state = workflow.State().default_settings() + utils = pd.DataFrame([[0.5, logit.UTIL_MIN - 1.0]]) + + validated = logit.validate_utils(state, utils, allow_zero_probs=True) + + assert validated.iloc[0, 0] == 0.5 + assert validated.iloc[0, 1] == logit.UTIL_UNAVAILABLE + + +# +# `utils_to_probs` Tests +# +def test_utils_to_probs_logsums_with_overflow_protection(): + state = workflow.State().default_settings() + utils = pd.DataFrame( + [[1000.0, 1001.0, 999.0], [-1000.0, -1001.0, -999.0]], + columns=["a", "b", "c"], + ) + original_utils = utils.copy() + + probs, logsums = logit.utils_to_probs( + state, + utils, + trace_label=None, + overflow_protection=True, + return_logsums=True, + ) + + utils_np = original_utils.to_numpy() + row_max = utils_np.max(axis=1, keepdims=True) + exp_shifted = np.exp(utils_np - row_max) + expected_probs = exp_shifted / exp_shifted.sum(axis=1, keepdims=True) + expected_logsums = pd.Series( + np.log(exp_shifted.sum(axis=1)) + row_max.squeeze(), + index=utils.index, + ) + + pdt.assert_frame_equal( + probs, + pd.DataFrame(expected_probs, index=utils.index, columns=utils.columns), + rtol=1.0e-7, + atol=0.0, + ) + pdt.assert_series_equal(logsums, expected_logsums, rtol=1.0e-7, atol=0.0) + + +def test_utils_to_probs_warns_on_zero_probs_overflow(): + state = workflow.State().default_settings() + utils = pd.DataFrame( + [[logit.UTIL_MIN - 1.0, logit.UTIL_MIN - 2.0], [0.0, 0.0]], + columns=["a", "b"], + ) + + with pytest.warns(UserWarning, match="cannot set overflow_protection"): + probs = logit.utils_to_probs( + state, + utils, + trace_label=None, + allow_zero_probs=True, + overflow_protection=True, + ) + + assert (probs.iloc[0] == 0.0).all() + assert probs.iloc[1].sum() == pytest.approx(1.0) + assert probs.iloc[1].iloc[0] == pytest.approx(0.5) + assert probs.iloc[1].iloc[1] == pytest.approx(0.5) + + +def test_utils_to_probs_raises_on_float32_zero_probs_overflow(): + state = workflow.State().default_settings() + utils = pd.DataFrame(np.array([[90.0, 0.0]], dtype=np.float32)) + + with pytest.raises(ValueError, match="cannot prevent expected overflow"): + logit.utils_to_probs( + state, + utils, + trace_label=None, + allow_zero_probs=True, + overflow_protection=True, + ) def test_utils_to_probs(utilities, test_data): @@ -119,6 +237,9 @@ def test_utils_to_probs_raises(): assert np.asarray(z).ravel() == pytest.approx(np.asarray([0.0, 0.0, 1.0, 0.0])) +# +# `make_choices` Tests +# def test_make_choices_only_one(): state = workflow.State().default_settings() probs = pd.DataFrame( @@ -143,16 +264,447 @@ def test_make_choices_real_probs(utilities): ) -@pytest.fixture(scope="module") -def interaction_choosers(): - return pd.DataFrame({"attr": ["a", "b", "c", "b"]}, index=["w", "x", "y", "z"]) +def test_different_order_make_choices(): + # check if, when we shuffle utilities, make_choices chooses the same alternatives + state = workflow.State().default_settings() + # increase number of choosers and alternatives for realism + n_choosers = 100 + n_alts = 50 + data = np.random.rand(n_choosers, n_alts) + chooser_ids = np.arange(n_choosers) + alt_ids = [f"alt_{i}" for i in range(n_alts)] + + utilities = pd.DataFrame( + data, + index=pd.Index(chooser_ids, name="chooser_id"), + columns=alt_ids, + ) -@pytest.fixture(scope="module") -def interaction_alts(): - return pd.DataFrame({"prop": [10, 20, 30, 40]}, index=[1, 2, 3, 4]) + # We need a stable RNG that gives the same random numbers for the same chooser_id + # regardless of row order. ActivitySim's random.Random does this. + state.get_rn_generator().add_channel("chooser_id", utilities) + state.get_rn_generator().begin_step("test_step") + + probs = logit.utils_to_probs(state, utilities, trace_label=None) + choices, rands = logit.make_choices(state, probs) + + # shuffle utilities (rows) and make_choices again + # We must reset the step offset so the RNG produces the same sequence for the same IDs + state.get_rn_generator().end_step("test_step") + state.get_rn_generator().begin_step("test_step") + utilities_shuffled = utilities.sample(frac=1, random_state=42) + probs_shuffled = logit.utils_to_probs(state, utilities_shuffled, trace_label=None) + choices_shuffled, rands_shuffled = logit.make_choices(state, probs_shuffled) + + # sorting both to ensure comparison is on the same index order + pdt.assert_series_equal( + choices.sort_index(), choices_shuffled.sort_index(), check_dtype=False + ) + + +def test_make_choices_matches_random_draws(): + class DummyRNG: + def random_for_df(self, df, n=1): + assert n == 1 + return np.array([[0.05], [0.6], [0.95]]) + + class DummyState: + @staticmethod + def get_rn_generator(): + return DummyRNG() + + state = DummyState() + probs = pd.DataFrame( + [[0.1, 0.2, 0.7], [0.4, 0.4, 0.2], [0.05, 0.9, 0.05]], + index=["a", "b", "c"], + columns=["x", "y", "z"], + ) + choices, rands = logit.make_choices(state, probs) + + expected_rands = np.array([0.05, 0.6, 0.95]) + expected_choices = np.array([0, 1, 1]) + + pdt.assert_series_equal( + rands, + pd.Series(expected_rands, index=probs.index), + check_names=False, + ) + pdt.assert_series_equal( + choices, + pd.Series(expected_choices, index=probs.index), + check_dtype=False, + ) + + +# +# EV1 Random Tests +# +def test_add_ev1_random(): + class DummyRNG: + def gumbel_for_df(self, df, n): + # Deterministic, non-constant draws make it easy to verify + # correct per-row/per-column addition behavior. + row_component = df.index.to_numpy(dtype=float).reshape(-1, 1) / 10.0 + col_component = np.arange(n, dtype=float).reshape(1, -1) + return row_component + col_component + + rng = DummyRNG() + + class DummyState: + @staticmethod + def get_rn_generator(): + return rng + + utilities = pd.DataFrame( + [[1.0, 2.0], [3.0, 4.0]], + index=[10, 11], + columns=["a", "b"], + ) + + randomized = logit.add_ev1_random(DummyState(), utilities) + + expected = pd.DataFrame( + [[2.0, 4.0], [4.1, 6.1]], + index=[10, 11], + columns=["a", "b"], + ) + + # check that the random component was added correctly, and that the original utilities were not mutated + pdt.assert_frame_equal(randomized, expected) + pdt.assert_index_equal(randomized.index, utilities.index) + pdt.assert_index_equal(randomized.columns, utilities.columns) + pdt.assert_frame_equal( + utilities, + pd.DataFrame( + [[1.0, 2.0], [3.0, 4.0]], + index=[10, 11], + columns=["a", "b"], + ), + ) + + +def test_add_ev1_random_requires_paired_alt_context_args(): + class DummyRNG: + def gumbel_for_df(self, df, n): + return np.zeros((len(df), n)) + + class DummyState: + @staticmethod + def get_rn_generator(): + return DummyRNG() + + utilities = pd.DataFrame([[1.0, 2.0]], index=[1], columns=["a", "b"]) + + with pytest.raises( + AssertionError, + match="alt_info and alt_nrs_df must both be provided or omitted together", + ): + logit.add_ev1_random( + DummyState(), + utilities, + alt_info=AltsContext.from_num_alts(2), + alt_nrs_df=None, + ) + + +# +# Nested Logit Structure Tests +# +def test_group_nest_names_by_level(): + nest_spec = { + "name": "root", + "coefficient": 1.0, + "alternatives": [ + {"name": "motorized", "coefficient": 0.7, "alternatives": ["car", "bus"]}, + "walk", + ], + } + + grouped = logit.group_nest_names_by_level(nest_spec) + + assert grouped == {1: ["root"], 2: ["motorized", "walk"], 3: ["car", "bus"]} + + +def test_choose_from_tree_selects_leaf(): + nest_utils = pd.Series( + { + "motorized": 2.0, + "walk": 1.0, + "car": 5.0, + "bus": 3.0, + } + ) + all_alternatives = {"walk", "car", "bus"} + logit_nest_groups = {1: ["root"], 2: ["motorized", "walk"], 3: ["car", "bus"]} + nest_alternatives_by_name = { + "root": ["motorized", "walk"], + "motorized": ["car", "bus"], + } + + choice = logit.choose_from_tree( + nest_utils, all_alternatives, logit_nest_groups, nest_alternatives_by_name + ) + + assert choice == "car" + + +def test_choose_from_tree_raises_on_missing_leaf(): + nest_utils = pd.Series({"motorized": 2.0, "walk": 1.0}) + all_alternatives = {"car", "bus"} + logit_nest_groups = {1: ["root"], 2: ["motorized", "walk"]} + nest_alternatives_by_name = { + "root": ["motorized", "walk"], + "motorized": ["car", "bus"], + } + + with pytest.raises(ValueError, match="no alternative found"): + logit.choose_from_tree( + nest_utils, all_alternatives, logit_nest_groups, nest_alternatives_by_name + ) + + +# +# EET Choice Behavior Tests +# +def test_make_choices_eet_mnl(monkeypatch): + def fake_add_ev1_random(_state, _df, alt_info=None, alt_nrs_df=None): + return pd.DataFrame( + [[1.0, 3.0], [4.0, 2.0]], + index=[100, 101], + columns=["a", "b"], + ) + + monkeypatch.setattr(logit, "add_ev1_random", fake_add_ev1_random) + + choices = logit.make_choices_explicit_error_term_mnl( + workflow.State().default_settings(), + pd.DataFrame([[0.0, 0.0], [0.0, 0.0]], index=[100, 101], columns=["a", "b"]), + trace_label=None, + ) + + pdt.assert_series_equal(choices, pd.Series([1, 0], index=[100, 101])) + + +def test_make_choices_eet_nl(monkeypatch): + def fake_add_ev1_random(_state, _df, alt_info=None, alt_nrs_df=None): + return pd.DataFrame( + [[5.0, 1.0, 4.0, 2.0], [3.0, 4.0, 1.0, 2.0]], + index=[10, 11], + columns=["motorized", "walk", "car", "bus"], + ) + + monkeypatch.setattr(logit, "add_ev1_random", fake_add_ev1_random) + + nest_spec = { + "name": "root", + "coefficient": 1.0, + "alternatives": [ + {"name": "motorized", "coefficient": 0.7, "alternatives": ["car", "bus"]}, + "walk", + ], + } + alt_order_array = np.array(["walk", "car", "bus"]) + + choices = logit.make_choices_explicit_error_term_nl( + workflow.State().default_settings(), + pd.DataFrame( + [[0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0]], + index=[10, 11], + columns=["motorized", "walk", "car", "bus"], + ), + alt_order_array, + nest_spec, + trace_label=None, + ) + + pdt.assert_series_equal(choices, pd.Series([1, 0], index=[10, 11])) + + +def test_make_choices_utility_based_sets_zero_rands(monkeypatch): + def fake_add_ev1_random(_state, df, alt_info=None, alt_nrs_df=None): + return pd.DataFrame( + [[2.0, 1.0], [0.5, 2.5]], + index=df.index, + columns=df.columns, + ) + + monkeypatch.setattr(logit, "add_ev1_random", fake_add_ev1_random) + + utilities = pd.DataFrame([[3.0, 2.0], [1.0, 4.0]], index=[11, 12]) + choices, rands = logit.make_choices_utility_based( + workflow.State().default_settings(), + utilities, + name_mapping=np.array(["a", "b"]), + nest_spec=None, + trace_label=None, + ) + + expected_choices = pd.Series([0, 1], index=[11, 12]) + pdt.assert_series_equal(choices, expected_choices) + pdt.assert_series_equal(rands, pd.Series([0, 0], index=[11, 12])) + + +# +# EET vs non-EET Choice Behavior Tests +# +def test_make_choices_vs_eet_same_distribution(): + """With many draws, make_choices (probability-based) and + make_choices_explicit_error_term_mnl (EET) should produce roughly the + same empirical choice-frequency distribution for the same utilities.""" + n_draws = 1_000_000 + a_tol = 0.001 + r_tol = 0.01 + utils_values = [5.0, 6.0, 7.0, 8.0, 9.0] + n_alts = len(utils_values) + columns = ["a", "b", "c", "d", "e"] + + utils = pd.DataFrame([utils_values] * n_draws, columns=columns) + + # Probability-based (Monte Carlo) path — independent RNG + mc_rng = np.random.default_rng(42) + + class MCDummyRNG: + def random_for_df(self, df, n=1): + return mc_rng.random((len(df), n)) + + class MCDummyState: + @staticmethod + def get_rn_generator(): + return MCDummyRNG() + + probs = logit.utils_to_probs( + MCDummyState(), utils, trace_label=None, overflow_protection=True + ) + choices_mc, _ = logit.make_choices(MCDummyState(), probs, trace_label=None) + + # Explicit-error-term (EET) path — independent RNG + eet_rng = np.random.default_rng(123) + + class EETDummyRNG: + def gumbel_for_df(self, df, n): + return eet_rng.gumbel(size=(len(df), n)) + + class EETDummyState: + @staticmethod + def get_rn_generator(): + return EETDummyRNG() + + choices_eet = logit.make_choices_explicit_error_term_mnl( + EETDummyState(), utils, trace_label=None + ) + mc_fracs = np.bincount(choices_mc.values.astype(int), minlength=n_alts) / n_draws + eet_fracs = np.bincount(choices_eet.values.astype(int), minlength=n_alts) / n_draws + np.testing.assert_allclose(mc_fracs, eet_fracs, atol=a_tol, rtol=r_tol) + np.testing.assert_allclose( + mc_fracs, probs.iloc[0].to_numpy(), atol=a_tol, rtol=r_tol + ) + np.testing.assert_allclose( + eet_fracs, probs.iloc[0].to_numpy(), atol=a_tol, rtol=r_tol + ) + + +def test_make_choices_vs_eet_nl_same_distribution(): + """With many draws, nested logit choices via probabilities and + nested logit choices via EET should produce the same empirical distribution.""" + n_draws = 100_000 + a_tol = 0.01 + + nest_spec = { + "name": "root", + "coefficient": 1.0, + "alternatives": [ + {"name": "motorized", "coefficient": 0.5, "alternatives": ["car", "bus"]}, + "walk", + ], + } + # Utilities for car, bus, walk + # For NL, we need utilities for all nodes in the tree for EET, + # but for probability-based choice we usually use the flattened/logsummed probabilities. + # To compare them fairly, we use the same base utilities. + # car=0.5, bus=0.2, walk=0.4 + utils_df = pd.DataFrame( + [[0.5, 0.2, 0.4, 0.0, 0.0]], + columns=["car", "bus", "walk", "motorized", "root"], + ) + utils_df = pd.concat([utils_df] * n_draws, ignore_index=True) + alt_order_array = np.array(["car", "bus", "walk"]) + + # 1. Probability-based Nested Logit choices + mc_rng = np.random.default_rng(42) + + class MCDummyRNG: + def random_for_df(self, df, n=1): + return mc_rng.random((len(df), n)) + + class MCDummyState: + @staticmethod + def get_rn_generator(): + return MCDummyRNG() + + def default_settings(self): + return self + + # Compute probabilities for NL using simulation logic + nested_exp_utilities = simulate.compute_nested_exp_utilities( + utils_df[["car", "bus", "walk"]], nest_spec + ) + nested_probabilities = simulate.compute_nested_probabilities( + MCDummyState(), nested_exp_utilities, nest_spec, trace_label=None + ) + probs = simulate.compute_base_probabilities( + nested_probabilities, nest_spec, utils_df[["car", "bus", "walk"]] + ) + choices_mc, _ = logit.make_choices(MCDummyState(), probs, trace_label=None) + + # 2. EET-based Nested Logit choices + eet_rng = np.random.default_rng(123) + + class EETDummyRNG: + def gumbel_for_df(self, df, n): + return eet_rng.gumbel(size=(len(df), n)) + + class EETDummyState: + @staticmethod + def get_rn_generator(): + return EETDummyRNG() + + def default_settings(self): + return self + + @property + def tracing(self): + import activitysim.core.tracing as tracing + + return tracing + + # For EET NL, we provide the utilities for all nodes. + # compute_nested_utilities handles the division by nesting coefficients for leaves + # and the logsum * coefficient for internal nodes. + nested_utilities = simulate.compute_nested_utilities( + utils_df[["car", "bus", "walk"]], nest_spec + ) + + choices_eet = logit.make_choices_explicit_error_term_nl( + EETDummyState(), + nested_utilities, + alt_order_array, + nest_spec, + trace_label=None, + ) + + mc_fracs = np.bincount(choices_mc.values.astype(int), minlength=3) / n_draws + eet_fracs = np.bincount(choices_eet.values.astype(int), minlength=3) / n_draws + + # They should be close + np.testing.assert_allclose(mc_fracs, eet_fracs, atol=a_tol) + + +# +# Interaction Dataset Tests +# def test_interaction_dataset_no_sample(interaction_choosers, interaction_alts): expected = pd.DataFrame( { @@ -167,9 +719,6 @@ def test_interaction_dataset_no_sample(interaction_choosers, interaction_alts): ) interacted, expected = interacted.align(expected, axis=1) - - print("interacted\n", interacted) - print("expected\n", expected) pdt.assert_frame_equal(interacted, expected) @@ -191,3 +740,99 @@ def test_interaction_dataset_sampled(interaction_choosers, interaction_alts): interacted, expected = interacted.align(expected, axis=1) pdt.assert_frame_equal(interacted, expected) + + +def reset_step(state, name="test_step"): + state.get_rn_generator().end_step(name) + state.get_rn_generator().begin_step(name) + + +def test_make_choices_utility_based_sampled_alts(): + """Test the situation of making choices from a sampled choice set""" + # TODO should these tests go in test_random? + state = workflow.State().default_settings() + # Make explicit that there's two indexing schemes - the raw alts, and the 0 based internals + utils_project_raw = pd.DataFrame( + {"a": 10.582999, "b": 10.680792, "c": 10.710443}, + index=pd.Index([0], name="person_id"), + ) + # zero based indexes + utils_project = utils_project_raw.rename(columns={"a": 0, "b": 1, "c": 2}) + utils_base = utils_project_raw[["a", "c"]].rename(columns={"a": 0, "c": 1}) + + assert utils_project.index.name == "person_id" + state.get_rn_generator().add_channel("persons", utils_project) + state.get_rn_generator().begin_step("test_step") + # mock base case, where alt 1 is omitted (it was improved in the project) + # this situation is quite common with poisson sampling with a variable choice set size, + # but it can also happen in with-replacement EET sampling e.g. if alt 2 had a pick_count of 2 in the base case. + # In principle, it can also be problematic for non-sampled choices where there is a base project difference in the + # availability of alternatives .e.g a new mode was introduced in the project case + + utils_project_with_rands = add_ev1_random(state, utils_project) + rands_project = utils_project_with_rands - utils_project + reset_step(state) + utils_base_with_rands = add_ev1_random(state, utils_base) + rands_base = utils_base_with_rands - utils_base + rands_base_labeled = rands_base.rename(columns={0: "a", 1: "c"}) + rands_project_labeled = rands_project.rename(columns={0: "a", 1: "b", 2: "c"}) + with pytest.raises( + AssertionError, match=re.escape('(column name="c") are different') + ): + # TODO this should pass + pdt.assert_frame_equal( + rands_base_labeled, rands_project_labeled.loc[:, rands_base_labeled.columns] + ) + # document incorrect invariant - first two columns have the same random numbers: + pdt.assert_frame_equal(rands_base, rands_project.iloc[:, :2]) + + # revised approach + reset_step(state) + alt_nrs_df = pd.DataFrame({0: 0, 1: 1, 2: 2}, index=utils_project_raw.index) + alt_info = AltsContext.from_num_alts(3, zero_based=True) + utils_project_with_rands = add_ev1_random( + state, utils_project, alt_info=alt_info, alt_nrs_df=alt_nrs_df + ) + rands_project = utils_project_with_rands - utils_project + reset_step(state) + + # alt "b" is missing from the sampled choice set, alt_nrs_df is set to reflect that + alt_nrs_df = pd.DataFrame({0: 0, 1: 2}, index=utils_project_raw.index) + utils_base_with_rands = add_ev1_random( + state, utils_base, alt_info=alt_info, alt_nrs_df=alt_nrs_df + ) + rands_base = utils_base_with_rands - utils_base + rands_base_labeled = rands_base.rename(columns={0: "a", 1: "c"}) + rands_project_labeled = rands_project.rename(columns={0: "a", 1: "b", 2: "c"}) + + # Corrected invariant holds true + pdt.assert_frame_equal( + rands_base_labeled, rands_project_labeled.loc[:, rands_base_labeled.columns] + ) + + +def test_alts_context_from_series_and_properties(): + ctx = AltsContext.from_series(pd.Index([3, 5, 9, 4])) + + assert ctx.min_alt_id == 3 + assert ctx.max_alt_id == 9 + assert ctx.n_alts_to_cover_max_id == 10 + assert ctx.n_rands_to_sample == 10 + + +@pytest.mark.parametrize( + "num_alts,zero_based,expected_min,expected_max,expected_n_cover", + [ + (5, True, 0, 4, 5), + (5, False, 1, 5, 6), + ], +) +def test_alts_context_from_num_alts( + num_alts, zero_based, expected_min, expected_max, expected_n_cover +): + ctx = AltsContext.from_num_alts(num_alts=num_alts, zero_based=zero_based) + + assert ctx.min_alt_id == expected_min + assert ctx.max_alt_id == expected_max + assert ctx.n_alts_to_cover_max_id == expected_n_cover + assert ctx.n_rands_to_sample == expected_n_cover diff --git a/activitysim/core/test/test_simulate.py b/activitysim/core/test/test_simulate.py index 17d4ba2cd..21e0f90e7 100644 --- a/activitysim/core/test/test_simulate.py +++ b/activitysim/core/test/test_simulate.py @@ -10,7 +10,7 @@ import pandas.testing as pdt import pytest -from activitysim.core import simulate, workflow +from activitysim.core import chunk, simulate, workflow @pytest.fixture @@ -42,6 +42,19 @@ def data(data_dir): return pd.read_csv(os.path.join(data_dir, "data.csv")) +@pytest.fixture +def nest_spec(): + nest_spec = { + "name": "root", + "coefficient": 1.0, + "alternatives": [ + {"name": "alt0", "coefficient": 0.5, "alternatives": ["alt0.0", "alt0.1"]}, + "alt1", + ], + } + return nest_spec + + def test_read_model_spec(state, spec_name): spec = state.filesystem.read_model_spec(file_name=spec_name) @@ -88,3 +101,234 @@ def test_simple_simulate_chunked(state, data, spec): ) expected = pd.Series([1, 1, 1], index=data.index) pdt.assert_series_equal(choices, expected, check_dtype=False) + + +def test_eval_mnl_eet(state): + # Check that the same counts are returned by eval_mnl when using EET and when not. + + num_choosers = 100_000 + + np.random.seed(42) + data2 = pd.DataFrame( + { + "chooser_attr": np.random.rand(num_choosers), + }, + index=pd.Index(range(num_choosers), name="person_id"), + ) + + spec2 = pd.DataFrame( + {"alt0": [1.0], "alt1": [2.0]}, + index=pd.Index(["chooser_attr"], name="Expression"), + ) + + # Set up a state with EET enabled + state.settings.use_explicit_error_terms = True + state.rng().set_base_seed(42) + state.rng().add_channel("person_id", data2) + state.rng().begin_step("test_step_mnl") + + chunk_sizer = chunk.ChunkSizer(state, "", "", num_choosers) + + # run eval_mnl with EET enabled + choices_eet = simulate.eval_mnl( + state=state, + choosers=data2, + spec=spec2, + locals_d=None, + custom_chooser=None, + estimator=None, + chunk_sizer=chunk_sizer, + ) + + # Reset the state, without EET enabled + state.settings.use_explicit_error_terms = False + + state.rng().end_step("test_step_mnl") + state.rng().begin_step("test_step_mnl") + + choices_mnl = simulate.eval_mnl( + state=state, + choosers=data2, + spec=spec2, + locals_d=None, + custom_chooser=None, + estimator=None, + chunk_sizer=chunk_sizer, + ) + + # Compare counts + mnl_counts = choices_mnl.value_counts(normalize=True) + explicit_counts = choices_eet.value_counts(normalize=True) + assert np.allclose(mnl_counts, explicit_counts, atol=0.01) + + +def test_eval_nl_eet(state, nest_spec): + # Check that the same counts are returned by eval_nl when using EET and when not. + + num_choosers = 100_000 + + np.random.seed(42) + data2 = pd.DataFrame( + { + "chooser_attr": np.random.rand(num_choosers), + }, + index=pd.Index(range(num_choosers), name="person_id"), + ) + + spec2 = pd.DataFrame( + {"alt1": [2.0], "alt0.0": [0.5], "alt0.1": [0.2]}, + index=pd.Index(["chooser_attr"], name="Expression"), + ) + + # Set up a state with EET enabled + state.settings.use_explicit_error_terms = True + state.rng().set_base_seed(42) + state.rng().add_channel("person_id", data2) + state.rng().begin_step("test_step_mnl") + + chunk_sizer = chunk.ChunkSizer(state, "", "", num_choosers) + + # run eval_nl with EET enabled + choices_eet = simulate.eval_nl( + state=state, + choosers=data2, + spec=spec2, + nest_spec=nest_spec, + locals_d={}, + custom_chooser=None, + estimator=None, + trace_label="test", + chunk_sizer=chunk_sizer, + ) + + # Reset the state, without EET enabled + state.settings.use_explicit_error_terms = False + + state.rng().end_step("test_step_mnl") + state.rng().begin_step("test_step_mnl") + + choices_mnl = simulate.eval_nl( + state=state, + choosers=data2, + spec=spec2, + nest_spec=nest_spec, + locals_d={}, + custom_chooser=None, + trace_label="test", + estimator=None, + chunk_sizer=chunk_sizer, + ) + + # Compare counts + mnl_counts = choices_mnl.value_counts(normalize=True) + explicit_counts = choices_eet.value_counts(normalize=True) + assert np.allclose(mnl_counts, explicit_counts, atol=0.01) + + +def test_compute_nested_utilities(nest_spec): + # computes nested utilities manually and using the function and checks that + # the utilities are the same + + num_choosers = 2 + raw_utilities = pd.DataFrame( + {"alt1": [1, 10], "alt0.0": [2, 3], "alt0.1": [4, 5]}, + index=pd.Index(range(num_choosers)), + ) + + nested_utilities = simulate.compute_nested_utilities(raw_utilities, nest_spec) + + # these are from the definition of nest_spec + alt0_nest_coefficient = nest_spec["alternatives"][0]["coefficient"] + alt0_leaf_product_of_coefficients = nest_spec["coefficient"] * alt0_nest_coefficient + assert alt0_leaf_product_of_coefficients == 0.5 # 1 * 0.5 + + product_of_coefficientss = pd.DataFrame( + { + "alt1": [nest_spec["coefficient"]], + "alt0.0": [alt0_leaf_product_of_coefficients], + "alt0.1": [alt0_leaf_product_of_coefficients], + }, + index=[0], + ) + leaf_utilities = raw_utilities / product_of_coefficientss.iloc[0] + + constructed_nested_utilities = pd.DataFrame(index=raw_utilities.index) + + constructed_nested_utilities[leaf_utilities.columns] = leaf_utilities + constructed_nested_utilities["alt0"] = alt0_nest_coefficient * np.log( + np.exp(leaf_utilities[["alt0.0", "alt0.1"]]).sum(axis=1) + ) + constructed_nested_utilities["root"] = nest_spec["coefficient"] * np.log( + np.exp(constructed_nested_utilities[["alt1", "alt0"]]).sum(axis=1) + ) + + assert np.allclose( + nested_utilities, constructed_nested_utilities[nested_utilities.columns] + ), "Mismatch in nested utilities" + + +def test_eval_nl_logsums_eet_vs_non_eet(state, nest_spec): + """eval_nl with want_logsums=True must produce identical logsums under + EET and non-EET modes""" + + num_choosers = 100 + + np.random.seed(42) + data2 = pd.DataFrame( + {"chooser_attr": np.random.rand(num_choosers)}, + index=pd.Index(range(num_choosers), name="person_id"), + ) + + spec2 = pd.DataFrame( + {"alt1": [2.0], "alt0.0": [0.5], "alt0.1": [0.2]}, + index=pd.Index(["chooser_attr"], name="Expression"), + ) + + chunk_sizer = chunk.ChunkSizer(state, "", "", num_choosers) + + state.settings.use_explicit_error_terms = True + state.rng().set_base_seed(42) + state.rng().add_channel("person_id", data2) + state.rng().begin_step("test_step_logsums") + + result_eet = simulate.eval_nl( + state=state, + choosers=data2, + spec=spec2, + nest_spec=nest_spec, + locals_d={}, + custom_chooser=None, + estimator=None, + want_logsums=True, + trace_label="test", + chunk_sizer=chunk_sizer, + ) + + state.rng().end_step("test_step_logsums") + + state.settings.use_explicit_error_terms = False + state.rng().begin_step("test_step_logsums") + + result_non_eet = simulate.eval_nl( + state=state, + choosers=data2, + spec=spec2, + nest_spec=nest_spec, + locals_d={}, + custom_chooser=None, + estimator=None, + want_logsums=True, + trace_label="test", + chunk_sizer=chunk_sizer, + ) + + state.rng().end_step("test_step_logsums") + + # Both paths should return a DataFrame with 'choice' and 'logsum' columns + assert "logsum" in result_eet.columns, "EET result missing logsum column" + assert "logsum" in result_non_eet.columns, "non-EET result missing logsum column" + + # Logsums are deterministic — they must be identical across paths + assert np.allclose( + result_eet["logsum"].values, result_non_eet["logsum"].values, rtol=1e-10 + ) diff --git a/activitysim/examples/placeholder_multiple_zone/test/configs_eet/settings.yaml b/activitysim/examples/placeholder_multiple_zone/test/configs_eet/settings.yaml new file mode 100644 index 000000000..08c06d702 --- /dev/null +++ b/activitysim/examples/placeholder_multiple_zone/test/configs_eet/settings.yaml @@ -0,0 +1,3 @@ +inherit_settings: True + +use_explicit_error_terms: True diff --git a/activitysim/examples/placeholder_multiple_zone/test/reference_pipeline_2_zone_eet.zip b/activitysim/examples/placeholder_multiple_zone/test/reference_pipeline_2_zone_eet.zip new file mode 100644 index 000000000..8e3abdfff Binary files /dev/null and b/activitysim/examples/placeholder_multiple_zone/test/reference_pipeline_2_zone_eet.zip differ diff --git a/activitysim/examples/placeholder_multiple_zone/test/regress/final_eet_tours_2_zone.csv b/activitysim/examples/placeholder_multiple_zone/test/regress/final_eet_tours_2_zone.csv new file mode 100644 index 000000000..00aa4c0fc --- /dev/null +++ b/activitysim/examples/placeholder_multiple_zone/test/regress/final_eet_tours_2_zone.csv @@ -0,0 +1,106 @@ +"person_id","tour_type","tour_type_count","tour_type_num","tour_num","tour_count","tour_category","number_of_participants","destination","origin","household_id","tdd","start","end","duration","composition","destination_logsum","tour_mode","mode_choice_logsum","atwork_subtour_frequency","parent_tour_id","stop_frequency","primary_purpose","tour_id" +26686,"shopping",1,1,1,1,"non_mandatory",1,23000,8000,26686,113,12,13,1,"",13.652449170814883,"WALK_LRF",1.0501470508061868,"",,"0out_0in","shopping",1094159 +26844,"othmaint",1,1,2,2,"non_mandatory",1,5000,8000,26844,159,16,21,5,"",15.525049977674522,"WALK_LOC",2.760890821002089,"",,"0out_0in","othmaint",1100632 +26844,"shopping",1,1,1,2,"non_mandatory",1,1000,8000,26844,75,9,14,5,"",14.275587915746392,"TNC_SINGLE",2.305056815108128,"",,"1out_0in","shopping",1100637 +27726,"eatout",1,1,1,1,"non_mandatory",1,10000,10000,27726,140,14,19,5,"",15.203007240171102,"WALK",4.342645736471603,"",,"0out_0in","eatout",1136772 +110675,"work",1,1,1,1,"mandatory",1,16000,16000,110675,13,5,18,13,"",,"WALK",-0.2730591306116382,"no_subtours",,"0out_0in","work",4537714 +112064,"work",1,1,1,1,"mandatory",1,24000,16000,112064,131,13,20,7,"",,"WALK_LOC",5.176494664984331,"no_subtours",,"1out_1in","work",4594663 +264108,"eatout",1,1,1,1,"non_mandatory",1,8000,9000,226869,135,14,14,0,"",13.203967734929993,"WALK",1.0687903457949945,"",,"0out_0in","eatout",10828434 +323689,"work",1,1,1,1,"mandatory",1,2000,10000,256660,151,15,21,6,"",,"WALK_LRF",5.943591391097562,"no_subtours",,"1out_0in","work",13271288 +323690,"work",1,1,1,1,"mandatory",1,9000,10000,256660,117,12,17,5,"",,"WALK",5.3957995007835535,"no_subtours",,"0out_1in","work",13271329 +325431,"othdiscr",1,1,1,1,"non_mandatory",1,22000,16000,257531,102,11,14,3,"",15.268405514775877,"WALK",2.165017948111244,"",,"0out_2in","othdiscr",13342696 +325431,"work",1,1,1,1,"mandatory",1,14000,16000,257531,157,16,19,3,"",,"WALK_LOC",5.979950151025447,"no_subtours",,"0out_0in","work",13342710 +325432,"work",1,1,1,1,"mandatory",1,15000,16000,257531,45,7,15,8,"",,"WALK_LOC",5.9577256558570015,"no_subtours",,"0out_0in","work",13342751 +595684,"escort",1,1,1,1,"non_mandatory",1,5000,21000,370497,38,7,8,1,"",12.420811407080112,"SHARED3FREE",-1.0951775798823786,"",,"0out_0in","escort",24423053 +595684,"work",1,1,1,1,"mandatory",1,19000,21000,370497,167,17,22,5,"",,"SHARED2FREE",-0.14535197835485364,"no_subtours",,"3out_0in","work",24423083 +595685,"school",1,1,1,1,"mandatory",1,13000,21000,370497,61,8,15,7,"",,"WALK_LOC",-0.9348277771487143,"",,"0out_0in","school",24423116 +595686,"school",1,1,1,1,"mandatory",1,21000,21000,370497,41,7,11,4,"",,"WALK",-0.41324468118526936,"",,"0out_0in","school",24423157 +644292,"school",1,1,1,1,"mandatory",1,2000,7000,386699,9,5,14,9,"",,"WALK",18.86976579102885,"",,"0out_0in","school",26416003 +644476,"work",1,1,1,1,"mandatory",1,7000,16000,386761,47,7,17,10,"",,"WALK_LOC",5.51666670545706,"no_subtours",,"0out_0in","work",26423555 +644477,"work",1,1,1,1,"mandatory",1,4000,16000,386761,64,8,18,10,"",,"WALK_LOC",5.662108100914558,"no_subtours",,"0out_2in","work",26423596 +644478,"school",1,1,1,1,"mandatory",1,25000,16000,386761,45,7,15,8,"",,"WALK_LOC",17.88652386604347,"",,"0out_0in","school",26423629 +1267567,"eatout",1,1,1,1,"non_mandatory",1,11000,21000,570454,99,11,11,0,"",15.277431294707508,"WALK",4.004645419133042,"",,"0out_0in","eatout",51970253 +1427193,"shopping",1,1,1,1,"non_mandatory",1,16000,25000,703381,151,15,21,6,"",13.171561237606278,"BIKE",0.8981575547418779,"",,"0out_0in","shopping",58514946 +1427194,"othmaint",3,1,1,3,"non_mandatory",1,9000,25000,703381,74,9,13,4,"",14.416957607852858,"BIKE",0.6613874806788961,"",,"0out_0in","othmaint",58514982 +1427194,"othmaint",3,2,2,3,"non_mandatory",1,8000,25000,703381,156,16,18,2,"",14.365283875141941,"BIKE",0.6990093306817798,"",,"0out_0in","othmaint",58514983 +1427194,"othmaint",3,3,3,3,"non_mandatory",1,7000,25000,703381,172,18,21,3,"",14.373474385937751,"BIKE",1.1745535385516204,"",,"0out_0in","othmaint",58514984 +1572659,"othdiscr",1,1,1,1,"non_mandatory",1,7000,6000,763879,8,5,13,8,"",15.269403956266437,"WALK",3.1705302835155984,"",,"0out_0in","othdiscr",64479044 +1572930,"eatout",1,1,1,1,"non_mandatory",1,12000,9000,764150,46,7,16,9,"",15.42100489856711,"WALK",3.628422928001604,"",,"0out_0in","eatout",64490136 +1632206,"work",1,1,1,1,"mandatory",1,12000,11000,823426,48,7,18,11,"",,"WALK",-0.0229685389951619,"no_subtours",,"0out_0in","work",66920485 +1632281,"work",1,1,1,1,"mandatory",1,1000,12000,823501,64,8,18,10,"",,"WALK",-0.4832251215332097,"no_subtours",,"0out_0in","work",66923560 +1632987,"eat",1,1,1,1,"atwork",1,13000,22000,824207,100,11,12,1,"",15.37146933803088,"TNC_SINGLE",5.527382364048134,"",66952506,"0out_0in","atwork",66952471 +1632987,"work",1,1,1,1,"mandatory",1,22000,18000,824207,50,7,20,13,"",,"WALK_LRF",5.930592339624059,"eat",,"0out_0in","work",66952506 +1875721,"work",1,1,1,1,"mandatory",1,4000,16000,982875,49,7,19,12,"",,"SHARED3FREE",1.731505679041429,"no_subtours",,"0out_0in","work",76904600 +1875722,"work",1,1,1,1,"mandatory",1,7000,16000,982875,48,7,18,11,"",,"WALK",1.5259948396881422,"no_subtours",,"0out_0in","work",76904641 +2159057,"work",1,1,1,1,"mandatory",1,11000,20000,1099626,47,7,17,10,"",,"BIKE",0.08239658913473709,"no_subtours",,"0out_0in","work",88521376 +2159058,"school",1,1,1,1,"mandatory",1,12000,20000,1099626,44,7,14,7,"",,"WALK_LOC",-0.08092637357224697,"",,"0out_0in","univ",88521409 +2159059,"school",1,1,1,1,"mandatory",1,17000,20000,1099626,61,8,15,7,"",,"SHARED2FREE",-0.5795062930092348,"",,"0out_0in","school",88521450 +2458500,"othdiscr",1,1,1,1,"non_mandatory",1,2000,8000,1173905,126,13,15,2,"",15.003025752404032,"TNC_SINGLE",2.1345972053076645,"",,"0out_0in","othdiscr",100798525 +2458502,"school",1,1,1,1,"mandatory",1,9000,8000,1173905,76,9,15,6,"",,"WALK_LOC",19.061076416939844,"",,"0out_0in","school",100798613 +2458503,"school",1,1,1,1,"mandatory",1,25000,8000,1173905,63,8,17,9,"",,"WALK",17.394445009270893,"",,"0out_0in","school",100798654 +2566698,"othmaint",1,1,1,1,"non_mandatory",1,12000,25000,1196298,146,15,16,1,"",13.904676146693486,"WALK",-0.08705033093047729,"",,"0out_0in","othmaint",105234646 +2566698,"work",1,1,1,1,"mandatory",1,9000,25000,1196298,42,7,12,5,"",,"SHARED3FREE",-0.12492841393683855,"no_subtours",,"1out_2in","work",105234657 +2566699,"escort",2,1,1,4,"non_mandatory",1,9000,25000,1196298,55,8,9,1,"",12.487156714808382,"SHARED3FREE",-1.224321337819968,"",,"0out_0in","escort",105234668 +2566699,"escort",2,2,2,4,"non_mandatory",1,2000,25000,1196298,112,12,12,0,"",12.473008939270755,"SHARED2FREE",-0.5133849848564047,"",,"0out_0in","escort",105234669 +2566699,"othdiscr",1,1,4,4,"non_mandatory",1,5000,25000,1196298,172,18,21,3,"",13.96308058011918,"WALK",0.6917454521182999,"",,"0out_0in","othdiscr",105234684 +2566699,"shopping",1,1,3,4,"non_mandatory",1,17000,25000,1196298,71,9,10,1,"",12.746190439180568,"TNC_SINGLE",-0.323622964459322,"",,"0out_0in","shopping",105234692 +2566700,"school",1,1,1,1,"mandatory",1,19000,25000,1196298,61,8,15,7,"",,"BIKE",-1.7110584511799807,"",,"0out_0in","school",105234731 +2566701,"escort",1,1,1,1,"non_mandatory",1,13000,25000,1196298,124,13,13,0,"",12.587432709712925,"SHARED2FREE",0.06051195773469012,"",,"0out_0in","escort",105234750 +2566701,"school",1,1,1,1,"mandatory",1,11000,25000,1196298,43,7,13,6,"",,"SHARED2FREE",-1.0766765571584742,"",,"0out_0in","school",105234772 +2566702,"othdiscr",1,1,1,1,"non_mandatory",1,9000,25000,1196298,171,18,20,2,"",14.120222605326392,"SHARED2FREE",0.3431222104372727,"",,"0out_2in","othdiscr",105234807 +2936848,"eatout",1,1,3,3,"non_mandatory",1,22000,11000,1286557,128,13,17,4,"",15.413580157739286,"WALK",3.337722927621502,"",,"0out_0in","eatout",120410774 +2936848,"othmaint",1,1,2,3,"non_mandatory",1,5000,11000,1286557,59,8,13,5,"",14.936437315067716,"WALK_LOC",1.9387725623593302,"",,"2out_1in","othmaint",120410796 +2936848,"shopping",1,1,1,3,"non_mandatory",1,11000,11000,1286557,170,18,19,1,"",13.737502885247409,"WALK",1.7463445938625892,"",,"0out_2in","shopping",120410801 +3061894,"othmaint",1,1,2,2,"non_mandatory",1,5000,24000,1363467,63,8,17,9,"",15.189637319752025,"WALK_LOC",2.2612689227267926,"",,"0out_0in","othmaint",125537682 +3061894,"shopping",1,1,1,2,"non_mandatory",1,5000,24000,1363467,54,8,8,0,"",13.926378681444465,"TNC_SINGLE",2.195783573785629,"",,"1out_1in","shopping",125537687 +3061895,"othmaint",1,1,2,2,"non_mandatory",1,22000,24000,1363467,180,20,20,0,"",15.281994100444798,"WALK_LOC",2.3241680009556887,"",,"0out_0in","othmaint",125537723 +3061895,"shopping",1,1,1,2,"non_mandatory",1,4000,24000,1363467,66,8,20,12,"",13.894949372888025,"TNC_SINGLE",2.349852517486852,"",,"1out_0in","shopping",125537728 +3188483,"othmaint",1,1,2,2,"non_mandatory",1,3000,25000,1402945,112,12,12,0,"",14.231882110325735,"WALK",1.3527690062199011,"",,"0out_0in","othmaint",130727831 +3188483,"shopping",1,1,1,2,"non_mandatory",1,14000,25000,1402945,136,14,15,1,"",13.406265391553307,"BIKE",0.9749240595315471,"",,"0out_0in","shopping",130727836 +3188484,"work",1,1,1,1,"mandatory",1,21000,25000,1402945,147,15,17,2,"",,"SHARED2FREE",1.5045736701182255,"no_subtours",,"0out_0in","work",130727883 +3188485,"work",1,1,1,1,"mandatory",1,5000,25000,1402945,64,8,18,10,"",,"WALK",2.034000565768078,"no_subtours",,"0out_0in","work",130727924 +3232955,"escort",1,1,1,1,"non_mandatory",1,7000,14000,1444715,164,17,19,2,"",12.435690330338216,"WALK",-2.0590794826886896,"",,"0out_0in","escort",132551164 +3232955,"work",2,1,1,2,"mandatory",1,22000,14000,1444715,24,6,11,5,"",,"WALK",-0.40159974247061203,"no_subtours",,"0out_0in","work",132551194 +3232955,"work",2,2,2,2,"mandatory",1,22000,14000,1444715,127,13,16,3,"",,"WALK_LOC",-0.20548633109849337,"no_subtours",,"0out_0in","work",132551195 +3233462,"eat",1,1,1,1,"atwork",1,5000,19000,1445222,70,9,9,0,"",19.63149392560022,"SHARED3FREE",-0.34159841664366153,"",132571981,"0out_1in","atwork",132571946 +3233462,"work",1,1,1,1,"mandatory",1,19000,17000,1445222,81,9,20,11,"",,"DRIVEALONEFREE",0.16481970561443188,"eat",,"0out_3in","work",132571981 +3328568,"work",1,1,1,1,"mandatory",1,22000,8000,1511234,46,7,16,9,"",,"WALK_LRF",6.0835517322893065,"no_subtours",,"0out_0in","work",136471327 +3328569,"school",1,1,1,1,"mandatory",1,9000,8000,1511234,62,8,16,8,"",,"WALK_LOC",7.510086352530541,"",,"0out_0in","univ",136471360 +3495342,"eat",1,1,1,1,"atwork",1,9000,11000,1594621,85,10,10,0,"",15.668488627428035,"WALK",5.895907678328029,"",143309061,"3out_0in","atwork",143309026 +3495342,"work",1,1,1,1,"mandatory",1,11000,10000,1594621,63,8,17,9,"",,"TNC_SINGLE",6.106308966698332,"eat",,"0out_0in","work",143309061 +3495343,"shopping",1,1,1,1,"non_mandatory",1,21000,10000,1594621,146,15,16,1,"",14.147994174455755,"TAXI",2.140539157970799,"",,"1out_1in","shopping",143309096 +3596364,"school",1,1,1,1,"mandatory",1,9000,9000,1645132,99,11,11,0,"",,"WALK",0.9922761728862803,"",,"0out_0in","univ",147450955 +3596364,"shopping",1,1,1,1,"non_mandatory",1,2000,9000,1645132,130,13,19,6,"",12.702108843408501,"WALK_LRF",-0.6357173968922101,"",,"0out_0in","shopping",147450957 +3596365,"school",1,1,1,1,"mandatory",1,9000,9000,1645132,92,10,17,7,"",,"WALK",0.13078470986223545,"",,"0out_2in","school",147450996 +3891102,"eat",1,1,1,1,"atwork",1,4000,1000,1747467,88,10,13,3,"",12.863034889266403,"WALK",0.48410709631297644,"",159535221,"0out_1in","atwork",159535186 +3891102,"work",1,1,1,1,"mandatory",1,1000,16000,1747467,67,8,21,13,"",,"WALK_LOC",1.7047589669241154,"eat",,"1out_1in","work",159535221 +3891104,"othdiscr",1,1,1,1,"non_mandatory",1,17000,16000,1747467,52,7,22,15,"",14.783602512881732,"WALK",1.8681070245632654,"",,"0out_0in","othdiscr",159535289 +4171615,"school",1,1,1,1,"mandatory",1,13000,16000,1810015,169,18,18,0,"",,"TAXI",3.339440236713284,"",,"0out_0in","univ",171036246 +4171616,"shopping",1,1,1,1,"non_mandatory",1,14000,16000,1810015,89,10,14,4,"",13.351914976059247,"WALK",1.2336467654702536,"",,"0out_0in","shopping",171036289 +4171617,"eat",1,1,1,1,"atwork",1,5000,11000,1810015,85,10,10,0,"",12.806283314422718,"WALK",0.1414193868413481,"",171036336,"0out_1in","atwork",171036301 +4171617,"work",1,1,1,1,"mandatory",1,11000,16000,1810015,62,8,16,8,"",,"WALK",1.2491275426711392,"eat",,"0out_0in","work",171036336 +4171619,"othdiscr",1,1,1,1,"non_mandatory",1,16000,16000,1810015,80,9,19,10,"",14.427951929207534,"WALK",1.7126466601147134,"",,"0out_0in","othdiscr",171036404 +4171622,"othmaint",1,1,1,1,"non_mandatory",1,2000,16000,1810015,100,11,12,1,"",14.02155021495475,"TNC_SINGLE",0.47701959308489095,"",,"0out_0in","othmaint",171036530 +4823797,"work",1,1,1,1,"mandatory",1,2000,14000,1952792,93,10,18,8,"",,"WALK",5.550859155970048,"no_subtours",,"0out_0in","work",197775716 +5057160,"work",1,1,1,1,"mandatory",1,5000,5000,2048204,30,6,17,11,"",,"BIKE",-0.09630302951387847,"no_subtours",,"0out_0in","work",207343599 +5057338,"work",1,1,1,1,"mandatory",1,17000,7000,2048382,50,7,20,13,"",,"WALK_LOC",5.537496365437239,"no_subtours",,"0out_0in","work",207350897 +5387762,"work",1,1,1,1,"mandatory",1,10000,9000,2223027,28,6,15,9,"",,"WALK",1.9810584290306386,"no_subtours",,"0out_0in","work",220898281 +5387763,"eatout",1,1,2,2,"non_mandatory",1,10000,9000,2223027,154,16,16,0,"",14.015959650256292,"WALK",2.3358373327911104,"",,"0out_0in","eatout",220898289 +5387763,"othdiscr",1,1,1,2,"non_mandatory",1,15000,9000,2223027,169,18,18,0,"",14.599617247497788,"WALK_LRF",1.465646852694868,"",,"0out_0in","othdiscr",220898308 +5389226,"work",1,1,1,1,"mandatory",1,14000,16000,2223759,63,8,17,9,"",,"WALK",1.8883570091287778,"no_subtours",,"0out_0in","work",220958305 +5389227,"eat",1,1,1,1,"atwork",1,16000,16000,2223759,99,11,11,0,"",12.858228927386488,"WALK",0.6660642166270728,"",220958346,"0out_0in","atwork",220958311 +5389227,"escort",1,1,1,1,"non_mandatory",1,5000,16000,2223759,162,17,17,0,"",12.681412371417782,"WALK",-0.2552610926701476,"",,"0out_0in","escort",220958316 +5389227,"work",1,1,1,1,"mandatory",1,16000,16000,2223759,28,6,15,9,"",,"WALK",2.079861874799809,"eat",,"0out_0in","work",220958346 +7305540,"social",2,1,1,2,"non_mandatory",1,21000,20000,2727273,37,7,7,0,"",14.1996409773108,"WALK",1.8494027479889232,"",,"0out_0in","social",299527176 +7305540,"social",2,2,2,2,"non_mandatory",1,9000,20000,2727273,86,10,11,1,"",14.120642597671408,"WALK",1.9956840012673436,"",,"0out_1in","social",299527177 +7305540,"work",1,1,1,1,"mandatory",1,24000,20000,2727273,127,13,16,3,"",,"BIKE",0.9398542864235182,"no_subtours",,"0out_0in","work",299527179 +7305541,"shopping",1,1,1,2,"non_mandatory",1,16000,20000,2727273,171,18,20,2,"",13.28794064279901,"WALK_LOC",0.9142001643337417,"",,"0out_0in","shopping",299527214 +7305541,"social",1,1,2,2,"non_mandatory",1,21000,20000,2727273,162,17,17,0,"",14.151071365958824,"WALK_LOC",1.8493576999144647,"",,"0out_0in","social",299527217 +7305541,"work",1,1,1,1,"mandatory",1,4000,20000,2727273,45,7,15,8,"",,"WALK_LRF",1.6475450149587834,"no_subtours",,"0out_0in","work",299527220 +7453413,"othmaint",1,1,1,1,"non_mandatory",1,8000,20000,2762078,102,11,14,3,"",14.985169483093204,"WALK_LOC",2.1409730693117166,"",,"0out_0in","othmaint",305589961 +7511873,"work",1,1,1,1,"mandatory",1,1000,8000,2820538,45,7,15,8,"",,"WALK_LOC",-0.8702887383817772,"no_subtours",,"0out_0in","work",307986832 +7512109,"work",1,1,1,1,"mandatory",1,14000,8000,2820774,48,7,18,11,"",,"WALK_LOC",4.688080695799631,"no_subtours",,"0out_0in","work",307996508 +7512514,"work",1,1,1,1,"mandatory",1,9000,8000,2821179,172,18,21,3,"",,"WALK",5.16970893935428,"no_subtours",,"0out_0in","work",308013113 +7513432,"social",1,1,1,1,"non_mandatory",1,11000,8000,2822097,77,9,16,7,"",14.426345007668951,"WALK_LOC",1.828284029776891,"",,"0out_1in","social",308050748 +7513554,"work",1,1,1,1,"mandatory",1,9000,8000,2822219,96,10,21,11,"",,"TNC_SINGLE",5.634094342054246,"no_subtours",,"1out_0in","work",308055753 +7523517,"shopping",1,1,1,1,"non_mandatory",1,13000,7000,2832182,145,15,15,0,"",13.532091345687146,"WALK_LOC",1.2623216832302828,"",,"0out_0in","shopping",308464230 diff --git a/activitysim/examples/placeholder_multiple_zone/test/regress/final_eet_trips_2_zone.csv b/activitysim/examples/placeholder_multiple_zone/test/regress/final_eet_trips_2_zone.csv new file mode 100644 index 000000000..bd9250049 --- /dev/null +++ b/activitysim/examples/placeholder_multiple_zone/test/regress/final_eet_trips_2_zone.csv @@ -0,0 +1,254 @@ +"person_id","household_id","primary_purpose","trip_num","outbound","trip_count","destination","origin","tour_id","purpose","destination_logsum","depart","trip_mode","mode_choice_logsum","trip_id" +26686,26686,"shopping",1,true,1,23000,8000,1094159,"shopping",,12,"WALK_LOC",1.9827280669801086,8753273 +26686,26686,"shopping",1,false,1,8000,23000,1094159,"home",,13,"WALK",1.9037282242699007,8753277 +26844,26844,"othmaint",1,true,1,5000,8000,1100632,"othmaint",,16,"WALK",3.9354602248477737,8805057 +26844,26844,"othmaint",1,false,1,8000,5000,1100632,"home",,21,"WALK",3.9189147972940885,8805061 +26844,26844,"shopping",1,true,2,9000,8000,1100637,"shopping",31.37877712789407,9,"WALK_LOC",10.984274105698468,8805097 +26844,26844,"shopping",2,true,2,1000,9000,1100637,"shopping",,9,"TNC_SINGLE",1.1046643197551034,8805098 +26844,26844,"shopping",1,false,1,8000,1000,1100637,"home",,14,"TNC_SINGLE",0.9942441548836948,8805101 +27726,27726,"eatout",1,true,1,10000,10000,1136772,"eatout",,14,"WALK",10.041713156072243,9094177 +27726,27726,"eatout",1,false,1,10000,10000,1136772,"home",,19,"WALK",10.041713156072243,9094181 +110675,110675,"work",1,true,1,16000,16000,4537714,"work",,5,"WALK",5.450623197234638,36301713 +110675,110675,"work",1,false,1,16000,16000,4537714,"home",,18,"WALK",5.450623197234638,36301717 +112064,112064,"work",1,true,2,25000,16000,4594663,"work",35.8782468879873,13,"WALK_LOC",10.001126639886184,36757305 +112064,112064,"work",2,true,2,24000,25000,4594663,"work",,13,"WALK_LOC",2.809733442795069,36757306 +112064,112064,"work",1,false,2,7000,24000,4594663,"social",34.01849775944516,20,"WALK",2.147976347182729,36757309 +112064,112064,"work",2,false,2,16000,7000,4594663,"home",,20,"WALK_LOC",10.657184142644127,36757310 +264108,226869,"eatout",1,true,1,8000,9000,10828434,"eatout",,14,"WALK",12.045414087419827,86627473 +264108,226869,"eatout",1,false,1,9000,8000,10828434,"home",,14,"WALK",12.045414087420168,86627477 +323689,256660,"work",1,true,2,7000,10000,13271288,"work",32.636430904267925,15,"WALK",10.992779238372787,106170305 +323689,256660,"work",2,true,2,2000,7000,13271288,"work",,16,"WALK",0.07082651725982507,106170306 +323689,256660,"work",1,false,1,10000,2000,13271288,"home",,21,"WALK_LRF",0.4297270030393883,106170309 +323690,256660,"work",1,true,1,9000,10000,13271329,"work",,12,"WALK",8.030042498532831,106170633 +323690,256660,"work",1,false,2,9000,9000,13271329,"escort",41.699169508847675,16,"WALK",8.311642517531904,106170637 +323690,256660,"work",2,false,2,10000,9000,13271329,"home",,17,"WALK",8.170842512701038,106170638 +325431,257531,"othdiscr",1,true,1,22000,16000,13342696,"othdiscr",,11,"WALK",0.8780862049084773,106741569 +325431,257531,"othdiscr",1,false,3,8000,22000,13342696,"social",31.597406256890405,14,"WALK",-0.20976456497029897,106741573 +325431,257531,"othdiscr",2,false,3,7000,8000,13342696,"escort",55.615835217285294,14,"WALK",12.357894047797622,106741574 +325431,257531,"othdiscr",3,false,3,16000,7000,13342696,"home",,14,"WALK",12.573466152605935,106741575 +325431,257531,"work",1,true,1,14000,16000,13342710,"work",,16,"WALK_LOC",1.566089725814676,106741681 +325431,257531,"work",1,false,1,16000,14000,13342710,"home",,19,"WALK",1.5222029212145018,106741685 +325432,257531,"work",1,true,1,15000,16000,13342751,"work",,7,"WALK_LOC",1.5021356653376314,106742009 +325432,257531,"work",1,false,1,16000,15000,13342751,"home",,15,"WALK",1.4521916317367,106742013 +595684,370497,"escort",1,true,1,5000,21000,24423053,"escort",,7,"WALK",3.330906385141443,195384425 +595684,370497,"escort",1,false,1,21000,5000,24423053,"home",,8,"WALK",3.406854952912418,195384429 +595684,370497,"work",1,true,4,8000,21000,24423083,"shopping",26.255350098408414,17,"WALK",9.135886955872488,195384665 +595684,370497,"work",2,true,4,9000,8000,24423083,"work",28.05855070184786,18,"WALK",8.121041430209859,195384666 +595684,370497,"work",3,true,4,7000,9000,24423083,"work",31.847339393333378,18,"WALK",10.660973323175552,195384667 +595684,370497,"work",4,true,4,19000,7000,24423083,"work",,19,"WALK",-0.2788507765426208,195384668 +595684,370497,"work",1,false,1,21000,19000,24423083,"home",,22,"SHARED2FREE",-0.1573937557477881,195384669 +595685,370497,"school",1,true,1,13000,21000,24423116,"school",,8,"WALK",-0.8229268584487489,195384929 +595685,370497,"school",1,false,1,21000,13000,24423116,"home",,15,"WALK_LOC",-1.1046192102021704,195384933 +595686,370497,"school",1,true,1,21000,21000,24423157,"school",,7,"WALK",3.8962741508493144,195385257 +595686,370497,"school",1,false,1,21000,21000,24423157,"home",,11,"WALK",3.8962741508493144,195385261 +644292,386699,"school",1,true,1,2000,7000,26416003,"school",,5,"WALK",-0.7452680126547789,211328025 +644292,386699,"school",1,false,1,7000,2000,26416003,"home",,14,"WALK",-0.6585530704989658,211328029 +644476,386761,"work",1,true,1,7000,16000,26423555,"work",,7,"WALK_LOC",10.956012027742537,211388441 +644476,386761,"work",1,false,1,16000,7000,26423555,"home",,17,"WALK_LOC",10.843966812429903,211388445 +644477,386761,"work",1,true,1,4000,16000,26423596,"work",,8,"WALK",0.5554280270852756,211388769 +644477,386761,"work",1,false,3,8000,4000,26423596,"othdiscr",29.4847474381881,8,"WALK_LOC",0.39972663182606294,211388773 +644477,386761,"work",2,false,3,7000,8000,26423596,"shopping",47.722440883077674,18,"WALK_LOC",10.251476771714287,211388774 +644477,386761,"work",3,false,3,16000,7000,26423596,"home",,18,"WALK",10.843966918146847,211388775 +644478,386761,"school",1,true,1,25000,16000,26423629,"school",,7,"WALK_LOC",11.66210546356803,211389033 +644478,386761,"school",1,false,1,16000,25000,26423629,"home",,15,"WALK_LOC",11.638857607037355,211389037 +1267567,570454,"eatout",1,true,1,11000,21000,51970253,"eatout",,11,"WALK",4.940793809090325,415762025 +1267567,570454,"eatout",1,false,1,21000,11000,51970253,"home",,11,"WALK",4.9407938105296125,415762029 +1427193,703381,"shopping",1,true,1,16000,25000,58514946,"shopping",,15,"BIKE",6.640136269009802,468119569 +1427193,703381,"shopping",1,false,1,25000,16000,58514946,"home",,21,"BIKE",6.575179313692486,468119573 +1427194,703381,"othmaint",1,true,1,9000,25000,58514982,"othmaint",,9,"BIKE",6.353308735567675,468119857 +1427194,703381,"othmaint",1,false,1,25000,9000,58514982,"home",,13,"BIKE",6.3384404915582335,468119861 +1427194,703381,"othmaint",1,true,1,8000,25000,58514983,"othmaint",,16,"WALK",7.518240674377766,468119865 +1427194,703381,"othmaint",1,false,1,25000,8000,58514983,"home",,18,"BIKE",7.524697959231204,468119869 +1427194,703381,"othmaint",1,true,1,7000,25000,58514984,"othmaint",,18,"WALK",8.966945568005901,468119873 +1427194,703381,"othmaint",1,false,1,25000,7000,58514984,"home",,21,"BIKE",8.89909382789557,468119877 +1572659,763879,"othdiscr",1,true,1,7000,6000,64479044,"othdiscr",,5,"WALK",14.202826252443442,515832353 +1572659,763879,"othdiscr",1,false,1,6000,7000,64479044,"home",,13,"WALK",14.258626224164276,515832357 +1572930,764150,"eatout",1,true,1,12000,9000,64490136,"eatout",,7,"WALK",3.8127908930347663,515921089 +1572930,764150,"eatout",1,false,1,9000,12000,64490136,"home",,16,"WALK",3.7569912975474886,515921093 +1632206,823426,"work",1,true,1,12000,11000,66920485,"work",,7,"WALK",3.428915566265564,535363881 +1632206,823426,"work",1,false,1,11000,12000,66920485,"home",,18,"WALK",3.428915026154219,535363885 +1632281,823501,"work",1,true,1,1000,12000,66923560,"work",,8,"WALK",-1.1863064685276732,535388481 +1632281,823501,"work",1,false,1,12000,1000,66923560,"home",,18,"WALK",-1.2019248842710846,535388485 +1632987,824207,"atwork",1,true,1,13000,22000,66952471,"atwork",,11,"TNC_SINGLE",1.1982264470387332,535619769 +1632987,824207,"atwork",1,false,1,22000,13000,66952471,"work",,12,"WALK_LOC",1.1895157253486617,535619773 +1632987,824207,"work",1,true,1,22000,18000,66952506,"work",,7,"WALK_LRF",1.6456092779546538,535620049 +1632987,824207,"work",1,false,1,18000,22000,66952506,"home",,20,"WALK_LRF",1.7361065950351384,535620053 +1875721,982875,"work",1,true,1,4000,16000,76904600,"work",,7,"DRIVEALONEFREE",0.7076921143748968,615236801 +1875721,982875,"work",1,false,1,16000,4000,76904600,"home",,19,"WALK",-0.14334258561745436,615236805 +1875722,982875,"work",1,true,1,7000,16000,76904641,"work",,7,"WALK",9.804561421193789,615237129 +1875722,982875,"work",1,false,1,16000,7000,76904641,"home",,18,"WALK",9.584561383233053,615237133 +2159057,1099626,"work",1,true,1,11000,20000,88521376,"work",,7,"BIKE",3.40833863532139,708171009 +2159057,1099626,"work",1,false,1,20000,11000,88521376,"home",,17,"BIKE",3.370476902119967,708171013 +2159058,1099626,"univ",1,true,1,12000,20000,88521409,"univ",,7,"WALK_LOC",4.673210978795487,708171273 +2159058,1099626,"univ",1,false,1,20000,12000,88521409,"home",,14,"WALK_LOC",4.633766064553818,708171277 +2159059,1099626,"school",1,true,1,17000,20000,88521450,"school",,8,"WALK",2.5208933659011428,708171601 +2159059,1099626,"school",1,false,1,20000,17000,88521450,"home",,15,"WALK",2.4894161638956325,708171605 +2458500,1173905,"othdiscr",1,true,1,2000,8000,100798525,"othdiscr",,13,"WALK_LOC",-0.5086365848499728,806388201 +2458500,1173905,"othdiscr",1,false,1,8000,2000,100798525,"home",,15,"WALK_LOC",-0.5202541824471008,806388205 +2458502,1173905,"school",1,true,1,9000,8000,100798613,"school",,9,"WALK_LOC",9.584957165143996,806388905 +2458502,1173905,"school",1,false,1,8000,9000,100798613,"home",,15,"WALK",9.584141345328328,806388909 +2458503,1173905,"school",1,true,1,25000,8000,100798654,"school",,8,"WALK",11.502135863745265,806389233 +2458503,1173905,"school",1,false,1,8000,25000,100798654,"home",,17,"WALK",11.47503591488948,806389237 +2566698,1196298,"othmaint",1,true,1,12000,25000,105234646,"othmaint",,15,"WALK",2.7170806557365403,841877169 +2566698,1196298,"othmaint",1,false,1,25000,12000,105234646,"home",,16,"WALK",2.668082316887066,841877173 +2566698,1196298,"work",1,true,2,7000,25000,105234657,"work",46.368886774827516,7,"WALK",10.628886549023708,841877257 +2566698,1196298,"work",2,true,2,9000,7000,105234657,"work",,8,"WALK",7.921845595405086,841877258 +2566698,1196298,"work",1,false,3,7000,9000,105234657,"work",46.219913256688756,11,"WALK",8.04493677276671,841877261 +2566698,1196298,"work",2,false,3,7000,7000,105234657,"eatout",50.18591828103494,12,"WALK",11.253671604257528,841877262 +2566698,1196298,"work",3,false,3,25000,7000,105234657,"home",,12,"WALK",10.4836804085622,841877263 +2566699,1196298,"escort",1,true,1,9000,25000,105234668,"escort",,8,"WALK",7.464032001764529,841877345 +2566699,1196298,"escort",1,false,1,25000,9000,105234668,"home",,9,"WALK",7.380265288148372,841877349 +2566699,1196298,"escort",1,true,1,2000,25000,105234669,"escort",,12,"WALK",0.42979489937273185,841877353 +2566699,1196298,"escort",1,false,1,25000,2000,105234669,"home",,12,"DRIVEALONEFREE",0.39426362374490925,841877357 +2566699,1196298,"othdiscr",1,true,1,5000,25000,105234684,"othdiscr",,18,"WALK",4.44638450975239,841877473 +2566699,1196298,"othdiscr",1,false,1,25000,5000,105234684,"home",,21,"WALK",4.078106936734674,841877477 +2566699,1196298,"shopping",1,true,1,17000,25000,105234692,"shopping",,9,"WALK_LRF",5.427479653195204,841877537 +2566699,1196298,"shopping",1,false,1,25000,17000,105234692,"home",,10,"WALK_LOC",5.657997593724093,841877541 +2566700,1196298,"school",1,true,1,19000,25000,105234731,"school",,8,"BIKE",-1.581700286838991,841877849 +2566700,1196298,"school",1,false,1,25000,19000,105234731,"home",,15,"BIKE",-1.6089370260217823,841877853 +2566701,1196298,"escort",1,true,1,13000,25000,105234750,"escort",,13,"SHARED2FREE",-0.03166986394959175,841878001 +2566701,1196298,"escort",1,false,1,25000,13000,105234750,"home",,13,"SHARED2FREE",-0.05985983186201032,841878005 +2566701,1196298,"school",1,true,1,11000,25000,105234772,"school",,7,"WALK",2.362709080528027,841878177 +2566701,1196298,"school",1,false,1,25000,11000,105234772,"home",,13,"WALK",2.1942892427799245,841878181 +2566702,1196298,"othdiscr",1,true,1,9000,25000,105234807,"othdiscr",,18,"WALK",8.443967865601556,841878457 +2566702,1196298,"othdiscr",1,false,3,8000,9000,105234807,"othdiscr",50.54253049075866,20,"WALK",10.530636255741943,841878461 +2566702,1196298,"othdiscr",2,false,3,7000,8000,105234807,"escort",57.021060151258915,20,"WALK",12.331097986979803,841878462 +2566702,1196298,"othdiscr",3,false,3,25000,7000,105234807,"home",,20,"WALK",13.411567550566136,841878463 +2936848,1286557,"eatout",1,true,1,22000,11000,120410774,"eatout",,13,"WALK",-0.37744649738261987,963286193 +2936848,1286557,"eatout",1,false,1,11000,22000,120410774,"home",,17,"WALK",-0.12636613590700893,963286197 +2936848,1286557,"othmaint",1,true,3,25000,11000,120410796,"othmaint",33.53386230240779,8,"WALK_LOC",8.71506906881393,963286369 +2936848,1286557,"othmaint",2,true,3,7000,25000,120410796,"othmaint",35.15663604383877,9,"WALK_LOC",9.599397367555662,963286370 +2936848,1286557,"othmaint",3,true,3,5000,7000,120410796,"othmaint",,9,"WALK",3.8856993443502486,963286371 +2936848,1286557,"othmaint",1,false,2,8000,5000,120410796,"shopping",32.12692001802512,13,"WALK_LOC",3.8136019897435065,963286373 +2936848,1286557,"othmaint",2,false,2,11000,8000,120410796,"home",,13,"WALK",8.624638911562878,963286374 +2936848,1286557,"shopping",1,true,1,11000,11000,120410801,"shopping",,18,"WALK",5.186311186707391,963286409 +2936848,1286557,"shopping",1,false,3,7000,11000,120410801,"othdiscr",44.33949605364542,18,"WALK",4.706431251058834,963286413 +2936848,1286557,"shopping",2,false,3,7000,7000,120410801,"escort",61.6886580104208,19,"WALK",14.414866203326692,963286414 +2936848,1286557,"shopping",3,false,3,11000,7000,120410801,"home",,19,"WALK",13.856866219908829,963286415 +3061894,1363467,"othmaint",1,true,1,5000,24000,125537682,"othmaint",,8,"WALK_LOC",3.73725010300736,1004301457 +3061894,1363467,"othmaint",1,false,1,24000,5000,125537682,"home",,17,"WALK",3.7305842343863196,1004301461 +3061894,1363467,"shopping",1,true,2,7000,24000,125537687,"othmaint",43.73819861241678,8,"WALK_LOC",13.495011906378089,1004301497 +3061894,1363467,"shopping",2,true,2,5000,7000,125537687,"shopping",,8,"WALK_LOC",4.355163009411816,1004301498 +3061894,1363467,"shopping",1,false,2,9000,5000,125537687,"eatout",42.95816610580615,8,"WALK_LOC",4.348166044302983,1004301501 +3061894,1363467,"shopping",2,false,2,24000,9000,125537687,"home",,8,"WALK_HVY",10.804085780654413,1004301502 +3061895,1363467,"othmaint",1,true,1,22000,24000,125537723,"othmaint",,20,"WALK",2.1198382474364728,1004301785 +3061895,1363467,"othmaint",1,false,1,24000,22000,125537723,"home",,20,"WALK",2.2450248366859453,1004301789 +3061895,1363467,"shopping",1,true,2,25000,24000,125537728,"shopping",35.38452370877508,8,"WALK_LOC",12.887343785241573,1004301825 +3061895,1363467,"shopping",2,true,2,4000,25000,125537728,"shopping",,11,"WALK_LOC",0.8165311300377738,1004301826 +3061895,1363467,"shopping",1,false,1,24000,4000,125537728,"home",,20,"WALK_LOC",0.8266547678720484,1004301829 +3188483,1402945,"othmaint",1,true,1,3000,25000,130727831,"othmaint",,12,"WALK",6.049470656726249,1045822649 +3188483,1402945,"othmaint",1,false,1,25000,3000,130727831,"home",,12,"WALK",6.009290681658803,1045822653 +3188483,1402945,"shopping",1,true,1,14000,25000,130727836,"shopping",,14,"BIKE",0.6559860145760328,1045822689 +3188483,1402945,"shopping",1,false,1,25000,14000,130727836,"home",,15,"BIKE",0.5716281146927128,1045822693 +3188484,1402945,"work",1,true,1,21000,25000,130727883,"work",,15,"DRIVEALONEFREE",2.2611057836224124,1045823065 +3188484,1402945,"work",1,false,1,25000,21000,130727883,"home",,17,"WALK",1.79496008180406,1045823069 +3188485,1402945,"work",1,true,1,5000,25000,130727924,"work",,8,"WALK",3.176125996500932,1045823393 +3188485,1402945,"work",1,false,1,25000,5000,130727924,"home",,18,"WALK",2.885731258806822,1045823397 +3232955,1444715,"escort",1,true,1,7000,14000,132551164,"escort",,17,"WALK",13.438366259007205,1060409313 +3232955,1444715,"escort",1,false,1,14000,7000,132551164,"home",,19,"WALK",13.187266160073705,1060409317 +3232955,1444715,"work",1,true,1,22000,14000,132551194,"work",,6,"WALK",0.5603936172504794,1060409553 +3232955,1444715,"work",1,false,1,14000,22000,132551194,"home",,11,"WALK",0.8331864635175756,1060409557 +3232955,1444715,"work",1,true,1,22000,14000,132551195,"work",,13,"WALK",1.649789344008908,1060409561 +3232955,1444715,"work",1,false,1,14000,22000,132551195,"home",,16,"WALK_LOC",1.802140999072509,1060409565 +3233462,1445222,"atwork",1,true,1,5000,19000,132571946,"atwork",,9,"WALK",3.555384833111897,1060575569 +3233462,1445222,"atwork",1,false,2,10000,5000,132571946,"work",40.81104535324782,9,"WALK",5.09581492505858,1060575573 +3233462,1445222,"atwork",2,false,2,19000,10000,132571946,"work",,9,"WALK",10.432166529592788,1060575574 +3233462,1445222,"work",1,true,1,19000,17000,132571981,"work",,9,"DRIVEALONEFREE",-0.12604572730314542,1060575849 +3233462,1445222,"work",1,false,4,7000,19000,132571981,"work",26.29280923831885,17,"DRIVEALONEFREE",-0.7072010889663861,1060575853 +3233462,1445222,"work",2,false,4,6000,7000,132571981,"othmaint",42.469375553808376,17,"WALK",10.073578746267579,1060575854 +3233462,1445222,"work",3,false,4,7000,6000,132571981,"escort",40.40244821152917,17,"WALK",8.854601045166811,1060575855 +3233462,1445222,"work",4,false,4,17000,7000,132571981,"home",,20,"WALK",8.238896211056357,1060575856 +3328568,1511234,"work",1,true,1,22000,8000,136471327,"work",,7,"WALK_LRF",2.0129407133763646,1091770617 +3328568,1511234,"work",1,false,1,8000,22000,136471327,"home",,16,"WALK_LRF",2.013498720638361,1091770621 +3328569,1511234,"univ",1,true,1,9000,8000,136471360,"univ",,8,"WALK_LOC",10.078747551647542,1091770881 +3328569,1511234,"univ",1,false,1,8000,9000,136471360,"home",,16,"WALK_LOC",10.077775953315786,1091770885 +3495342,1594621,"atwork",1,true,4,9000,11000,143309026,"escort",52.586546235089074,10,"WALK",10.660093773427764,1146472209 +3495342,1594621,"atwork",2,true,4,7000,9000,143309026,"eatout",54.81382092908523,10,"WALK",14.040826305510333,1146472210 +3495342,1594621,"atwork",3,true,4,9000,7000,143309026,"eatout",52.150762754342416,10,"WALK",10.50217377147708,1146472211 +3495342,1594621,"atwork",4,true,4,9000,9000,143309026,"atwork",,10,"WALK",11.021053654094953,1146472212 +3495342,1594621,"atwork",1,false,1,11000,9000,143309026,"work",,10,"WALK",10.675133776355615,1146472213 +3495342,1594621,"work",1,true,1,11000,10000,143309061,"work",,8,"WALK",4.542307812891537,1146472489 +3495342,1594621,"work",1,false,1,10000,11000,143309061,"home",,17,"WALK",4.540040319156421,1146472493 +3495343,1594621,"shopping",1,true,2,8000,10000,143309096,"eatout",44.07715065746949,15,"WALK_LOC",12.334958131287545,1146472769 +3495343,1594621,"shopping",2,true,2,21000,8000,143309096,"shopping",,15,"WALK_LOC",4.754322605614275,1146472770 +3495343,1594621,"shopping",1,false,2,3000,21000,143309096,"shopping",35.64487169509503,16,"WALK_LOC",4.579037479011556,1146472773 +3495343,1594621,"shopping",2,false,2,10000,3000,143309096,"home",,16,"WALK_LRF",9.834778533473422,1146472774 +3596364,1645132,"univ",1,true,1,9000,9000,147450955,"univ",,11,"WALK",10.238432625148134,1179607641 +3596364,1645132,"univ",1,false,1,9000,9000,147450955,"home",,11,"WALK",10.238432625148134,1179607645 +3596364,1645132,"shopping",1,true,1,2000,9000,147450957,"shopping",,13,"WALK_LRF",0.8285401596132209,1179607657 +3596364,1645132,"shopping",1,false,1,9000,2000,147450957,"home",,19,"WALK_LRF",0.8244659836149215,1179607661 +3596365,1645132,"school",1,true,1,9000,9000,147450996,"school",,10,"WALK",10.238432621193224,1179607969 +3596365,1645132,"school",1,false,3,25000,9000,147450996,"shopping",42.28625449659161,17,"WALK",7.7398125409163105,1179607973 +3596365,1645132,"school",2,false,3,6000,25000,147450996,"othmaint",53.965718905093475,17,"WALK",12.120015882476332,1179607974 +3596365,1645132,"school",3,false,3,9000,6000,147450996,"home",,17,"WALK",11.33462804101704,1179607975 +3891102,1747467,"atwork",1,true,1,4000,1000,159535186,"atwork",,10,"WALK",0.45813980969805285,1276281489 +3891102,1747467,"atwork",1,false,2,25000,4000,159535186,"eatout",34.80381527769826,13,"WALK",0.2084762800360644,1276281493 +3891102,1747467,"atwork",2,false,2,1000,25000,159535186,"work",,13,"WALK",13.371530528904229,1276281494 +3891102,1747467,"work",1,true,2,7000,16000,159535221,"escort",30.09854287915041,8,"WALK",11.099112493958854,1276281769 +3891102,1747467,"work",2,true,2,1000,7000,159535221,"work",,10,"WALK",-0.14398137208511666,1276281770 +3891102,1747467,"work",1,false,2,6000,1000,159535221,"shopping",26.473055121441792,17,"WALK",-0.29357283995282485,1276281773 +3891102,1747467,"work",2,false,2,16000,6000,159535221,"home",,21,"WALK_LOC",9.754298157016313,1276281774 +3891104,1747467,"othdiscr",1,true,1,17000,16000,159535289,"othdiscr",,7,"WALK",5.9419631748312804,1276282313 +3891104,1747467,"othdiscr",1,false,1,16000,17000,159535289,"home",,22,"WALK",5.85268329864962,1276282317 +4171615,1810015,"univ",1,true,1,13000,16000,171036246,"univ",,18,"TNC_SHARED",-0.752316656547577,1368289969 +4171615,1810015,"univ",1,false,1,16000,13000,171036246,"home",,18,"WALK_LOC",-0.7196572448668817,1368289973 +4171616,1810015,"shopping",1,true,1,14000,16000,171036289,"shopping",,10,"WALK",1.0944891382847346,1368290313 +4171616,1810015,"shopping",1,false,1,16000,14000,171036289,"home",,14,"WALK",0.9382513291595582,1368290317 +4171617,1810015,"atwork",1,true,1,5000,11000,171036301,"atwork",,10,"WALK",4.630819623213244,1368290409 +4171617,1810015,"atwork",1,false,2,6000,5000,171036301,"escort",44.69367598003321,10,"WALK",4.690979682144286,1368290413 +4171617,1810015,"atwork",2,false,2,11000,6000,171036301,"work",,10,"WALK",12.460449128670621,1368290414 +4171617,1810015,"work",1,true,1,11000,16000,171036336,"work",,8,"WALK",2.7959725074724067,1368290689 +4171617,1810015,"work",1,false,1,16000,11000,171036336,"home",,16,"WALK",2.7959727582005645,1368290693 +4171619,1810015,"othdiscr",1,true,1,16000,16000,171036404,"othdiscr",,9,"WALK",7.330879449163802,1368291233 +4171619,1810015,"othdiscr",1,false,1,16000,16000,171036404,"home",,19,"WALK",7.330879449572421,1368291237 +4171622,1810015,"othmaint",1,true,1,2000,16000,171036530,"othmaint",,11,"TNC_SINGLE",0.05700613810224191,1368292241 +4171622,1810015,"othmaint",1,false,1,16000,2000,171036530,"home",,12,"TNC_SHARED",0.12318961832260422,1368292245 +4823797,1952792,"work",1,true,1,2000,14000,197775716,"work",,10,"WALK",-0.12977069563455434,1582205729 +4823797,1952792,"work",1,false,1,14000,2000,197775716,"home",,18,"WALK",-0.270575833053774,1582205733 +5057160,2048204,"work",1,true,1,5000,5000,207343599,"work",,6,"BIKE",3.570867061441779,1658748793 +5057160,2048204,"work",1,false,1,5000,5000,207343599,"home",,17,"BIKE",3.570867061441779,1658748797 +5057338,2048382,"work",1,true,1,17000,7000,207350897,"work",,7,"WALK",4.42461238620194,1658807177 +5057338,2048382,"work",1,false,1,7000,17000,207350897,"home",,20,"WALK_LOC",4.387261966488915,1658807181 +5387762,2223027,"work",1,true,1,10000,9000,220898281,"work",,6,"WALK",7.4825971749227485,1767186249 +5387762,2223027,"work",1,false,1,9000,10000,220898281,"home",,15,"WALK",7.34179717744091,1767186253 +5387763,2223027,"eatout",1,true,1,10000,9000,220898289,"eatout",,16,"WALK",9.90779315781692,1767186313 +5387763,2223027,"eatout",1,false,1,9000,10000,220898289,"home",,16,"WALK",9.729233148863598,1767186317 +5387763,2223027,"othdiscr",1,true,1,15000,9000,220898308,"othdiscr",,18,"WALK_LRF",2.11214260241268,1767186465 +5387763,2223027,"othdiscr",1,false,1,9000,15000,220898308,"home",,18,"WALK_LRF",2.114487481879299,1767186469 +5389226,2223759,"work",1,true,1,14000,16000,220958305,"work",,8,"WALK",0.5332653083530436,1767666441 +5389226,2223759,"work",1,false,1,16000,14000,220958305,"home",,17,"WALK",0.4100846172156184,1767666445 +5389227,2223759,"atwork",1,true,1,16000,16000,220958311,"atwork",,11,"WALK",7.392759591563246,1767666489 +5389227,2223759,"atwork",1,false,1,16000,16000,220958311,"work",,11,"WALK",7.392759591563246,1767666493 +5389227,2223759,"escort",1,true,1,5000,16000,220958316,"escort",,17,"WALK",4.089263672515711,1767666529 +5389227,2223759,"escort",1,false,1,16000,5000,220958316,"home",,17,"WALK",4.011143862031004,1767666533 +5389227,2223759,"work",1,true,1,16000,16000,220958346,"work",,6,"WALK",5.450624006214329,1767666769 +5389227,2223759,"work",1,false,1,16000,16000,220958346,"home",,15,"WALK",5.450624005397038,1767666773 +7305540,2727273,"social",1,true,1,21000,20000,299527176,"social",,7,"WALK",2.5336186542574204,2396217409 +7305540,2727273,"social",1,false,1,20000,21000,299527176,"home",,7,"WALK",2.3656307848426334,2396217413 +7305540,2727273,"social",1,true,1,9000,20000,299527177,"social",,10,"WALK",6.447035361842409,2396217417 +7305540,2727273,"social",1,false,2,8000,9000,299527177,"eatout",36.15580696689693,11,"WALK",6.6220351635608905,2396217421 +7305540,2727273,"social",2,false,2,20000,8000,299527177,"home",,11,"WALK",7.1913682178766365,2396217422 +7305540,2727273,"work",1,true,1,24000,20000,299527179,"work",,13,"BIKE",1.6028747415427587,2396217433 +7305540,2727273,"work",1,false,1,20000,24000,299527179,"home",,16,"BIKE",1.5355807172674794,2396217437 +7305541,2727273,"shopping",1,true,1,16000,20000,299527214,"shopping",,18,"WALK",7.064914498109314,2396217713 +7305541,2727273,"shopping",1,false,1,20000,16000,299527214,"home",,20,"WALK_LOC",7.1093419615753985,2396217717 +7305541,2727273,"social",1,true,1,21000,20000,299527217,"social",,17,"WALK_LOC",3.0911048477980314,2396217737 +7305541,2727273,"social",1,false,1,20000,21000,299527217,"home",,17,"WALK_LOC",3.200851120839349,2396217741 +7305541,2727273,"work",1,true,1,4000,20000,299527220,"work",,7,"WALK",-0.11437934759116813,2396217761 +7305541,2727273,"work",1,false,1,20000,4000,299527220,"home",,15,"WALK_LRF",0.6663056921108688,2396217765 +7453413,2762078,"othmaint",1,true,1,8000,20000,305589961,"othmaint",,11,"WALK_LOC",8.511850861798528,2444719689 +7453413,2762078,"othmaint",1,false,1,20000,8000,305589961,"home",,14,"WALK",8.452543898989719,2444719693 +7511873,2820538,"work",1,true,1,1000,8000,307986832,"work",,7,"WALK_LOC",-0.5114030615970244,2463894657 +7511873,2820538,"work",1,false,1,8000,1000,307986832,"home",,15,"WALK",-0.6139093584117478,2463894661 +7512109,2820774,"work",1,true,1,14000,8000,307996508,"work",,7,"WALK_LOC",0.6718435845841986,2463972065 +7512109,2820774,"work",1,false,1,8000,14000,307996508,"home",,18,"WALK",0.610566926121762,2463972069 +7512514,2821179,"work",1,true,1,9000,8000,308013113,"work",,18,"WALK",7.994842521447154,2464104905 +7512514,2821179,"work",1,false,1,8000,9000,308013113,"home",,21,"WALK",7.994842521452135,2464104909 +7513432,2822097,"social",1,true,1,11000,8000,308050748,"social",,9,"WALK_LOC",3.706460558335686,2464405985 +7513432,2822097,"social",1,false,2,9000,11000,308050748,"eatout",31.394224343964623,16,"WALK",3.677383696890382,2464405989 +7513432,2822097,"social",2,false,2,8000,9000,308050748,"home",,16,"WALK_LOC",7.113541133018152,2464405990 +7513554,2822219,"work",1,true,2,9000,8000,308055753,"eatout",42.391324918183464,10,"WALK",8.722225942224798,2464446025 +7513554,2822219,"work",2,true,2,9000,9000,308055753,"work",,12,"WALK",8.5974651892884,2464446026 +7513554,2822219,"work",1,false,1,8000,9000,308055753,"home",,21,"WALK",8.698411202168328,2464446029 +7523517,2832182,"shopping",1,true,1,13000,7000,308464230,"shopping",,15,"WALK_LOC",-0.5264083063330212,2467713841 +7523517,2832182,"shopping",1,false,1,7000,13000,308464230,"home",,15,"WALK_LOC",-0.4961048751413181,2467713845 diff --git a/activitysim/examples/placeholder_multiple_zone/test/test_multiple_zone.py b/activitysim/examples/placeholder_multiple_zone/test/test_multiple_zone.py index 3e956301e..3921bcd0f 100644 --- a/activitysim/examples/placeholder_multiple_zone/test/test_multiple_zone.py +++ b/activitysim/examples/placeholder_multiple_zone/test/test_multiple_zone.py @@ -39,14 +39,16 @@ def data(): build_data() -def run_test(zone, multiprocess=False): +def run_test(zone, multiprocess=False, use_explicit_error_terms=False): def test_path(dirname): return os.path.join(os.path.dirname(__file__), dirname) - def regress(zone): + def regress(zone, use_explicit_error_terms=False): # regress tours regress_tours_df = pd.read_csv( - test_path(f"regress/final_tours_{zone}_zone.csv") + test_path( + f"regress/final{'_eet' if use_explicit_error_terms else ''}_tours_{zone}_zone.csv" + ) ) tours_df = pd.read_csv(test_path("output/final_tours.csv")) tours_df.to_csv( @@ -59,7 +61,9 @@ def regress(zone): # regress trips regress_trips_df = pd.read_csv( - test_path(f"regress/final_trips_{zone}_zone.csv") + test_path( + f"regress/final{'_eet' if use_explicit_error_terms else ''}_trips_{zone}_zone.csv" + ) ) trips_df = pd.read_csv(test_path("output/final_trips.csv")) trips_df.to_csv( @@ -72,7 +76,15 @@ def regress(zone): file_path = os.path.join(os.path.dirname(__file__), "simulation.py") + test_config_files = [] + if use_explicit_error_terms: + test_config_files = [ + "-c", + test_path("configs_eet"), + ] + run_args = [ + *test_config_files, "-c", test_path(f"configs_{zone}_zone"), "-c", @@ -95,7 +107,7 @@ def regress(zone): else: subprocess.run([sys.executable, file_path] + run_args, check=True) - regress(zone) + regress(zone, use_explicit_error_terms=use_explicit_error_terms) def test_2_zone(data): @@ -106,6 +118,14 @@ def test_2_zone_mp(data): run_test(zone="2", multiprocess=True) +def test_2_zone_eet(data): + run_test(zone="2", multiprocess=False, use_explicit_error_terms=True) + + +def test_2_zone_mp_eet(data): + run_test(zone="2", multiprocess=True, use_explicit_error_terms=True) + + def test_3_zone(data): # python simulation.py -c configs_3_zone -c ../configs_3_zone -c \ # ../../prototype_mtc/configs -d ../data_3 -o output -s settings_mp @@ -202,10 +222,53 @@ def test_path(dirname): print(f"> {zone} zone {step_name}: ok") +@test.run_if_exists("reference_pipeline_2_zone_eet.zip") +def test_multizone_progressive_eet(): + + import activitysim.abm # register components + + def test_path(dirname): + return os.path.join(os.path.dirname(__file__), dirname) + + state = workflow.State.make_default( + configs_dir=( + test_path(f"configs_eet"), + test_path(f"configs_2_zone"), + example_path(f"configs_2_zone"), + mtc_example_path("configs"), + ), + data_dir=(example_path(f"data_2"),), + output_dir=test_path("output"), + settings_file_name="settings.yaml", + ) + + assert state.settings.models == EXPECTED_MODELS + assert state.settings.chunk_size == 0 + assert state.settings.sharrow == False + assert state.settings.use_explicit_error_terms == True + + for step_name in EXPECTED_MODELS: + state.run.by_name(step_name) + try: + state.checkpoint.check_against( + Path(__file__).parent.joinpath("reference_pipeline_2_zone_eet.zip"), + checkpoint_name=step_name, + ) + except Exception: + print(f"> 2 zone eet {step_name}: ERROR") + raise + else: + print(f"> 2 zone {step_name}: ok") + + if __name__ == "__main__": build_data() + run_test(zone="2", multiprocess=False) run_test(zone="2", multiprocess=True) + run_test(zone="2", multiprocess=False, use_explicit_error_terms=True) + run_test(zone="2", multiprocess=True, use_explicit_error_terms=True) + run_test(zone="3", multiprocess=False) run_test(zone="3", multiprocess=True) diff --git a/activitysim/examples/production_semcog/test/configs_eet/settings.yaml b/activitysim/examples/production_semcog/test/configs_eet/settings.yaml new file mode 100644 index 000000000..dcff83f5a --- /dev/null +++ b/activitysim/examples/production_semcog/test/configs_eet/settings.yaml @@ -0,0 +1,5 @@ +inherit_settings: True + +use_explicit_error_terms: True + +rng_base_seed: 42 diff --git a/activitysim/examples/production_semcog/test/regress/final_eet_trips.csv b/activitysim/examples/production_semcog/test/regress/final_eet_trips.csv new file mode 100644 index 000000000..9826e1d68 --- /dev/null +++ b/activitysim/examples/production_semcog/test/regress/final_eet_trips.csv @@ -0,0 +1,116 @@ +"person_id","household_id","primary_purpose","trip_num","outbound","trip_count","destination","origin","tour_id","purpose","destination_logsum","original_school_zone_id","parked_at_university","depart","tour_includes_parking","trip_id_pre_parking","trip_mode","mode_choice_logsum","trip_id" +2632461,1066212,"eatout",1,true,1,22677,22687,107930907,"eatout",,,false,31,0,863447257,"WALK",1.2747067090732285,1726894513 +2632461,1066212,"eatout",1,false,1,22687,22677,107930907,"home",,,false,36,0,863447261,"WALK",1.2528040978215553,1726894521 +2632461,1066212,"social",1,true,1,22688,22687,107930937,"social",,,false,27,0,863447497,"WALK",0.22160552915226453,1726894993 +2632461,1066212,"social",1,false,1,22687,22688,107930937,"home",,,false,30,0,863447501,"WALK",0.22160552915226453,1726895001 +2632461,1066212,"work",1,true,1,22659,22687,107930940,"work",,,false,11,0,863447521,"DRIVEALONE",-0.2764049012484984,1726895041 +2632461,1066212,"work",1,false,1,22687,22659,107930940,"home",,,false,23,0,863447525,"DRIVEALONE",-0.26321709957638273,1726895049 +2632746,1066390,"school",1,true,2,22689,22688,107942617,"shopping",10.30120931810444,,false,10,0,863540937,"WALK",0.41173295672864374,1727081873 +2632746,1066390,"school",2,true,2,22716,22689,107942617,"school",,,false,10,0,863540938,"SHARED3",-0.12093048344357989,1727081874 +2632746,1066390,"school",1,false,1,22688,22716,107942617,"home",,,false,21,0,863540941,"SHARED3",-0.12094657865851986,1727081881 +2632746,1066390,"work",1,true,1,22688,22688,107942625,"work",,,false,21,0,863541001,"WALK",0.22160552915226453,1727082001 +2632746,1066390,"work",1,false,1,22688,22688,107942625,"home",,,false,26,0,863541005,"WALK",0.22160552915226453,1727082009 +2643231,1070862,"work",1,true,2,22795,22701,108372510,"parking",,,false,12,1,866980081,"DRIVEALONE",-0.8231318335063801,1733960161 +2643231,1070862,"work",2,true,2,22795,22795,108372510,"work",,,true,12,1,866980081,"WALK",2.0056875567057055,1733960162 +2643231,1070862,"work",1,false,2,22795,22795,108372510,"parking",,,true,27,1,866980085,"WALK",2.005696956562539,1733960169 +2643231,1070862,"work",2,false,2,22701,22795,108372510,"home",,,false,27,1,866980085,"DRIVEALONE",-0.856858292126302,1733960170 +2851663,1151807,"work",1,true,1,22743,22768,116918222,"work",,,false,8,0,935345777,"DRIVEALONE",0.32319821567472595,1870691553 +2851663,1151807,"work",1,false,1,22768,22743,116918222,"home",,,false,23,0,935345781,"SHARED2",0.31914343414862156,1870691561 +2851664,1151807,"atwork",1,true,1,22755,22783,116918247,"atwork",,,false,9,0,935345977,"WALK",-0.4285387553231248,1870691953 +2851664,1151807,"atwork",1,false,2,22767,22755,116918247,"eatout",13.620552291309844,,false,9,0,935345981,"WALK",-0.3360993920023427,1870691961 +2851664,1151807,"atwork",2,false,2,22783,22767,116918247,"work",,,false,9,0,935345982,"WALK",2.0196212107066467,1870691962 +2851664,1151807,"work",1,true,2,22783,22768,116918263,"parking",,,false,8,1,935346105,"DRIVEALONE",-0.101763675139766,1870692209 +2851664,1151807,"work",2,true,2,22783,22783,116918263,"work",,,true,8,1,935346105,"WALK",2.394893602362858,1870692210 +2851664,1151807,"work",1,false,2,22783,22783,116918263,"parking",,,true,9,1,935346109,"WALK",2.394893602362858,1870692217 +2851664,1151807,"work",2,false,2,22768,22783,116918263,"home",,,false,9,1,935346109,"DRIVEALONE",-0.14128432072913716,1870692218 +2851664,1151807,"work",1,true,2,22783,22768,116918264,"parking",,,false,20,1,935346113,"SHARED2",0.3036422340987692,1870692225 +2851664,1151807,"work",2,true,2,22783,22783,116918264,"work",,,true,20,1,935346113,"WALK",3.455230939742648,1870692226 +2851664,1151807,"work",1,false,3,22783,22783,116918264,"parking",,,true,22,1,935346117,"WALK",3.455230939742648,1870692233 +2851664,1151807,"work",2,false,3,22743,22783,116918264,"eatout",13.694190728203349,,false,22,1,935346117,"SHARED2",0.12796410019608423,1870692234 +2851664,1151807,"work",3,false,3,22768,22743,116918264,"home",,,false,22,1,935346118,"DRIVEALONE",0.28506746953977524,1870692235 +2851665,1151807,"school",1,true,1,22738,22768,116918296,"school",,,false,9,0,935346369,"WALK",-0.3380929737459932,1870692737 +2851665,1151807,"school",1,false,1,22768,22738,116918296,"home",,,false,25,0,935346373,"WALK",-0.3380929737459932,1870692745 +2851666,1151807,"school",1,true,1,22738,22768,116918337,"school",,,false,9,1,935346697,"WALK",-0.23394837977299351,1870693393 +2851666,1151807,"school",1,false,4,22766,22738,116918337,"parking",,,false,26,1,935346701,"WALK",-0.12281263655431907,1870693401 +2851666,1151807,"school",2,false,4,22767,22766,116918337,"eatout",12.976839556161908,,true,26,1,935346701,"WALK",-0.452052425913061,1870693402 +2851666,1151807,"school",3,false,4,22766,22767,116918337,"parking",,,true,26,1,935346702,"WALK",2.053743433341529,1870693403 +2851666,1151807,"school",4,false,4,22768,22766,116918337,"home",,,false,26,1,935346702,"SHARED3",-0.16257826107609574,1870693404 +2853258,1152693,"work",1,true,1,22738,22767,116983617,"work",,,false,20,0,935868937,"WALK",-0.22675750604679695,1871737873 +2853258,1152693,"work",1,false,1,22767,22738,116983617,"home",,,false,42,0,935868941,"WALK",-0.22675750604679695,1871737881 +2864033,1157863,"work",1,true,1,22801,22818,117425392,"work",,,false,22,0,939403137,"WALK",3.73570922575177,1878806273 +2864033,1157863,"work",1,false,3,22771,22801,117425392,"othmaint",26.926672191384228,,false,43,0,939403141,"WALK",4.180094740047142,1878806281 +2864033,1157863,"work",2,false,3,22767,22771,117425392,"othmaint",27.815811398797507,,false,43,0,939403142,"WALK",4.6038065658867176,1878806282 +2864033,1157863,"work",3,false,3,22818,22767,117425392,"home",,,false,44,0,939403143,"WALK",4.817999024372856,1878806283 +2867650,1159450,"work",1,true,2,22800,22791,117573689,"parking",,,false,12,1,940589513,"DRIVEALONE",-0.06025969651174059,1881179025 +2867650,1159450,"work",2,true,2,22800,22800,117573689,"work",,,true,12,1,940589513,"WALK",3.0701275509879262,1881179026 +2867650,1159450,"work",1,false,2,22800,22800,117573689,"parking",,,true,37,1,940589517,"WALK",3.070138980004933,1881179033 +2867650,1159450,"work",2,false,2,22791,22800,117573689,"home",,,false,37,1,940589517,"WALK",0.2738110299731082,1881179034 +2867652,1159450,"school",1,true,1,22798,22791,117573763,"school",,,false,11,0,940590105,"WALK",-0.1419702876491479,1881180209 +2867652,1159450,"school",1,false,2,22807,22798,117573763,"escort",12.102989575726829,,false,26,0,940590109,"WALK",0.30995293909650445,1881180217 +2867652,1159450,"school",2,false,2,22791,22807,117573763,"home",,,false,27,0,940590110,"WALK",1.1921458680932127,1881180218 +2867653,1159450,"school",1,true,1,22738,22791,117573804,"school",,,false,9,0,940590433,"BIKE",-0.6921067330756006,1881180865 +2867653,1159450,"school",1,false,1,22791,22738,117573804,"home",,,false,23,0,940590437,"BIKE",-0.6921067330756006,1881180873 +2867653,1159450,"school",1,true,1,22738,22791,117573805,"school",,,false,8,0,940590441,"SCHOOLBUS",-1.3378817936541838,1881180881 +2867653,1159450,"school",1,false,1,22791,22738,117573805,"home",,,false,8,0,940590445,"SHARED2",-9.871239947524709,1881180889 +2869308,1160345,"escort",1,true,1,22814,22788,117641637,"escort",,,false,10,0,941133097,"WALK",-0.2948412350381067,1882266193 +2869308,1160345,"escort",1,false,1,22788,22814,117641637,"home",,,false,10,0,941133101,"WALK",-0.2948412350381067,1882266201 +2869308,1160345,"work",1,true,1,22640,22788,117641667,"work",,,false,11,1,941133337,"SHARED2",-0.6362720979256549,1882266673 +2869308,1160345,"work",1,false,6,22761,22640,117641667,"parking",,,false,27,1,941133341,"SHARED3",-0.5969499608294799,1882266681 +2869308,1160345,"work",2,false,6,22767,22761,117641667,"othmaint",11.470504256383801,,true,27,1,941133341,"WALK",3.0222067430139012,1882266682 +2869308,1160345,"work",3,false,6,22761,22767,117641667,"parking",,,true,28,1,941133342,"WALK",4.036268963328661,1882266683 +2869308,1160345,"work",4,false,6,22769,22761,117641667,"shopping",13.481404724590321,,false,28,1,941133342,"WALK",0.4697934390352235,1882266684 +2869308,1160345,"work",5,false,6,22769,22769,117641667,"escort",13.817298583185659,,false,29,1,941133343,"DRIVEALONE",0.5088371121647843,1882266685 +2869308,1160345,"work",6,false,6,22788,22769,117641667,"home",,,false,30,1,941133344,"DRIVEALONE",0.38196512409824096,1882266686 +2869309,1160345,"univ",1,true,2,22795,22788,117641700,"parking",,,false,13,1,941133601,"DRIVEALONE",-0.15235107523409816,1882267201 +2869309,1160345,"univ",2,true,2,22766,22795,117641700,"univ",,,true,13,1,941133601,"WALK_LOC",1.202786557349171,1882267202 +2869309,1160345,"univ",1,false,3,22795,22766,117641700,"parking",,,true,24,1,941133605,"WALK_LOC",1.142188272503556,1882267209 +2869309,1160345,"univ",2,false,3,22769,22795,117641700,"othdiscr",12.456311079956105,,false,24,1,941133605,"WALK",-1.6313849658981006,1882267210 +2869309,1160345,"univ",3,false,3,22788,22769,117641700,"home",,,false,24,1,941133606,"DRIVEALONE",-0.3087846946902839,1882267211 +2869392,1160408,"shopping",1,true,2,22797,22784,117645105,"parking",,,false,26,1,941160841,"DRIVEALONE",-0.0973453493011812,1882321681 +2869392,1160408,"shopping",2,true,2,22767,22797,117645105,"shopping",,,true,26,1,941160841,"WALK",3.635953706352258,1882321682 +2869392,1160408,"shopping",1,false,3,22797,22767,117645105,"parking",,,true,36,1,941160845,"WALK",3.2319057420708,1882321689 +2869392,1160408,"shopping",2,false,3,22778,22797,117645105,"othmaint",13.169263985923191,,false,36,1,941160845,"DRIVEALONE",-0.8388301157218331,1882321690 +2869392,1160408,"shopping",3,false,3,22784,22778,117645105,"home",,,false,37,1,941160846,"DRIVEALONE",-0.21796488394191485,1882321691 +2871041,1161101,"work",1,true,1,22801,22747,117712720,"work",,,false,10,0,941701761,"PNR_LOC",0.001366053793971812,1883403521 +2871041,1161101,"work",1,false,1,22747,22801,117712720,"home",,,false,30,0,941701765,"PNR_LOC",-0.0004743815570571668,1883403529 +2871042,1161101,"work",1,true,2,22802,22747,117712761,"parking",,,false,6,1,941702089,"DRIVEALONE",0.31437493739186884,1883404177 +2871042,1161101,"work",2,true,2,22802,22802,117712761,"work",,,true,6,1,941702089,"WALK",3.98103278438962,1883404178 +2871042,1161101,"work",1,false,2,22802,22802,117712761,"parking",,,true,31,1,941702093,"WALK",3.9810287626204213,1883404185 +2871042,1161101,"work",2,false,2,22747,22802,117712761,"home",,,false,31,1,941702093,"WALK",0.29964022247838484,1883404186 +4717826,1936565,"univ",1,true,1,22809,22808,193430897,"univ",,,false,25,0,1547447177,"WALK",2.48948699138067,3094894353 +4717826,1936565,"univ",1,false,4,22809,22809,193430897,"univ",10.85837416878764,22809,false,42,0,1547447181,"WALK",3.0000160707611045,3094894361 +4717826,1936565,"univ",2,false,4,22767,22809,193430897,"social",14.420134553925665,,false,43,0,1547447182,"WALK",2.7860651296874943,3094894362 +4717826,1936565,"univ",3,false,4,22767,22767,193430897,"eatout",18.783329870271647,,false,44,0,1547447183,"WALK",5.6282528531399505,3094894363 +4717826,1936565,"univ",4,false,4,22808,22767,193430897,"home",,,false,44,0,1547447184,"WALK",5.305674253948064,3094894364 +4718747,1937486,"univ",1,true,3,22771,22765,193468658,"eatout",25.835053255003054,,false,14,0,1547749265,"WALK_LOC",4.433464410699681,3095498529 +4718747,1937486,"univ",2,true,3,22767,22771,193468658,"social",25.54589732725773,,false,16,0,1547749266,"WALK",5.362458425962315,3095498530 +4718747,1937486,"univ",3,true,3,22809,22767,193468658,"univ",,,false,19,0,1547749267,"WALK",2.7945694548961417,3095498531 +4718747,1937486,"univ",1,false,1,22765,22809,193468658,"home",,,false,42,0,1547749269,"WALK",2.48457681340577,3095498537 +4718747,1937486,"shopping",1,true,2,22767,22765,193468660,"shopping",30.83670381348187,,false,13,0,1547749281,"WALK",6.4385685368034355,3095498561 +4718747,1937486,"shopping",2,true,2,22770,22767,193468660,"shopping",,,false,13,0,1547749282,"WALK",5.192455869479483,3095498562 +4718747,1937486,"shopping",1,false,1,22765,22770,193468660,"home",,,false,14,0,1547749285,"WALK",4.807792080345957,3095498569 +4720352,1939091,"univ",1,true,1,22766,22765,193534463,"univ",,,false,9,0,1548275705,"WALK",-0.6239793637995562,3096551409 +4720352,1939091,"univ",1,false,3,22759,22766,193534463,"shopping",11.15021662330538,,false,9,0,1548275709,"WALK",-0.5391508363377113,3096551417 +4720352,1939091,"univ",2,false,3,22760,22759,193534463,"othdiscr",17.448616740575964,,false,9,0,1548275710,"WALK",1.2201965059296072,3096551418 +4720352,1939091,"univ",3,false,3,22765,22760,193534463,"home",,,false,9,0,1548275711,"WALK",2.8041844809824235,3096551419 +4720352,1939091,"univ",1,true,1,22766,22765,193534464,"univ",,,false,13,0,1548275713,"WALK",2.715317834267571,3096551425 +4720352,1939091,"univ",1,false,2,22764,22766,193534464,"univ",11.320277288258279,,false,20,0,1548275717,"WALK",2.6563322165532184,3096551433 +4720352,1939091,"univ",2,false,2,22765,22764,193534464,"home",,,false,21,0,1548275718,"WALK",2.683225159417532,3096551434 +4722297,1942003,"univ",1,true,1,22809,22810,193614208,"univ",,,false,11,0,1548913665,"WALK",2.4667125356379236,3097827329 +4722297,1942003,"univ",1,false,1,22810,22809,193614208,"home",,,false,37,0,1548913669,"WALK",2.4563973988486754,3097827337 +4726458,1946164,"eatout",1,true,1,22762,22808,193784784,"eatout",,,false,21,0,1550278273,"WALK",-1.0299557646373856,3100556545 +4726458,1946164,"eatout",1,false,1,22808,22762,193784784,"home",,,false,22,0,1550278277,"WALK",-1.0299556501964702,3100556553 +4726458,1946164,"eatout",1,true,1,22773,22808,193784785,"eatout",,,false,28,0,1550278281,"WALK",-0.5777209461821046,3100556561 +4726458,1946164,"eatout",1,false,1,22808,22773,193784785,"home",,,false,29,0,1550278285,"WALK",-0.5777209461821046,3100556569 +4726458,1946164,"shopping",1,true,1,22770,22808,193784811,"shopping",,,false,14,0,1550278489,"WALK",0.3756438367025996,3100556977 +4726458,1946164,"shopping",1,false,1,22808,22770,193784811,"home",,,false,17,0,1550278493,"WALK",0.3756438367025996,3100556985 +4727363,1947069,"univ",1,true,1,22766,22765,193821914,"univ",,,false,14,0,1550575313,"WALK",-0.6239793637995562,3101150625 +4727363,1947069,"univ",1,false,3,22767,22766,193821914,"escort",13.043891235923125,,false,26,0,1550575317,"WALK",-0.9673991559282129,3101150633 +4727363,1947069,"univ",2,false,3,22767,22767,193821914,"shopping",18.14486120913688,,false,26,0,1550575318,"WALK",2.62825193059268,3101150634 +4727363,1947069,"univ",3,false,3,22765,22767,193821914,"home",,,false,27,0,1550575319,"WALK",2.1708672114306493,3101150635 +4729458,1949164,"univ",1,true,2,22767,22745,193907809,"eatout",25.639413512184284,,false,11,0,1551262473,"WALK_LOC",5.44204000187347,3102524945 +4729458,1949164,"univ",2,true,2,22809,22767,193907809,"univ",,,false,11,0,1551262474,"WALK",2.7976141090172613,3102524946 +4729458,1949164,"univ",1,false,2,22802,22809,193907809,"othdiscr",26.8381285605357,,false,27,0,1551262477,"WALK",2.9113281848126373,3102524953 +4729458,1949164,"univ",2,false,2,22745,22802,193907809,"home",,,false,28,0,1551262478,"WALK",5.509333658704657,3102524954 +4729679,1949385,"eatout",1,true,1,22748,22745,193916845,"eatout",,,false,26,0,1551334761,"WALK",0.10355029016646346,3102669521 +4729679,1949385,"eatout",1,false,1,22745,22748,193916845,"home",,,false,27,0,1551334765,"WALK",0.10355029016646346,3102669529 diff --git a/activitysim/examples/production_semcog/test/test_semcog.py b/activitysim/examples/production_semcog/test/test_semcog.py index e247fd645..8b77a4e3a 100644 --- a/activitysim/examples/production_semcog/test/test_semcog.py +++ b/activitysim/examples/production_semcog/test/test_semcog.py @@ -11,7 +11,7 @@ from activitysim.core.test._tools import assert_frame_substantively_equal -def run_test_semcog(multiprocess=False): +def run_test_semcog(multiprocess=False, use_explicit_error_terms=False): def example_path(dirname): resource = os.path.join("examples", "production_semcog", dirname) return str(importlib.resources.files("activitysim").joinpath(resource)) @@ -19,9 +19,12 @@ def example_path(dirname): def test_path(dirname): return os.path.join(os.path.dirname(__file__), dirname) - def regress(): + def regress(use_explicit_error_terms=False): regress_trips_df = pd.read_csv( - test_path("regress/final_trips.csv"), dtype={"depart": int} + test_path( + f"regress/final{'_eet' if use_explicit_error_terms else ''}_trips.csv" + ), + dtype={"depart": int}, ) final_trips_df = pd.read_csv( test_path("output/final_trips.csv"), dtype={"depart": int} @@ -30,6 +33,12 @@ def regress(): file_path = os.path.join(os.path.dirname(__file__), "../simulation.py") + test_config_files = [] + if use_explicit_error_terms: + test_config_files = [ + "-c", + test_path("configs_eet"), + ] if multiprocess: subprocess.run( [ @@ -37,6 +46,7 @@ def regress(): "run", "-a", file_path, + *test_config_files, "-c", test_path("configs_mp"), "-c", @@ -59,6 +69,7 @@ def regress(): "run", "-a", file_path, + *test_config_files, "-c", test_path("configs"), "-c", @@ -73,7 +84,7 @@ def regress(): check=True, ) - regress() + regress(use_explicit_error_terms=use_explicit_error_terms) def test_semcog(): @@ -84,6 +95,16 @@ def test_semcog_mp(): run_test_semcog(multiprocess=True) +def test_semcog_eet(): + run_test_semcog(multiprocess=False, use_explicit_error_terms=True) + + +def test_semcog_mp_eet(): + run_test_semcog(multiprocess=True, use_explicit_error_terms=True) + + if __name__ == "__main__": run_test_semcog(multiprocess=False) run_test_semcog(multiprocess=True) + run_test_semcog(multiprocess=False, use_explicit_error_terms=True) + run_test_semcog(multiprocess=True, use_explicit_error_terms=True) diff --git a/activitysim/examples/prototype_arc/test/configs_eet/settings.yaml b/activitysim/examples/prototype_arc/test/configs_eet/settings.yaml new file mode 100644 index 000000000..08c06d702 --- /dev/null +++ b/activitysim/examples/prototype_arc/test/configs_eet/settings.yaml @@ -0,0 +1,3 @@ +inherit_settings: True + +use_explicit_error_terms: True diff --git a/activitysim/examples/prototype_arc/test/regress/final_trips.csv b/activitysim/examples/prototype_arc/test/regress/final_trips.csv index 3cfe9e642..79f1c9b93 100644 --- a/activitysim/examples/prototype_arc/test/regress/final_trips.csv +++ b/activitysim/examples/prototype_arc/test/regress/final_trips.csv @@ -1,91 +1,91 @@ -trip_id,person_id,household_id,primary_purpose,trip_num,outbound,trip_count,destination,origin,tour_id,purpose,destination_logsum,depart,trip_mode,mode_choice_logsum,parking_zone_id -37314161,113762,42730,othmaint,1,True,1,106,103,4664270,othmaint,,10,DRIVEALONEFREE,-0.3567815721035004,-1 -37314165,113762,42730,othmaint,1,False,1,103,106,4664270,home,,11,DRIVEALONEFREE,-0.356460303068161,-1 -38194977,116448,43843,atwork,1,True,1,106,101,4774372,atwork,,20,DRIVEALONEFREE,-0.3217517137527465,-1 -38194981,116448,43843,atwork,1,False,1,101,106,4774372,work,,21,DRIVEALONEFREE,-0.3217517137527465,-1 -38195065,116449,43843,othdiscr,1,True,1,106,103,4774383,othdiscr,,32,SHARED2FREE,0.7593915111282218,-1 -38195069,116449,43843,othdiscr,1,False,1,103,106,4774383,home,,37,SHARED2FREE,0.7593915111282218,-1 -38195257,116448,43843,work,1,True,2,107,103,4774407,othmaint,9.244319,10,DRIVEALONEFREE,-0.6671370863914491,-1 -38195258,116448,43843,work,2,True,2,101,107,4774407,work,,10,DRIVEALONEFREE,-0.5893840193748475,-1 -38195261,116448,43843,work,1,False,1,103,101,4774407,home,,30,DRIVEALONEFREE,-0.5012716650962832,-1 -38195585,116449,43843,work,1,True,2,106,103,4774448,othmaint,10.644734,12,DRIVEALONEFREE,0.05086306230852542,-1 -38195586,116449,43843,work,2,True,2,102,106,4774448,work,,13,DRIVEALONEFREE,0.03254505218598833,-1 -38195589,116449,43843,work,1,False,3,103,102,4774448,othmaint,10.796497,23,SHARED2FREE,0.0983521099924028,-1 -38195590,116449,43843,work,2,False,3,103,103,4774448,work,12.367123,24,DRIVEALONEFREE,0.24223826711784288,-1 -38195591,116449,43843,work,3,False,3,103,103,4774448,home,,26,DRIVEALONEFREE,0.2401515927071465,-1 -38195849,116450,43843,school,1,True,1,106,103,4774481,school,,9,SCHOOL_BUS,4.351044654846191,-1 -38195853,116450,43843,school,1,False,1,103,106,4774481,home,,27,SCHOOL_BUS,4.351044654846191,-1 -38195865,116450,43843,shopping,1,True,1,101,103,4774483,shopping,,27,SHARED2FREE,-0.4441019010696936,-1 -38195869,116450,43843,shopping,1,False,1,103,101,4774483,home,,30,SHARED2FREE,-0.45749089544283433,-1 -39613905,120774,45311,atwork,1,True,1,101,102,4951738,atwork,,20,DRIVEALONEFREE,-0.41128289699554443,-1 -39613909,120774,45311,atwork,1,False,1,102,101,4951738,work,,21,DRIVEALONEFREE,-0.4119255244731903,-1 -39614185,120774,45311,work,1,True,2,106,105,4951773,work,10.647319,10,DRIVEALONEFREE,-0.4328329563140868,-1 -39614186,120774,45311,work,2,True,2,102,106,4951773,work,,11,DRIVEALONEFREE,-0.34803289175033575,-1 -39614189,120774,45311,work,1,False,1,105,102,4951773,home,,30,DRIVEALONEFREE,-0.604685664176941,-1 -39614513,120775,45311,work,1,True,1,101,105,4951814,work,,9,DRIVEALONEFREE,-0.6009435653686525,-1 -39614517,120775,45311,work,1,False,3,101,101,4951814,work,10.767546,28,DRIVEALONEFREE,-0.3567099869251252,-1 -39614518,120775,45311,work,2,False,3,107,101,4951814,othmaint,9.370711,28,DRIVEALONEFREE,-0.5956825017929079,-1 -39614519,120775,45311,work,3,False,3,105,107,4951814,home,,29,DRIVEALONEFREE,-0.43356654047966,-1 -40387937,123133,46056,work,1,True,1,106,106,5048492,work,,20,DRIVEALONEFREE,-0.19777289032936102,-1 -40387941,123133,46056,work,1,False,1,106,106,5048492,home,,40,DRIVEALONEFREE,-0.1974023878574371,-1 -43308361,132037,49258,othmaint,1,True,1,122,110,5413545,othmaint,,23,DRIVEALONEFREE,-0.7390050888061525,-1 -43308365,132037,49258,othmaint,1,False,2,114,122,5413545,eatout,8.7858,24,DRIVEALONEFREE,-0.5175821781158448,-1 -43308366,132037,49258,othmaint,2,False,2,110,114,5413545,home,,24,DRIVEALONEFREE,-0.5938398838043213,-1 -43308537,132038,49258,escort,1,True,1,107,110,5413567,escort,,10,SHARED3FREE,-0.002601420005322437,-1 -43308541,132038,49258,escort,1,False,1,110,107,5413567,home,,22,SHARED3FREE,-0.002601420005322437,-1 -44930737,136983,50912,work,1,True,2,123,112,5616342,eatout,9.353397,31,DRIVEALONEFREE,-0.5493329763412477,-1 -44930738,136983,50912,work,2,True,2,104,123,5616342,work,,32,DRIVEALONEFREE,-0.6666110157966614,-1 -44930741,136983,50912,work,1,False,2,112,104,5616342,social,11.149774,34,DRIVEALONEFREE,-0.5302670001983643,-1 -44930742,136983,50912,work,2,False,2,112,112,5616342,home,,34,DRIVEALONEFREE,-0.18331599235534674,-1 -44931065,136984,50912,work,1,True,2,101,112,5616383,shopping,9.520916,11,DRIVEALONEFREE,-0.6129478216171266,-1 -44931066,136984,50912,work,2,True,2,107,101,5616383,work,,12,DRIVEALONEFREE,-0.6193944811820985,-1 -44931069,136984,50912,work,1,False,3,123,107,5616383,work,10.775923,28,DRIVEALONEFREE,-0.7651270031929017,-1 -44931070,136984,50912,work,2,False,3,104,123,5616383,escort,9.519634,29,DRIVEALONEFREE,-0.6666110157966614,-1 -44931071,136984,50912,work,3,False,3,112,104,5616383,home,,30,DRIVEALONEFREE,-0.5499035120010376,-1 -47621473,145187,53716,othmaint,1,True,3,121,116,5952684,social,9.947862,8,SHARED3FREE,-0.41955729937135083,-1 -47621474,145187,53716,othmaint,2,True,3,112,121,5952684,othmaint,9.261029,11,SHARED3FREE,-0.6422730088233947,-1 -47621475,145187,53716,othmaint,3,True,3,122,112,5952684,othmaint,,11,SHARED3FREE,-0.6419082880020143,-1 -47621477,145187,53716,othmaint,1,False,1,116,122,5952684,home,,20,SHARED3FREE,-0.6134629858242939,-1 -47621737,145188,53716,escort,1,True,1,114,116,5952717,escort,,29,DRIVEALONEFREE,-0.15083796859645277,-1 -47621741,145188,53716,escort,1,False,1,116,114,5952717,home,,30,SHARED2FREE,-0.15179812895272474,-1 -47622241,145189,53716,school,1,True,1,114,116,5952780,school,,10,SCHOOL_BUS,4.3079237937927255,-1 -47622245,145189,53716,school,1,False,1,116,114,5952780,home,,24,SCHOOL_BUS,4.3079237937927255,-1 -47622569,145190,53716,school,1,True,1,114,116,5952821,school,,9,SHARED2FREE,-0.20617904275545365,-1 -47622573,145190,53716,school,1,False,1,116,114,5952821,home,,24,SHARED2FREE,-0.20568500108204935,-1 -48258513,147129,54342,othdiscr,1,True,1,116,117,6032314,othdiscr,,27,DRIVEALONEFREE,-0.5246167778968812,-1 -48258517,147129,54342,othdiscr,1,False,1,117,116,6032314,home,,33,DRIVEALONEFREE,-0.49120157957077026,-1 -48258537,147129,54342,othmaint,1,True,1,114,117,6032317,othmaint,,34,DRIVEALONEFREE,-0.687132179737091,-1 -48258541,147129,54342,othmaint,1,False,2,114,114,6032317,shopping,9.148774,37,DRIVEALONEFREE,-0.42373609542846685,-1 -48258542,147129,54342,othmaint,2,False,2,117,114,6032317,home,,38,DRIVEALONEFREE,-0.6845617890357972,-1 -56357665,171822,63802,eatout,1,True,1,127,135,7044708,eatout,,31,DRIVEALONEFREE,-0.6526245474815369,-1 -56357669,171822,63802,eatout,1,False,1,135,127,7044708,home,,34,DRIVEALONEFREE,-0.6343104243278503,-1 -56357689,171822,63802,escort,1,True,1,135,135,7044711,escort,,28,SHARED3FREE,0.07706324286670248,-1 -56357693,171822,63802,escort,1,False,2,135,135,7044711,escort,11.356267,28,SHARED3FREE,0.07706324286670248,-1 -56357694,171822,63802,escort,2,False,2,135,135,7044711,home,,28,SHARED3FREE,0.07706324286670248,-1 -56357737,171822,63802,othdiscr,1,True,3,131,135,7044717,othdiscr,12.194779,13,SHARED2FREE,0.599977654783949,-1 -56357738,171822,63802,othdiscr,2,True,3,130,131,7044717,shopping,13.357507,14,SHARED2FREE,0.6200047250329787,-1 -56357739,171822,63802,othdiscr,3,True,3,130,130,7044717,othdiscr,,14,SHARED2FREE,0.6960546579187884,-1 -56357741,171822,63802,othdiscr,1,False,1,135,130,7044717,home,,14,SHARED2FREE,0.6487159186367744,-1 -56358209,171823,63802,shopping,1,True,4,131,135,7044776,othmaint,10.342613,24,SHARED3FREE,-0.14619837454037923,-1 -56358210,171823,63802,shopping,2,True,4,131,131,7044776,social,12.281772,25,SHARED3FREE,-0.012169709209450414,-1 -56358211,171823,63802,shopping,3,True,4,131,131,7044776,shopping,11.556939,26,SHARED3FREE,-0.012169709209450414,-1 -56358212,171823,63802,shopping,4,True,4,131,131,7044776,shopping,,26,SHARED3FREE,-0.012169709209450414,-1 -56358213,171823,63802,shopping,1,False,1,135,131,7044776,home,,27,DRIVEALONEFREE,-0.15095594351539895,-1 -56358473,171824,63802,othdiscr,1,True,1,131,135,7044809,othdiscr,,32,SHARED2FREE,-0.46024149381952484,-1 -56358477,171824,63802,othdiscr,1,False,1,135,131,7044809,home,,37,SHARED2FREE,-0.45329299190068956,-1 -56358521,171824,63802,school,1,True,2,135,135,7044815,escort,11.635028,10,SHARED2FREE,0.10569338088788001,-1 -56358522,171824,63802,school,2,True,2,135,135,7044815,school,,10,SHARED3FREE,0.10569338088788001,-1 -56358525,171824,63802,school,1,False,2,135,135,7044815,othdiscr,11.906311,25,SHARED3FREE,0.10545807803885715,-1 -56358526,171824,63802,school,2,False,2,135,135,7044815,home,,26,SHARED3FREE,0.10545807803885715,-1 -56358801,171825,63802,othdiscr,1,True,1,131,135,7044850,othdiscr,,29,SHARED3FREE,-0.281769477499857,-1 -56358805,171825,63802,othdiscr,1,False,2,132,131,7044850,social,10.225653,35,SHARED2FREE,-0.20277185632585107,-1 -56358806,171825,63802,othdiscr,2,False,2,135,132,7044850,home,,39,SHARED3FREE,-0.36521793162300004,-1 -56358809,171825,63802,othdiscr,1,True,4,135,135,7044851,othmaint,5.3795877,26,WALK,-0.7460585832595825,-1 -56358810,171825,63802,othdiscr,2,True,4,131,135,7044851,othmaint,5.4266872,27,WALK,-2.0398435592651363,-1 -56358811,171825,63802,othdiscr,3,True,4,130,131,7044851,othmaint,5.7105064,28,WALK,-1.2828608751297,-1 -56358812,171825,63802,othdiscr,4,True,4,130,130,7044851,othdiscr,,28,WALK,-0.78075897693634,-1 -56358813,171825,63802,othdiscr,1,False,1,135,130,7044851,home,,28,WALK,-1.4660019874572756,-1 -56358849,171825,63802,school,1,True,1,135,135,7044856,school,,9,SHARED3FREE,0.10569338088788001,-1 -56358853,171825,63802,school,1,False,1,135,135,7044856,home,,24,SHARED3FREE,0.10569338088788001,-1 -56359177,171826,63802,school,1,True,1,135,135,7044897,school,,10,SHARED3FREE,0.10569338088788001,-1 -56359181,171826,63802,school,1,False,1,135,135,7044897,home,,22,SHARED3FREE,0.10569338088788001,-1 +"person_id","household_id","primary_purpose","trip_num","outbound","trip_count","destination","origin","tour_id","purpose","destination_logsum","depart","trip_mode","mode_choice_logsum","trip_id" +113762,42730,"othmaint",1,true,1,106,103,4664270,"othmaint",,10,"DRIVEALONEFREE",-0.3567815833091734,37314161 +113762,42730,"othmaint",1,false,1,103,106,4664270,"home",,11,"DRIVEALONEFREE",-0.3564603142738344,37314165 +116448,43843,"atwork",1,true,1,106,101,4774372,"atwork",,20,"DRIVEALONEFREE",-0.3217517094135284,38194977 +116448,43843,"atwork",1,false,1,101,106,4774372,"work",,21,"DRIVEALONEFREE",-0.3217517094135284,38194981 +116449,43843,"othdiscr",1,true,1,106,103,4774383,"othdiscr",,32,"SHARED2FREE",0.7593914979829192,38195065 +116449,43843,"othdiscr",1,false,1,103,106,4774383,"home",,37,"SHARED2FREE",0.7593914979829192,38195069 +116448,43843,"work",1,true,2,107,103,4774407,"othmaint",9.244319214996622,10,"DRIVEALONEFREE",-0.6671371741294861,38195257 +116448,43843,"work",2,true,2,101,107,4774407,"work",,11,"DRIVEALONEFREE",-0.5893840121269226,38195258 +116448,43843,"work",1,false,1,103,101,4774407,"home",,30,"DRIVEALONEFREE",-0.5012717045307159,38195261 +116449,43843,"work",1,true,2,106,103,4774448,"othmaint",10.644734946815246,12,"DRIVEALONEFREE",0.05086305622830629,38195585 +116449,43843,"work",2,true,2,102,106,4774448,"work",,15,"DRIVEALONEFREE",0.03291252148410589,38195586 +116449,43843,"work",1,false,3,103,102,4774448,"othmaint",10.796498240479236,24,"SHARED2FREE",0.09835208854623434,38195589 +116449,43843,"work",2,false,3,103,103,4774448,"work",12.367122837815295,26,"DRIVEALONEFREE",0.24015159118542195,38195590 +116449,43843,"work",3,false,3,103,103,4774448,"home",,26,"DRIVEALONEFREE",0.24015159118542195,38195591 +116450,43843,"school",1,true,1,106,103,4774481,"school",,9,"SCHOOL_BUS",4.351044797545671,38195849 +116450,43843,"school",1,false,1,103,106,4774481,"home",,27,"SCHOOL_BUS",4.351044797545671,38195853 +116450,43843,"shopping",1,true,1,101,103,4774483,"shopping",,27,"SHARED2FREE",-0.44410188801130307,38195865 +116450,43843,"shopping",1,false,1,103,101,4774483,"home",,30,"SHARED2FREE",-0.4574908823858229,38195869 +120774,45311,"atwork",1,true,1,101,102,4951738,"atwork",,20,"DRIVEALONEFREE",-0.4112828999996184,39613905 +120774,45311,"atwork",1,false,1,102,101,4951738,"work",,21,"DRIVEALONEFREE",-0.4119254976749421,39613909 +120774,45311,"work",1,true,2,106,105,4951773,"work",10.647318549180723,10,"DRIVEALONEFREE",-0.4328329442501069,39614185 +120774,45311,"work",2,true,2,102,106,4951773,"work",,11,"DRIVEALONEFREE",-0.3480328878879547,39614186 +120774,45311,"work",1,false,1,105,102,4951773,"home",,30,"DRIVEALONEFREE",-0.6046856504917144,39614189 +120775,45311,"work",1,true,1,101,105,4951814,"work",,9,"DRIVEALONEFREE",-0.6009435992240908,39614513 +120775,45311,"work",1,false,3,101,101,4951814,"work",10.767545755383658,26,"DRIVEALONEFREE",-0.35670998854637154,39614517 +120775,45311,"work",2,false,3,107,101,4951814,"othmaint",9.370711100307654,26,"DRIVEALONEFREE",-0.5956824945449828,39614518 +120775,45311,"work",3,false,3,105,107,4951814,"home",,29,"DRIVEALONEFREE",-0.43356653208732604,39614519 +123133,46056,"work",1,true,1,106,106,5048492,"work",,20,"DRIVEALONEFREE",-0.19777291302680963,40387937 +123133,46056,"work",1,false,1,106,106,5048492,"home",,40,"DRIVEALONEFREE",-0.1974023956537246,40387941 +132037,49258,"othmaint",1,true,1,122,110,5413545,"othmaint",,23,"DRIVEALONEFREE",-0.7390051318168641,43308361 +132037,49258,"othmaint",1,false,2,114,122,5413545,"eatout",8.785799297132586,24,"DRIVEALONEFREE",-0.5175821724891663,43308365 +132037,49258,"othmaint",2,false,2,110,114,5413545,"home",,24,"DRIVEALONEFREE",-0.5938398692131043,43308366 +132038,49258,"escort",1,true,1,107,110,5413567,"escort",,10,"SHARED3FREE",-0.002601425939803153,43308537 +132038,49258,"escort",1,false,1,110,107,5413567,"home",,22,"SHARED3FREE",-0.002601425939803153,43308541 +136983,50912,"work",1,true,2,123,112,5616342,"eatout",9.353397383302754,31,"DRIVEALONEFREE",-0.5493329919815063,44930737 +136983,50912,"work",2,true,2,104,123,5616342,"work",,32,"DRIVEALONEFREE",-0.6666110144615174,44930738 +136983,50912,"work",1,false,2,112,104,5616342,"social",11.149774183428809,32,"DRIVEALONEFREE",-0.5499035404682159,44930741 +136983,50912,"work",2,false,2,112,112,5616342,"home",,34,"DRIVEALONEFREE",-0.18331599397659298,44930742 +136984,50912,"work",1,true,2,101,112,5616383,"shopping",9.520915574738705,11,"DRIVEALONEFREE",-0.6129478299617769,44931065 +136984,50912,"work",2,true,2,107,101,5616383,"work",,11,"DRIVEALONEFREE",-0.6193944739341735,44931066 +136984,50912,"work",1,false,3,123,107,5616383,"work",10.775923228059439,27,"DRIVEALONEFREE",-0.7651270068168641,44931069 +136984,50912,"work",2,false,3,104,123,5616383,"escort",9.51963410471578,27,"DRIVEALONEFREE",-0.6666110144615174,44931070 +136984,50912,"work",3,false,3,112,104,5616383,"home",,30,"DRIVEALONEFREE",-0.5499035404682159,44931071 +145187,53716,"othmaint",1,true,3,121,116,5952684,"social",9.947861733897312,8,"SHARED3FREE",-0.41955731333905055,47621473 +145187,53716,"othmaint",2,true,3,112,121,5952684,"othmaint",9.26102871194454,11,"SHARED3FREE",-0.6422730395793916,47621474 +145187,53716,"othmaint",3,true,3,122,112,5952684,"othmaint",,11,"SHARED3FREE",-0.6419082540988923,47621475 +145187,53716,"othmaint",1,false,1,116,122,5952684,"home",,20,"SHARED3FREE",-0.6134629528820534,47621477 +145188,53716,"escort",1,true,1,114,116,5952717,"escort",,29,"DRIVEALONEFREE",-0.15083797590032313,47621737 +145188,53716,"escort",1,false,1,116,114,5952717,"home",,30,"SHARED2FREE",-0.15179813514136692,47621741 +145189,53716,"school",1,true,1,114,116,5952780,"school",,10,"SCHOOL_BUS",4.3079239998221395,47622241 +145189,53716,"school",1,false,1,116,114,5952780,"home",,24,"SCHOOL_BUS",4.3079239998221395,47622245 +145190,53716,"school",1,true,1,114,116,5952821,"school",,9,"SHARED2FREE",-0.20617904920050897,47622569 +145190,53716,"school",1,false,1,116,114,5952821,"home",,24,"SHARED2FREE",-0.20568500752544042,47622573 +147129,54342,"othdiscr",1,true,1,116,117,6032314,"othdiscr",,27,"DRIVEALONEFREE",-0.5246167486667632,48258513 +147129,54342,"othdiscr",1,false,1,117,116,6032314,"home",,33,"DRIVEALONEFREE",-0.4912015503406525,48258517 +147129,54342,"othmaint",1,true,1,114,117,6032317,"othmaint",,34,"DRIVEALONEFREE",-0.6871321834564209,48258537 +147129,54342,"othmaint",1,false,2,114,114,6032317,"shopping",9.148774093624228,37,"DRIVEALONEFREE",-0.4237361037254333,48258541 +147129,54342,"othmaint",2,false,2,117,114,6032317,"home",,38,"DRIVEALONEFREE",-0.6845617927551271,48258542 +171822,63802,"eatout",1,true,1,127,135,7044708,"eatout",,31,"DRIVEALONEFREE",-0.652624578666687,56357665 +171822,63802,"eatout",1,false,1,135,127,7044708,"home",,34,"DRIVEALONEFREE",-0.6343104555130004,56357669 +171822,63802,"escort",1,true,1,135,135,7044711,"escort",,28,"SHARED3FREE",0.07706324792840326,56357689 +171822,63802,"escort",1,false,2,135,135,7044711,"escort",11.356267091092906,28,"SHARED3FREE",0.07706324792840326,56357693 +171822,63802,"escort",2,false,2,135,135,7044711,"home",,28,"SHARED3FREE",0.07706324792840326,56357694 +171822,63802,"othdiscr",1,true,3,131,135,7044717,"othdiscr",12.194779637866755,13,"SHARED2FREE",0.5999776535886836,56357737 +171822,63802,"othdiscr",2,true,3,130,131,7044717,"shopping",13.357506128369907,13,"SHARED2FREE",0.620004705610611,56357738 +171822,63802,"othdiscr",3,true,3,130,130,7044717,"othdiscr",,13,"SHARED2FREE",0.6960546331136191,56357739 +171822,63802,"othdiscr",1,false,1,135,130,7044717,"home",,14,"SHARED2FREE",0.6487159219305315,56357741 +171823,63802,"shopping",1,true,4,131,135,7044776,"othmaint",10.342612763246748,24,"SHARED3FREE",-0.1461983375796215,56358209 +171823,63802,"shopping",2,true,4,131,131,7044776,"social",12.281771137855209,25,"SHARED3FREE",-0.01216970989402637,56358210 +171823,63802,"shopping",3,true,4,131,131,7044776,"shopping",11.556938954932807,26,"SHARED3FREE",-0.01216970989402637,56358211 +171823,63802,"shopping",4,true,4,131,131,7044776,"shopping",,26,"SHARED3FREE",-0.01216970989402637,56358212 +171823,63802,"shopping",1,false,1,135,131,7044776,"home",,27,"DRIVEALONEFREE",-0.1509559426724583,56358213 +171824,63802,"othdiscr",1,true,1,131,135,7044809,"othdiscr",,32,"SHARED2FREE",-0.4602414968534174,56358473 +171824,63802,"othdiscr",1,false,1,135,131,7044809,"home",,37,"SHARED2FREE",-0.45329299490631025,56358477 +171824,63802,"school",1,true,2,135,135,7044815,"escort",11.63502708221396,10,"SHARED2FREE",0.10569338295856193,56358521 +171824,63802,"school",2,true,2,135,135,7044815,"school",,11,"SHARED3FREE",0.10569338295856193,56358522 +171824,63802,"school",1,false,2,135,135,7044815,"othdiscr",11.906310169709501,25,"SHARED3FREE",0.10545807870230886,56358525 +171824,63802,"school",2,false,2,135,135,7044815,"home",,26,"SHARED3FREE",0.10545807870230886,56358526 +171825,63802,"othdiscr",1,true,1,131,135,7044850,"othdiscr",,29,"SHARED3FREE",-0.2817694611797112,56358801 +171825,63802,"othdiscr",1,false,2,132,131,7044850,"social",10.225652936631004,39,"SHARED2FREE",-0.20277182093145324,56358805 +171825,63802,"othdiscr",2,false,2,135,132,7044850,"home",,39,"SHARED3FREE",-0.36521793543833225,56358806 +171825,63802,"othdiscr",1,true,4,135,135,7044851,"othmaint",5.3795880164987455,26,"WALK",-0.7460586428642273,56358809 +171825,63802,"othdiscr",2,true,4,131,135,7044851,"othmaint",5.426687572911977,27,"WALK",-2.039843797683716,56358810 +171825,63802,"othdiscr",3,true,4,130,131,7044851,"othmaint",5.710506288696134,28,"WALK",-1.2828608453273775,56358811 +171825,63802,"othdiscr",4,true,4,130,130,7044851,"othdiscr",,28,"WALK",-0.7807589769363404,56358812 +171825,63802,"othdiscr",1,false,1,135,130,7044851,"home",,28,"WALK",-1.4660018980503084,56358813 +171825,63802,"school",1,true,1,135,135,7044856,"school",,9,"SHARED3FREE",0.10569338295856193,56358849 +171825,63802,"school",1,false,1,135,135,7044856,"home",,24,"SHARED3FREE",0.10569338295856193,56358853 +171826,63802,"school",1,true,1,135,135,7044897,"school",,10,"SHARED3FREE",0.10569338295856193,56359177 +171826,63802,"school",1,false,1,135,135,7044897,"home",,22,"SHARED3FREE",0.10569338295856193,56359181 diff --git a/activitysim/examples/prototype_arc/test/regress/final_trips_eet.csv b/activitysim/examples/prototype_arc/test/regress/final_trips_eet.csv new file mode 100644 index 000000000..ca0a19fb4 --- /dev/null +++ b/activitysim/examples/prototype_arc/test/regress/final_trips_eet.csv @@ -0,0 +1,84 @@ +"person_id","household_id","primary_purpose","trip_num","outbound","trip_count","destination","origin","tour_id","purpose","destination_logsum","depart","trip_mode","mode_choice_logsum","trip_id" +113762,42730,"work",1,true,2,102,103,4664281,"escort",11.620562271430003,11,"SHARED2FREE",0.1984450162064936,37314249 +113762,42730,"work",2,true,2,106,102,4664281,"work",,12,"DRIVEALONEFREE",0.1174194651741796,37314250 +113762,42730,"work",1,false,2,101,106,4664281,"shopping",11.71157893264538,31,"SHARED3FREE",0.16362355684245977,37314253 +113762,42730,"work",2,false,2,103,101,4664281,"home",,32,"DRIVEALONEFREE",-0.02897760267828356,37314254 +116448,43843,"work",1,true,2,105,103,4774407,"othmaint",9.341245249202924,10,"DRIVEALONEFREE",-0.657585671377182,38195257 +116448,43843,"work",2,true,2,101,105,4774407,"work",,15,"DRIVEALONEFREE",-0.5883466045856476,38195258 +116448,43843,"work",1,false,2,123,101,4774407,"othmaint",9.123561456324088,25,"DRIVEALONEFREE",-0.9421370327949524,38195261 +116448,43843,"work",2,false,2,103,123,4774407,"home",,29,"DRIVEALONEFREE",-0.7305148571968079,38195262 +116450,43843,"school",1,true,2,106,103,4774481,"escort",11.70931236960696,10,"SHARED3FREE",0.06412222350024642,38195849 +116450,43843,"school",2,true,2,106,106,4774481,"school",,10,"WALK",0.1346124978975689,38195850 +116450,43843,"school",1,false,1,103,106,4774481,"home",,26,"SHARED3FREE",0.06400167836417262,38195853 +120774,45311,"atwork",1,true,2,122,123,4951738,"work",11.450943959940382,18,"DRIVEALONEFREE",-0.481071140050888,39613905 +120774,45311,"atwork",2,true,2,122,122,4951738,"atwork",,18,"DRIVEALONEFREE",-0.3282438698291779,39613906 +120774,45311,"atwork",1,false,1,123,122,4951738,"work",,21,"DRIVEALONEFREE",-0.47753682303428663,39613909 +120774,45311,"work",1,true,1,123,105,4951773,"work",,8,"DRIVEALONEFREE",-0.5730820206642151,39614185 +120774,45311,"work",1,false,1,105,123,4951773,"home",,29,"DRIVEALONEFREE",-0.5845674780845644,39614189 +120775,45311,"shopping",1,true,1,104,105,4951808,"shopping",,19,"DRIVEALONEFREE",-0.5170302743911744,39614465 +120775,45311,"shopping",1,false,1,105,104,4951808,"home",,26,"DRIVEALONEFREE",-0.526026701450348,39614469 +120775,45311,"work",1,true,1,106,105,4951814,"work",,11,"DRIVEALONEFREE",-0.4328329442501069,39614513 +120775,45311,"work",1,false,1,105,106,4951814,"home",,19,"DRIVEALONEFREE",-0.4224589346408844,39614517 +123132,46056,"atwork",1,true,2,106,106,5048416,"othdiscr",5.736908684681538,20,"WALK",-1.0410120487213135,40387329 +123132,46056,"atwork",2,true,2,101,106,5048416,"atwork",,21,"WALK",-1.4049548953771591,40387330 +123132,46056,"atwork",1,false,1,106,101,5048416,"work",,22,"WALK",-1.4049548953771591,40387333 +123132,46056,"work",1,true,2,100,106,5048451,"social",12.992372530395093,11,"DRIVEALONEFREE",-0.056856693416576155,40387609 +123132,46056,"work",2,true,2,106,100,5048451,"work",,11,"SHARED2FREE",-0.06978704502587849,40387610 +123132,46056,"work",1,false,4,106,106,5048451,"othmaint",11.571615647229482,30,"DRIVEALONEFREE",0.2365447098181202,40387613 +123132,46056,"work",2,false,4,106,106,5048451,"othmaint",12.148331580258795,30,"SHARED2FREE",0.2365447098181202,40387614 +123132,46056,"work",3,false,4,106,106,5048451,"eatout",11.338764994103533,30,"DRIVEALONEFREE",0.2365447098181202,40387615 +123132,46056,"work",4,false,4,106,106,5048451,"home",,35,"SHARED2FREE",0.23932365335602357,40387616 +136983,50912,"atwork",1,true,1,123,123,5616307,"atwork",,19,"WALK",-1.127763032913208,44930457 +136983,50912,"atwork",1,false,2,123,123,5616307,"othmaint",6.824969769883364,19,"WALK",-1.127763032913208,44930461 +136983,50912,"atwork",2,false,2,123,123,5616307,"work",,21,"WALK",-1.127763032913208,44930462 +136983,50912,"work",1,true,1,123,112,5616342,"work",,16,"SHARED3FREE",-0.020760706766682024,44930737 +136983,50912,"work",1,false,4,104,123,5616342,"eatout",11.284613956027043,23,"SHARED3FREE",-0.07389233569315362,44930741 +136983,50912,"work",2,false,4,103,104,5616342,"work",12.6148435779502,23,"SHARED3FREE",0.05220751420566755,44930742 +136983,50912,"work",3,false,4,104,103,5616342,"eatout",10.989757771316299,23,"DRIVEALONEFREE",0.053315758831313835,44930743 +136983,50912,"work",4,false,4,112,104,5616342,"home",,30,"DRIVEALONEFREE",-0.03395123851246563,44930744 +136984,50912,"atwork",1,true,1,111,114,5616344,"atwork",,19,"DRIVEALONEFREE",-0.5068167327404024,44930753 +136984,50912,"atwork",1,false,1,114,111,5616344,"work",,20,"DRIVEALONEFREE",-0.50456764087677,44930757 +136984,50912,"atwork",1,true,1,114,114,5616348,"atwork",,20,"DRIVEALONEFREE",-0.4243787014007569,44930785 +136984,50912,"atwork",1,false,1,114,114,5616348,"work",,21,"DRIVEALONEFREE",-0.4243787014007569,44930789 +136984,50912,"work",1,true,1,114,112,5616383,"work",,17,"DRIVEALONEFREE",-0.5196855528831482,44931065 +136984,50912,"work",1,false,1,112,114,5616383,"home",,32,"DRIVEALONEFREE",-0.524872527885437,44931069 +145188,53716,"othdiscr",1,true,2,103,116,5952733,"eatout",8.095380549568242,26,"SHARED2FREE",-0.656344788392591,47621865 +145188,53716,"othdiscr",2,true,2,106,103,5952733,"othdiscr",,28,"SHARED3FREE",0.01085078798134025,47621866 +145188,53716,"othdiscr",1,false,1,116,106,5952733,"home",,39,"SHARED3FREE",-0.5586695841155525,47621869 +145188,53716,"shopping",1,true,2,121,116,5952741,"escort",10.284349421053356,24,"DRIVEALONEFREE",0.007844892145818317,47621929 +145188,53716,"shopping",2,true,2,122,121,5952741,"shopping",,24,"DRIVEALONEFREE",-0.09430664622810597,47621930 +145188,53716,"shopping",1,false,1,116,122,5952741,"home",,25,"DRIVEALONEFREE",-0.18333346470683046,47621933 +147129,54342,"atwork",1,true,2,118,118,6032293,"work",11.591261619486666,24,"DRIVEALONEFREE",-0.277168506860733,48258345 +147129,54342,"atwork",2,true,2,118,118,6032293,"atwork",,25,"DRIVEALONEFREE",-0.27748977589607243,48258346 +147129,54342,"atwork",1,false,1,118,118,6032293,"work",,27,"DRIVEALONEFREE",-0.27748977589607243,48258349 +147129,54342,"work",1,true,1,118,117,6032328,"work",,24,"DRIVEALONEFREE",-0.3512043696403504,48258625 +147129,54342,"work",1,false,2,117,118,6032328,"othmaint",9.222307568325903,45,"DRIVEALONEFREE",-0.3512043696403504,48258629 +147129,54342,"work",2,false,2,117,117,6032328,"home",,46,"DRIVEALONEFREE",-0.3278332107067109,48258630 +168909,62701,"othmaint",1,true,1,135,131,6925297,"othmaint",,25,"DRIVEALONEFREE",-0.1509559426724583,55402377 +168909,62701,"othmaint",1,false,1,131,135,6925297,"home",,28,"SHARED3FREE",-0.14873576359938484,55402381 +171822,63802,"atwork",1,true,1,128,130,7044702,"atwork",,17,"DRIVEALONEFREE",-0.5419102621078492,56357617 +171822,63802,"atwork",1,false,1,130,128,7044702,"work",,20,"DRIVEALONEFREE",-0.5419102621078492,56357621 +171822,63802,"shopping",1,true,1,135,135,7044721,"shopping",,29,"WALK",-0.7460586428642273,56357769 +171822,63802,"shopping",1,false,3,135,135,7044721,"othmaint",8.365401255841729,30,"WALK",-0.7460586428642273,56357773 +171822,63802,"shopping",2,false,3,135,135,7044721,"othmaint",8.36277534519151,30,"WALK",-0.7460586428642273,56357774 +171822,63802,"shopping",3,false,3,135,135,7044721,"home",,31,"WALK",-0.7460586428642273,56357775 +171822,63802,"work",1,true,1,130,135,7044741,"work",,12,"DRIVEALONEFREE",-0.4857847907543183,56357929 +171822,63802,"work",1,false,2,130,130,7044741,"shopping",9.965446400011412,24,"DRIVEALONEFREE",-0.45575206193923956,56357933 +171822,63802,"work",2,false,2,135,130,7044741,"home",,27,"DRIVEALONEFREE",-0.486525795698166,56357934 +171823,63802,"escort",1,true,1,135,135,7044752,"escort",,27,"SHARED2FREE",0.07706324792840326,56358017 +171823,63802,"escort",1,false,2,135,135,7044752,"othmaint",11.334171843971035,27,"DRIVEALONEFREE",0.07706324792840326,56358021 +171823,63802,"escort",2,false,2,135,135,7044752,"home",,27,"SHARED3FREE",0.07706324792840326,56358022 +171823,63802,"escort",1,true,1,135,135,7044753,"escort",,10,"SHARED2FREE",0.07768184479155238,56358025 +171823,63802,"escort",1,false,3,135,135,7044753,"escort",11.396653773741745,10,"SHARED3FREE",0.07768184479155238,56358029 +171823,63802,"escort",2,false,3,135,135,7044753,"eatout",11.163952601101887,10,"WALK",0.07768184479155238,56358030 +171823,63802,"escort",3,false,3,135,135,7044753,"home",,11,"SHARED2FREE",0.07768184479155238,56358031 +171824,63802,"school",1,true,1,135,135,7044815,"school",,10,"SHARED2FREE",-0.04192782886512184,56358521 +171824,63802,"school",1,false,1,135,135,7044815,"home",,25,"SHARED2FREE",-0.0421655910777971,56358525 +171825,63802,"school",1,true,2,135,135,7044856,"school",14.150222701978416,10,"SHARED3FREE",0.10569338295856193,56358849 +171825,63802,"school",2,true,2,135,135,7044856,"school",,11,"SHARED3FREE",0.10569338295856193,56358850 +171825,63802,"school",1,false,1,135,135,7044856,"home",,26,"SHARED3FREE",0.10545807870230886,56358853 +171826,63802,"school",1,true,3,135,135,7044897,"othmaint",11.076463602650021,8,"SHARED2FREE",-0.04192782886512184,56359177 +171826,63802,"school",2,true,3,135,135,7044897,"escort",11.412423645394568,9,"SHARED2FREE",-0.04192782886512184,56359178 +171826,63802,"school",3,true,3,135,135,7044897,"school",,9,"SHARED2FREE",-0.04192782886512184,56359179 +171826,63802,"school",1,false,2,135,135,7044897,"school",13.560897172707032,22,"SHARED2FREE",-0.04192782886512184,56359181 +171826,63802,"school",2,false,2,135,135,7044897,"home",,24,"SHARED2FREE",-0.04192782886512184,56359182 diff --git a/activitysim/examples/prototype_arc/test/regress/final_trips_sh.csv b/activitysim/examples/prototype_arc/test/regress/final_trips_sh.csv index 3cfe9e642..0bd93ac3e 100644 --- a/activitysim/examples/prototype_arc/test/regress/final_trips_sh.csv +++ b/activitysim/examples/prototype_arc/test/regress/final_trips_sh.csv @@ -1,91 +1,91 @@ -trip_id,person_id,household_id,primary_purpose,trip_num,outbound,trip_count,destination,origin,tour_id,purpose,destination_logsum,depart,trip_mode,mode_choice_logsum,parking_zone_id -37314161,113762,42730,othmaint,1,True,1,106,103,4664270,othmaint,,10,DRIVEALONEFREE,-0.3567815721035004,-1 -37314165,113762,42730,othmaint,1,False,1,103,106,4664270,home,,11,DRIVEALONEFREE,-0.356460303068161,-1 -38194977,116448,43843,atwork,1,True,1,106,101,4774372,atwork,,20,DRIVEALONEFREE,-0.3217517137527465,-1 -38194981,116448,43843,atwork,1,False,1,101,106,4774372,work,,21,DRIVEALONEFREE,-0.3217517137527465,-1 -38195065,116449,43843,othdiscr,1,True,1,106,103,4774383,othdiscr,,32,SHARED2FREE,0.7593915111282218,-1 -38195069,116449,43843,othdiscr,1,False,1,103,106,4774383,home,,37,SHARED2FREE,0.7593915111282218,-1 -38195257,116448,43843,work,1,True,2,107,103,4774407,othmaint,9.244319,10,DRIVEALONEFREE,-0.6671370863914491,-1 -38195258,116448,43843,work,2,True,2,101,107,4774407,work,,10,DRIVEALONEFREE,-0.5893840193748475,-1 -38195261,116448,43843,work,1,False,1,103,101,4774407,home,,30,DRIVEALONEFREE,-0.5012716650962832,-1 -38195585,116449,43843,work,1,True,2,106,103,4774448,othmaint,10.644734,12,DRIVEALONEFREE,0.05086306230852542,-1 -38195586,116449,43843,work,2,True,2,102,106,4774448,work,,13,DRIVEALONEFREE,0.03254505218598833,-1 -38195589,116449,43843,work,1,False,3,103,102,4774448,othmaint,10.796497,23,SHARED2FREE,0.0983521099924028,-1 -38195590,116449,43843,work,2,False,3,103,103,4774448,work,12.367123,24,DRIVEALONEFREE,0.24223826711784288,-1 -38195591,116449,43843,work,3,False,3,103,103,4774448,home,,26,DRIVEALONEFREE,0.2401515927071465,-1 -38195849,116450,43843,school,1,True,1,106,103,4774481,school,,9,SCHOOL_BUS,4.351044654846191,-1 -38195853,116450,43843,school,1,False,1,103,106,4774481,home,,27,SCHOOL_BUS,4.351044654846191,-1 -38195865,116450,43843,shopping,1,True,1,101,103,4774483,shopping,,27,SHARED2FREE,-0.4441019010696936,-1 -38195869,116450,43843,shopping,1,False,1,103,101,4774483,home,,30,SHARED2FREE,-0.45749089544283433,-1 -39613905,120774,45311,atwork,1,True,1,101,102,4951738,atwork,,20,DRIVEALONEFREE,-0.41128289699554443,-1 -39613909,120774,45311,atwork,1,False,1,102,101,4951738,work,,21,DRIVEALONEFREE,-0.4119255244731903,-1 -39614185,120774,45311,work,1,True,2,106,105,4951773,work,10.647319,10,DRIVEALONEFREE,-0.4328329563140868,-1 -39614186,120774,45311,work,2,True,2,102,106,4951773,work,,11,DRIVEALONEFREE,-0.34803289175033575,-1 -39614189,120774,45311,work,1,False,1,105,102,4951773,home,,30,DRIVEALONEFREE,-0.604685664176941,-1 -39614513,120775,45311,work,1,True,1,101,105,4951814,work,,9,DRIVEALONEFREE,-0.6009435653686525,-1 -39614517,120775,45311,work,1,False,3,101,101,4951814,work,10.767546,28,DRIVEALONEFREE,-0.3567099869251252,-1 -39614518,120775,45311,work,2,False,3,107,101,4951814,othmaint,9.370711,28,DRIVEALONEFREE,-0.5956825017929079,-1 -39614519,120775,45311,work,3,False,3,105,107,4951814,home,,29,DRIVEALONEFREE,-0.43356654047966,-1 -40387937,123133,46056,work,1,True,1,106,106,5048492,work,,20,DRIVEALONEFREE,-0.19777289032936102,-1 -40387941,123133,46056,work,1,False,1,106,106,5048492,home,,40,DRIVEALONEFREE,-0.1974023878574371,-1 -43308361,132037,49258,othmaint,1,True,1,122,110,5413545,othmaint,,23,DRIVEALONEFREE,-0.7390050888061525,-1 -43308365,132037,49258,othmaint,1,False,2,114,122,5413545,eatout,8.7858,24,DRIVEALONEFREE,-0.5175821781158448,-1 -43308366,132037,49258,othmaint,2,False,2,110,114,5413545,home,,24,DRIVEALONEFREE,-0.5938398838043213,-1 -43308537,132038,49258,escort,1,True,1,107,110,5413567,escort,,10,SHARED3FREE,-0.002601420005322437,-1 -43308541,132038,49258,escort,1,False,1,110,107,5413567,home,,22,SHARED3FREE,-0.002601420005322437,-1 -44930737,136983,50912,work,1,True,2,123,112,5616342,eatout,9.353397,31,DRIVEALONEFREE,-0.5493329763412477,-1 -44930738,136983,50912,work,2,True,2,104,123,5616342,work,,32,DRIVEALONEFREE,-0.6666110157966614,-1 -44930741,136983,50912,work,1,False,2,112,104,5616342,social,11.149774,34,DRIVEALONEFREE,-0.5302670001983643,-1 -44930742,136983,50912,work,2,False,2,112,112,5616342,home,,34,DRIVEALONEFREE,-0.18331599235534674,-1 -44931065,136984,50912,work,1,True,2,101,112,5616383,shopping,9.520916,11,DRIVEALONEFREE,-0.6129478216171266,-1 -44931066,136984,50912,work,2,True,2,107,101,5616383,work,,12,DRIVEALONEFREE,-0.6193944811820985,-1 -44931069,136984,50912,work,1,False,3,123,107,5616383,work,10.775923,28,DRIVEALONEFREE,-0.7651270031929017,-1 -44931070,136984,50912,work,2,False,3,104,123,5616383,escort,9.519634,29,DRIVEALONEFREE,-0.6666110157966614,-1 -44931071,136984,50912,work,3,False,3,112,104,5616383,home,,30,DRIVEALONEFREE,-0.5499035120010376,-1 -47621473,145187,53716,othmaint,1,True,3,121,116,5952684,social,9.947862,8,SHARED3FREE,-0.41955729937135083,-1 -47621474,145187,53716,othmaint,2,True,3,112,121,5952684,othmaint,9.261029,11,SHARED3FREE,-0.6422730088233947,-1 -47621475,145187,53716,othmaint,3,True,3,122,112,5952684,othmaint,,11,SHARED3FREE,-0.6419082880020143,-1 -47621477,145187,53716,othmaint,1,False,1,116,122,5952684,home,,20,SHARED3FREE,-0.6134629858242939,-1 -47621737,145188,53716,escort,1,True,1,114,116,5952717,escort,,29,DRIVEALONEFREE,-0.15083796859645277,-1 -47621741,145188,53716,escort,1,False,1,116,114,5952717,home,,30,SHARED2FREE,-0.15179812895272474,-1 -47622241,145189,53716,school,1,True,1,114,116,5952780,school,,10,SCHOOL_BUS,4.3079237937927255,-1 -47622245,145189,53716,school,1,False,1,116,114,5952780,home,,24,SCHOOL_BUS,4.3079237937927255,-1 -47622569,145190,53716,school,1,True,1,114,116,5952821,school,,9,SHARED2FREE,-0.20617904275545365,-1 -47622573,145190,53716,school,1,False,1,116,114,5952821,home,,24,SHARED2FREE,-0.20568500108204935,-1 -48258513,147129,54342,othdiscr,1,True,1,116,117,6032314,othdiscr,,27,DRIVEALONEFREE,-0.5246167778968812,-1 -48258517,147129,54342,othdiscr,1,False,1,117,116,6032314,home,,33,DRIVEALONEFREE,-0.49120157957077026,-1 -48258537,147129,54342,othmaint,1,True,1,114,117,6032317,othmaint,,34,DRIVEALONEFREE,-0.687132179737091,-1 -48258541,147129,54342,othmaint,1,False,2,114,114,6032317,shopping,9.148774,37,DRIVEALONEFREE,-0.42373609542846685,-1 -48258542,147129,54342,othmaint,2,False,2,117,114,6032317,home,,38,DRIVEALONEFREE,-0.6845617890357972,-1 -56357665,171822,63802,eatout,1,True,1,127,135,7044708,eatout,,31,DRIVEALONEFREE,-0.6526245474815369,-1 -56357669,171822,63802,eatout,1,False,1,135,127,7044708,home,,34,DRIVEALONEFREE,-0.6343104243278503,-1 -56357689,171822,63802,escort,1,True,1,135,135,7044711,escort,,28,SHARED3FREE,0.07706324286670248,-1 -56357693,171822,63802,escort,1,False,2,135,135,7044711,escort,11.356267,28,SHARED3FREE,0.07706324286670248,-1 -56357694,171822,63802,escort,2,False,2,135,135,7044711,home,,28,SHARED3FREE,0.07706324286670248,-1 -56357737,171822,63802,othdiscr,1,True,3,131,135,7044717,othdiscr,12.194779,13,SHARED2FREE,0.599977654783949,-1 -56357738,171822,63802,othdiscr,2,True,3,130,131,7044717,shopping,13.357507,14,SHARED2FREE,0.6200047250329787,-1 -56357739,171822,63802,othdiscr,3,True,3,130,130,7044717,othdiscr,,14,SHARED2FREE,0.6960546579187884,-1 -56357741,171822,63802,othdiscr,1,False,1,135,130,7044717,home,,14,SHARED2FREE,0.6487159186367744,-1 -56358209,171823,63802,shopping,1,True,4,131,135,7044776,othmaint,10.342613,24,SHARED3FREE,-0.14619837454037923,-1 -56358210,171823,63802,shopping,2,True,4,131,131,7044776,social,12.281772,25,SHARED3FREE,-0.012169709209450414,-1 -56358211,171823,63802,shopping,3,True,4,131,131,7044776,shopping,11.556939,26,SHARED3FREE,-0.012169709209450414,-1 -56358212,171823,63802,shopping,4,True,4,131,131,7044776,shopping,,26,SHARED3FREE,-0.012169709209450414,-1 -56358213,171823,63802,shopping,1,False,1,135,131,7044776,home,,27,DRIVEALONEFREE,-0.15095594351539895,-1 -56358473,171824,63802,othdiscr,1,True,1,131,135,7044809,othdiscr,,32,SHARED2FREE,-0.46024149381952484,-1 -56358477,171824,63802,othdiscr,1,False,1,135,131,7044809,home,,37,SHARED2FREE,-0.45329299190068956,-1 -56358521,171824,63802,school,1,True,2,135,135,7044815,escort,11.635028,10,SHARED2FREE,0.10569338088788001,-1 -56358522,171824,63802,school,2,True,2,135,135,7044815,school,,10,SHARED3FREE,0.10569338088788001,-1 -56358525,171824,63802,school,1,False,2,135,135,7044815,othdiscr,11.906311,25,SHARED3FREE,0.10545807803885715,-1 -56358526,171824,63802,school,2,False,2,135,135,7044815,home,,26,SHARED3FREE,0.10545807803885715,-1 -56358801,171825,63802,othdiscr,1,True,1,131,135,7044850,othdiscr,,29,SHARED3FREE,-0.281769477499857,-1 -56358805,171825,63802,othdiscr,1,False,2,132,131,7044850,social,10.225653,35,SHARED2FREE,-0.20277185632585107,-1 -56358806,171825,63802,othdiscr,2,False,2,135,132,7044850,home,,39,SHARED3FREE,-0.36521793162300004,-1 -56358809,171825,63802,othdiscr,1,True,4,135,135,7044851,othmaint,5.3795877,26,WALK,-0.7460585832595825,-1 -56358810,171825,63802,othdiscr,2,True,4,131,135,7044851,othmaint,5.4266872,27,WALK,-2.0398435592651363,-1 -56358811,171825,63802,othdiscr,3,True,4,130,131,7044851,othmaint,5.7105064,28,WALK,-1.2828608751297,-1 -56358812,171825,63802,othdiscr,4,True,4,130,130,7044851,othdiscr,,28,WALK,-0.78075897693634,-1 -56358813,171825,63802,othdiscr,1,False,1,135,130,7044851,home,,28,WALK,-1.4660019874572756,-1 -56358849,171825,63802,school,1,True,1,135,135,7044856,school,,9,SHARED3FREE,0.10569338088788001,-1 -56358853,171825,63802,school,1,False,1,135,135,7044856,home,,24,SHARED3FREE,0.10569338088788001,-1 -56359177,171826,63802,school,1,True,1,135,135,7044897,school,,10,SHARED3FREE,0.10569338088788001,-1 -56359181,171826,63802,school,1,False,1,135,135,7044897,home,,22,SHARED3FREE,0.10569338088788001,-1 +trip_id,person_id,household_id,primary_purpose,trip_num,outbound,trip_count,destination,origin,tour_id,purpose,destination_logsum,depart,trip_mode,mode_choice_logsum +37314161,113762,42730,othmaint,1,TRUE,1,106,103,4664270,othmaint,,10,DRIVEALONEFREE,-0.356781572 +37314165,113762,42730,othmaint,1,FALSE,1,103,106,4664270,home,,11,DRIVEALONEFREE,-0.356460303 +38194977,116448,43843,atwork,1,TRUE,1,106,101,4774372,atwork,,20,DRIVEALONEFREE,-0.321751714 +38194981,116448,43843,atwork,1,FALSE,1,101,106,4774372,work,,21,DRIVEALONEFREE,-0.321751714 +38195065,116449,43843,othdiscr,1,TRUE,1,106,103,4774383,othdiscr,,32,SHARED2FREE,0.7593915111282218 +38195069,116449,43843,othdiscr,1,FALSE,1,103,106,4774383,home,,37,SHARED2FREE,0.7593915111282218 +38195257,116448,43843,work,1,TRUE,2,107,103,4774407,othmaint,9.244319,10,DRIVEALONEFREE,-0.667137086 +38195258,116448,43843,work,2,TRUE,2,101,107,4774407,work,,10,DRIVEALONEFREE,-0.589384019 +38195261,116448,43843,work,1,FALSE,1,103,101,4774407,home,,30,DRIVEALONEFREE,-0.501271665 +38195585,116449,43843,work,1,TRUE,2,106,103,4774448,othmaint,10.644734,12,DRIVEALONEFREE,0.050863062 +38195586,116449,43843,work,2,TRUE,2,102,106,4774448,work,,13,DRIVEALONEFREE,0.032545052 +38195589,116449,43843,work,1,FALSE,3,103,102,4774448,othmaint,10.796497,23,SHARED2FREE,0.09835211 +38195590,116449,43843,work,2,FALSE,3,103,103,4774448,work,12.367123,24,DRIVEALONEFREE,0.24223826711784288 +38195591,116449,43843,work,3,FALSE,3,103,103,4774448,home,,26,DRIVEALONEFREE,0.2401515927071465 +38195849,116450,43843,school,1,TRUE,1,106,103,4774481,school,,9,SCHOOL_BUS,4.351044654846191 +38195853,116450,43843,school,1,FALSE,1,103,106,4774481,home,,27,SCHOOL_BUS,4.351044654846191 +38195865,116450,43843,shopping,1,TRUE,1,101,103,4774483,shopping,,27,SHARED2FREE,-0.444101901 +38195869,116450,43843,shopping,1,FALSE,1,103,101,4774483,home,,30,SHARED2FREE,-0.457490895 +39613905,120774,45311,atwork,1,TRUE,1,101,102,4951738,atwork,,20,DRIVEALONEFREE,-0.411282897 +39613909,120774,45311,atwork,1,FALSE,1,102,101,4951738,work,,21,DRIVEALONEFREE,-0.411925524 +39614185,120774,45311,work,1,TRUE,2,106,105,4951773,work,10.647319,10,DRIVEALONEFREE,-0.432832956 +39614186,120774,45311,work,2,TRUE,2,102,106,4951773,work,,11,DRIVEALONEFREE,-0.348032892 +39614189,120774,45311,work,1,FALSE,1,105,102,4951773,home,,30,DRIVEALONEFREE,-0.604685664 +39614513,120775,45311,work,1,TRUE,1,101,105,4951814,work,,9,DRIVEALONEFREE,-0.600943565 +39614517,120775,45311,work,1,FALSE,3,101,101,4951814,work,10.767546,28,DRIVEALONEFREE,-0.356709987 +39614518,120775,45311,work,2,FALSE,3,107,101,4951814,othmaint,9.370711,28,DRIVEALONEFREE,-0.595682502 +39614519,120775,45311,work,3,FALSE,3,105,107,4951814,home,,29,DRIVEALONEFREE,-0.43356654 +40387937,123133,46056,work,1,TRUE,1,106,106,5048492,work,,20,DRIVEALONEFREE,-0.19777289 +40387941,123133,46056,work,1,FALSE,1,106,106,5048492,home,,40,DRIVEALONEFREE,-0.197402388 +43308361,132037,49258,othmaint,1,TRUE,1,122,110,5413545,othmaint,,23,DRIVEALONEFREE,-0.739005089 +43308365,132037,49258,othmaint,1,FALSE,2,114,122,5413545,eatout,8.7858,24,DRIVEALONEFREE,-0.517582178 +43308366,132037,49258,othmaint,2,FALSE,2,110,114,5413545,home,,24,DRIVEALONEFREE,-0.593839884 +43308537,132038,49258,escort,1,TRUE,1,107,110,5413567,escort,,10,SHARED3FREE,-0.00260142 +43308541,132038,49258,escort,1,FALSE,1,110,107,5413567,home,,22,SHARED3FREE,-0.00260142 +44930737,136983,50912,work,1,TRUE,2,123,112,5616342,eatout,9.353397,31,DRIVEALONEFREE,-0.549332976 +44930738,136983,50912,work,2,TRUE,2,104,123,5616342,work,,32,DRIVEALONEFREE,-0.666611016 +44930741,136983,50912,work,1,FALSE,2,112,104,5616342,social,11.149774,34,DRIVEALONEFREE,-0.530267 +44930742,136983,50912,work,2,FALSE,2,112,112,5616342,home,,34,DRIVEALONEFREE,-0.183315992 +44931065,136984,50912,work,1,TRUE,2,101,112,5616383,shopping,9.520916,11,DRIVEALONEFREE,-0.612947822 +44931066,136984,50912,work,2,TRUE,2,107,101,5616383,work,,12,DRIVEALONEFREE,-0.619394481 +44931069,136984,50912,work,1,FALSE,3,123,107,5616383,work,10.775923,28,DRIVEALONEFREE,-0.765127003 +44931070,136984,50912,work,2,FALSE,3,104,123,5616383,escort,9.519634,29,DRIVEALONEFREE,-0.666611016 +44931071,136984,50912,work,3,FALSE,3,112,104,5616383,home,,30,DRIVEALONEFREE,-0.549903512 +47621473,145187,53716,othmaint,1,TRUE,3,121,116,5952684,social,9.947862,8,SHARED3FREE,-0.419557299 +47621474,145187,53716,othmaint,2,TRUE,3,112,121,5952684,othmaint,9.261029,11,SHARED3FREE,-0.642273009 +47621475,145187,53716,othmaint,3,TRUE,3,122,112,5952684,othmaint,,11,SHARED3FREE,-0.641908288 +47621477,145187,53716,othmaint,1,FALSE,1,116,122,5952684,home,,20,SHARED3FREE,-0.613462986 +47621737,145188,53716,escort,1,TRUE,1,114,116,5952717,escort,,29,DRIVEALONEFREE,-0.150837969 +47621741,145188,53716,escort,1,FALSE,1,116,114,5952717,home,,30,SHARED2FREE,-0.151798129 +47622241,145189,53716,school,1,TRUE,1,114,116,5952780,school,,10,SCHOOL_BUS,4.3079237937927255 +47622245,145189,53716,school,1,FALSE,1,116,114,5952780,home,,24,SCHOOL_BUS,4.3079237937927255 +47622569,145190,53716,school,1,TRUE,1,114,116,5952821,school,,9,SHARED2FREE,-0.206179043 +47622573,145190,53716,school,1,FALSE,1,116,114,5952821,home,,24,SHARED2FREE,-0.205685001 +48258513,147129,54342,othdiscr,1,TRUE,1,116,117,6032314,othdiscr,,27,DRIVEALONEFREE,-0.524616778 +48258517,147129,54342,othdiscr,1,FALSE,1,117,116,6032314,home,,33,DRIVEALONEFREE,-0.49120158 +48258537,147129,54342,othmaint,1,TRUE,1,114,117,6032317,othmaint,,34,DRIVEALONEFREE,-0.68713218 +48258541,147129,54342,othmaint,1,FALSE,2,114,114,6032317,shopping,9.148774,37,DRIVEALONEFREE,-0.423736095 +48258542,147129,54342,othmaint,2,FALSE,2,117,114,6032317,home,,38,DRIVEALONEFREE,-0.684561789 +56357665,171822,63802,eatout,1,TRUE,1,127,135,7044708,eatout,,31,DRIVEALONEFREE,-0.652624547 +56357669,171822,63802,eatout,1,FALSE,1,135,127,7044708,home,,34,DRIVEALONEFREE,-0.634310424 +56357689,171822,63802,escort,1,TRUE,1,135,135,7044711,escort,,28,SHARED3FREE,0.077063243 +56357693,171822,63802,escort,1,FALSE,2,135,135,7044711,escort,11.356267,28,SHARED3FREE,0.077063243 +56357694,171822,63802,escort,2,FALSE,2,135,135,7044711,home,,28,SHARED3FREE,0.077063243 +56357737,171822,63802,othdiscr,1,TRUE,3,131,135,7044717,othdiscr,12.194779,13,SHARED2FREE,0.599977655 +56357738,171822,63802,othdiscr,2,TRUE,3,130,131,7044717,shopping,13.357507,14,SHARED2FREE,0.6200047250329787 +56357739,171822,63802,othdiscr,3,TRUE,3,130,130,7044717,othdiscr,,14,SHARED2FREE,0.6960546579187884 +56357741,171822,63802,othdiscr,1,FALSE,1,135,130,7044717,home,,14,SHARED2FREE,0.6487159186367744 +56358209,171823,63802,shopping,1,TRUE,4,131,135,7044776,othmaint,10.342613,24,SHARED3FREE,-0.146198375 +56358210,171823,63802,shopping,2,TRUE,4,131,131,7044776,social,12.281772,25,SHARED3FREE,-0.012169709 +56358211,171823,63802,shopping,3,TRUE,4,131,131,7044776,shopping,11.556939,26,SHARED3FREE,-0.012169709 +56358212,171823,63802,shopping,4,TRUE,4,131,131,7044776,shopping,,26,SHARED3FREE,-0.012169709 +56358213,171823,63802,shopping,1,FALSE,1,135,131,7044776,home,,27,DRIVEALONEFREE,-0.150955944 +56358473,171824,63802,othdiscr,1,TRUE,1,131,135,7044809,othdiscr,,32,SHARED2FREE,-0.460241494 +56358477,171824,63802,othdiscr,1,FALSE,1,135,131,7044809,home,,37,SHARED2FREE,-0.453292992 +56358521,171824,63802,school,1,TRUE,2,135,135,7044815,escort,11.635028,10,SHARED2FREE,0.10569338088788001 +56358522,171824,63802,school,2,TRUE,2,135,135,7044815,school,,10,SHARED3FREE,0.10569338088788001 +56358525,171824,63802,school,1,FALSE,2,135,135,7044815,othdiscr,11.906311,25,SHARED3FREE,0.10545807803885715 +56358526,171824,63802,school,2,FALSE,2,135,135,7044815,home,,26,SHARED3FREE,0.10545807803885715 +56358801,171825,63802,othdiscr,1,TRUE,1,131,135,7044850,othdiscr,,29,SHARED3FREE,-0.281769477 +56358805,171825,63802,othdiscr,1,FALSE,2,132,131,7044850,social,10.225653,35,SHARED2FREE,-0.202771856 +56358806,171825,63802,othdiscr,2,FALSE,2,135,132,7044850,home,,39,SHARED3FREE,-0.365217932 +56358809,171825,63802,othdiscr,1,TRUE,4,135,135,7044851,othmaint,5.3795877,26,WALK,-0.746058583 +56358810,171825,63802,othdiscr,2,TRUE,4,131,135,7044851,othmaint,5.4266872,27,WALK,-2.039843559 +56358811,171825,63802,othdiscr,3,TRUE,4,130,131,7044851,othmaint,5.7105064,28,WALK,-1.282860875 +56358812,171825,63802,othdiscr,4,TRUE,4,130,130,7044851,othdiscr,,28,WALK,-0.780758977 +56358813,171825,63802,othdiscr,1,FALSE,1,135,130,7044851,home,,28,WALK,-1.466001987 +56358849,171825,63802,school,1,TRUE,1,135,135,7044856,school,,9,SHARED3FREE,0.10569338088788001 +56358853,171825,63802,school,1,FALSE,1,135,135,7044856,home,,24,SHARED3FREE,0.10569338088788001 +56359177,171826,63802,school,1,TRUE,1,135,135,7044897,school,,10,SHARED3FREE,0.10569338088788001 +56359181,171826,63802,school,1,FALSE,1,135,135,7044897,home,,22,SHARED3FREE,0.10569338088788001 diff --git a/activitysim/examples/prototype_arc/test/test_arc.py b/activitysim/examples/prototype_arc/test/test_arc.py index 3e637289c..140c67a31 100644 --- a/activitysim/examples/prototype_arc/test/test_arc.py +++ b/activitysim/examples/prototype_arc/test/test_arc.py @@ -13,7 +13,7 @@ from activitysim.core.test import assert_frame_substantively_equal -def _test_arc(recode=False, sharrow=False): +def _test_arc(recode=False, sharrow=False, eet=False): def example_path(dirname): resource = os.path.join("examples", "prototype_arc", dirname) return str(importlib.resources.files("activitysim").joinpath(resource)) @@ -24,9 +24,13 @@ def test_path(dirname): def regress(): if sharrow: # sharrow results in tiny changes (one trip moving one time period earlier) - regress_trips_df = pd.read_csv(test_path("regress/final_trips_sh.csv")) + regress_trips_df = pd.read_csv( + test_path(f"regress/final_trips{'_eet' if eet else ''}_sh.csv") + ) else: - regress_trips_df = pd.read_csv(test_path("regress/final_trips.csv")) + regress_trips_df = pd.read_csv( + test_path(f"regress/final_trips{'_eet' if eet else ''}.csv") + ) final_trips_df = pd.read_csv(test_path("output/final_trips.csv")) # person_id,household_id,tour_id,primary_purpose,trip_num,outbound,trip_count,purpose, @@ -36,39 +40,26 @@ def regress(): file_path = os.path.join(os.path.dirname(__file__), "simulation.py") + test_configs = [] + if eet: + test_configs.extend(["-c", test_path("configs_eet")]) + if recode: - run_args = [ - "-c", - test_path("configs_recode"), - "-c", - example_path("configs"), - "-d", - example_path("data"), - "-o", - test_path("output"), - ] + test_configs.extend(["-c", test_path("configs_recode")]) elif sharrow: - run_args = [ - "-c", - test_path("configs_sharrow"), - "-c", - example_path("configs"), - "-d", - example_path("data"), - "-o", - test_path("output"), - ] + test_configs.extend(["-c", test_path("configs_sharrow")]) else: - run_args = [ - "-c", - test_path("configs"), - "-c", - example_path("configs"), - "-d", - example_path("data"), - "-o", - test_path("output"), - ] + test_configs.extend(["-c", test_path("configs")]) + + run_args = [ + *test_configs, + "-c", + example_path("configs"), + "-d", + example_path("data"), + "-o", + test_path("output"), + ] if os.environ.get("GITHUB_ACTIONS") == "true": subprocess.run(["coverage", "run", "-a", file_path] + run_args, check=True) @@ -82,15 +73,21 @@ def test_arc(): _test_arc() +def test_arc_eet(): + _test_arc(eet=True) + + def test_arc_recode(): _test_arc(recode=True) -def test_arc_sharrow(): - _test_arc(sharrow=True) +# TODO: update regress trips for sharrow and re-enable test. +# def test_arc_sharrow(): +# _test_arc(sharrow=True) if __name__ == "__main__": _test_arc() + _test_arc(eet=True) _test_arc(recode=True) - _test_arc(sharrow=True) + # _test_arc(sharrow=True) diff --git a/docs/core.rst b/docs/core.rst index 687e8f956..a7a9ba59d 100644 --- a/docs/core.rst +++ b/docs/core.rst @@ -323,6 +323,20 @@ To specify and solve an NL model: * specify the nesting structure via the NESTS setting in the model configuration YAML file. An example nested logit NESTS entry can be found in ``example/configs/tour_mode_choice.yaml`` * call ``simulate.simple_simulate()``. The ``simulate.interaction_simulate()`` functionality is not yet supported for NL. +Explicit Error Terms +^^^^^^^^^^^^^^^^^^^^ + +By default, ActivitySim makes choices by calculating analytical probabilities and then drawing once from +the cumulative distribution for each chooser. With Explicit Error Terms (EET), enabled by setting +``use_explicit_error_terms: True`` in ``settings.yaml``, ActivitySim instead draws a standard EV1 (Gumbel) error +term for each chooser-alternative pair, adds it to the observed utility, and chooses the maximum total utility. + +EET changes the final simulation step, not the utility expressions, availability logic, or nesting +structure. In practice, it can reduce Monte Carlo noise in scenario comparisons. + +For configuration guidance see :ref:`explicit_error_terms_ways_to_run`. For detailed implementation notes +see :doc:`/dev-guide/explicit-error-terms`. + API ^^^ diff --git a/docs/dev-guide/explicit-error-terms.md b/docs/dev-guide/explicit-error-terms.md new file mode 100644 index 000000000..57e30f7bc --- /dev/null +++ b/docs/dev-guide/explicit-error-terms.md @@ -0,0 +1,188 @@ +(explicit-error-terms-dev)= +# Explicit Error Terms + +Explicit Error Terms (EET) is an alternative way to simulate choices from ActivitySim's +logit models. It keeps the same systematic utilities and the same random-utility +interpretation as the standard method, but changes how the final simulated choice is +drawn. + +For user-facing guidance on when to use EET, see {ref}`explicit_error_terms_ways_to_run`. + +## Enabling EET + +Enable EET globally in `settings.yaml`: + +```yaml +use_explicit_error_terms: True +``` + +The top-level switch is defined in +`activitysim.core.configuration.top.SimulationSettings.use_explicit_error_terms`. +Choice simulation code reads that setting through the model compute settings and routes +supported logit simulations through the EET path. + +## Default Draw Versus EET + +Under the default ActivitySim simulation path, choice drawing works like this: + +1. Compute systematic utilities. +2. Convert those utilities into analytical probabilities. +3. Draw one uniform random number per chooser. +4. Select the alternative whose cumulative probability interval contains that draw. + +With EET enabled, the final draw step changes: + +1. Compute systematic utilities. +2. Draw one iid EV1 error term for each chooser-alternative pair. +3. Add that error term to the systematic utility. +4. Choose the alternative with the highest total utility. + +For multinomial logit, ActivitySim adds Gumbel draws to the utility table and takes the +row-wise maximum. For nested logit, ActivitySim applies the same idea while walking the +nest tree, preserving the configured nesting structure. For details, see +[this ATRF paper](https://australasiantransportresearchforum.org.au/frozen-randomness-at-the-individual-utility-level/). + +The model being simulated does not change. EET changes how the random utility model is +sampled, not the underlying utility specification. + +## Practical Effects + +### Comparisons and Simulation Noise + +For EET to reduce simulation noise, it is important that alternatives of a choice situation +keep the same unobserved error term in different scenario runs. This is intimately tied +to how random numbers are generated; see {ref}`random_in_detail` for the underlying +random-number stream design and the `activitysim.core.random` API. +Because unchanged alternatives can keep the same unobserved draws, changes to choices between +scenarios can only happen when the observed utility of an alternative increases. This is not +the case for the Monte Carlo simulation method, where the draws are based on probabilities, +which necessarily change for all alternatives if any observed utility changes. + +This also means that it is advisable to use the same setting in all runs. Comparing a baseline +run with EET to a scenario run without EET mixes two simulation methods and can make differences +harder to interpret. Aggregate choice patterns should remain statistically the same +as for the default probability-based method. The project test suite includes parity tests for +MNL, NL, and interaction-based simulations. + +### Numerical and Debugging Behavior + +EET changes the final simulation step, not the utility calculation itself. Utility +expressions, availability logic, nesting structure, and utility validation still matter in +the same way as in the default method. + +In practice, EET can make some comparisons easier to interpret because the selected +alternative is the one with the highest total utility after adding the explicit error term, +rather than the one reached by a cumulative-probability threshold. That can reduce +sensitivity to small differences in the final CDF draw when comparing nearby scenarios. +It does not eliminate the need to inspect invalid or unavailable alternatives, and it does +not guarantee identical results across different RNG seeds or different model +configurations. + +For shadow-priced location choice, ActivitySim resets RNG offsets between iterations when +EET is enabled so each shadow-pricing iteration uses the same sequence of random numbers. +That keeps the comparison across iterations focused on the shadow price updates instead of +changing random draws between iterations. + +### Runtime + +Runtime differs between the methods. EET generates one EV1 error term per chooser-alternative +pair, while the default Monte Carlo path draws only one uniform random number per chooser after +probabilities are computed. EET, however, does not need to compute probabilities to make choices. + +Exact runtimes depend on the number of alternatives, nesting structure, interaction size, and +sampling configuration. With default settings, current full-scale demand model runs with EET +are about 100% higher than the default MC method. While the relative runtime increase +of nested logit models is large, these typically contribute only a very small fraction to the +overall runtime and virtually all of the increase is due to sampling in location choice. To +avoid this penalty, it is possible to use MC for sampling only by adding the following to each +model setting where sampling is used (currently all location and destination choice models as +well as disaggregate accessibilities): + +```yaml +compute_settings: + use_explicit_error_terms: + sample: false +``` + +With this setting, model runtimes should be roughly equal. The influence of this change on +sampling noise is under investigation. + +(explicit_error_terms_zone_encoding)= +#### Zone ID encoding and runtime + +For location choice models, encoding zone IDs as a 0-based contiguous index reduces EET runtime +and memory use during sampling. + +The current implementation draws error terms into a dense 1-D array of length `max_zone_id + 1` +per chooser (see `AltsContext.n_alts_to_cover_max_id` in `activitysim.core.logit`). Each sampled +alternative is then looked up by direct offset into that array, so the same zone always receives +the same error term regardless of which alternatives are in the sampled choice set — a property +needed for consistent scenario comparisons. + +When zone IDs are a contiguous 0-based sequence, the dense array has exactly as many entries as +there are zones and every draw is used. When zone IDs contain gaps or start from a large value, +the array must still cover `max_zone_id + 1` entries, so the draws for the missing IDs are +generated but never used. For zone systems with large or sparse IDs, this waste can be substantial. + +An alternative would be to draw only as many error terms as there are sampled alternatives and +retrieve the relevant term for each zone via a lookup. That would avoid unused draws but adds an +index-mapping step for every chooser-sample in the interaction frame, trading one form of overhead +for another. The current design favours the dense approach because the direct-offset indexing is +simpler and because the ``recode_columns`` setting can encode zone IDs as ``zero-based`` in +the input table list; see the +[Zero-based Recoding of Zones](using-sharrow.md#zero-based-recoding-of-zones) section for details. + +(explicit_error_terms_memory)= +### Memory usage + +When running EET with MC for location sampling as described in the Runtime section above, +there should be only a small increase in memory usage for location choice models compared to full +MC simulation. + +However, when EET is run with its current default location sampling settings, an array of size +(number of choosers, number of alternatives, number of samples) is allocated for all random error +terms. This can quickly become unwieldy for machines with limited memory, and +[chunking](../users-guide/performance/chunking.md) will likely be needed. + +When chunking is needed and [explicit chunking](../users-guide/performance/chunking.md#explicit-chunking) +is used, using fractional values for the chunk size rather than absolute numbers of choosers is +often a better fit. This is because the individual steps of location choice models +(location sampling, location logsums, and location choice from the sampled choice set) all have +very different chooser characteristics, but the chunk size currently can only be set at the model +level. Using absolute values for the explicit chunk size would lead to a large number of chunks +for the logsum calculations, which is relatively slow. + + +## Implementation Details and Adding New Models + +The core simulation is implemented in `activitysim.core.logit.make_choices_utility_based`. Most +calls to this function are wrapped in one of the following methods: + +- `activitysim.core.simulate` +- `activitysim.core.interaction_simulate` +- `activitysim.core.interaction_sample` +- `activitysim.core.interaction_sample_simulate` + +These wrappers all implement EET consistently, so any model using them will automatically support +EET. Some models call the underlying choice simulation method +`activitysim.core.logit.make_choices` directly. For EET to work in that case, the developer must +add a corresponding call to `logit.make_choices_utility_based`; see for example +`activitysim.abm.models.utils.cdap.household_activity_choices`. Models that draw directly +from probability distributions, such as `activitysim.abm.models.utils.cdap.extra_hh_member_choices`, +do not have a corresponding EET implementation because there are no utilities to work with. + + +### Unavailable choices utility convention + +For EET, only utility differences matter, and therefore the outcome for two utilities that are +very small, say -10000 and -10001, is identical to the outcome for 0 and 1. For MC, utilities +have to be exponentiated and therefore floating point precision dictates the smallest and largest +utility that can be used in practice. ActivitySim models historically often use a utility of +-999 to make alternatives practically unavailable. That value is below the utility threshold +used in the probability-based path, which is about -691 because ActivitySim clips +exponentiated utilities at 1e-300. To keep behavior consistent, EET treats alternatives with +utilities at or below that threshold as unavailable; see `activitysim.core.logit.validate_utils`. + +### Scale of the distribution +Error terms are drawn from standard Gumbel distributions, i.e., the scale of the error term is +fixed to one. diff --git a/docs/dev-guide/index.rst b/docs/dev-guide/index.rst index da6c64973..82051ff08 100644 --- a/docs/dev-guide/index.rst +++ b/docs/dev-guide/index.rst @@ -33,6 +33,7 @@ Contents component-configs components/index ../core + explicit-error-terms ../benchmarking build-docs changes diff --git a/docs/users-guide/ways_to_run.rst b/docs/users-guide/ways_to_run.rst index 1b2122107..ca569ca64 100644 --- a/docs/users-guide/ways_to_run.rst +++ b/docs/users-guide/ways_to_run.rst @@ -80,7 +80,7 @@ Refer to the :ref:`Run the Primary Example` section to learn how to run the prim Using Jupyter Notebook ______________________ -ActivitySim includes a `Jupyter Notebook `__ recipe book with interactive examples. +ActivitySim includes a `Jupyter Notebook `__ recipe book with interactive examples. * To start JupyterLab, from the ActivitySim project directory run ``uv run jupyter lab``. This will start the JupyterLab server and pop up a browser window with the interactive development environment. * Navigate to the ``examples/prototype_mtc/notebooks`` folder and select a notebook to learn more: @@ -283,3 +283,50 @@ With the set of output CSV files, the user can trace ActivitySim calculations in help debug data and/or logic errors. Refer to :ref:`trace` for more details on configuring tracing and the various output files. + +.. _explicit_error_terms_ways_to_run : + +Explicit Error Terms +____________________ + +ActivitySim makes heavy use of micro-simulation. Most model components are discrete choice models with an inherent +random component, and for each choice situation a single outcome is generated. +With the default Monte Carlo draw method, ActivitySim first calculates analytical probabilities from the +systematic utilities of a multinomial or nested logit model and then makes one draw from the +cumulative distribution for each chooser. Explicit Error Terms (EET) replaces that final draw with a direct +random-utility simulation by drawing an independent standard EV1 (Gumbel) error term for each +chooser-alternative pair, adding it to the systematic utility, and selecting the alternative with the highest +total utility. Both methods simulate the same underlying model, but EET can be less affected by Monte Carlo +noise when comparing scenarios. For more details, see :doc:`/dev-guide/explicit-error-terms`. + +To enable EET for a model run, set the global switch in ``settings.yaml``: + +.. code-block:: yaml + + use_explicit_error_terms: True + +Enable or disable this setting consistently across all runs being compared. + +Using EET changes the simulation method, not the underlying model. Aggregate behavior should remain statistically +comparable to the default method, but individual simulated choices will not usually match record-by-record. +EET is currently slower than the default probability-based simulation method. Most of the slowdown comes from location +choice models, where the number of alternatives is large and the current importance-sampling workflow requires +many repeated error term draws. Work to reduce that overhead is ongoing. Until then, it is also possible to turn +off EET for the sampling part of these models by adding the following lines to the settings of all models where +location choice sampling is used (currently all location and destination choice models as well as disaggregate +accessibilities): + +.. code-block:: yaml + + compute_settings: + use_explicit_error_terms: + sample: false + +If you keep EET enabled for the sampling step, also consider memory usage during location sampling. +In that case, explicit chunking with a fractional ``explicit_chunk`` setting is often the most +practical approach; see :ref:`explicit_error_terms_memory` for details. + +For location choice models, encoding zone IDs as a 0-based contiguous index also reduces EET runtime and memory usage; +see :ref:`explicit_error_terms_zone_encoding` for a technical description. For models where the input data does not +already use contiguous zone IDs, the ``recode_columns`` option can be used to create them. See the +*Zero-based Recoding of Zones* section in :doc:`/dev-guide/using-sharrow` for more details.