Skip to content

Commit

Permalink
Merge pull request #594 from camsys/develop
Browse files Browse the repository at this point in the history
Repair tests and examples
  • Loading branch information
jpn-- authored Sep 2, 2022
2 parents 96bf698 + f14c078 commit 7ead422
Show file tree
Hide file tree
Showing 15 changed files with 242 additions and 2,867 deletions.
33 changes: 21 additions & 12 deletions activitysim/estimation/test/test_larch_estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,18 @@ def est_data():
os.chdir(cwd)


def _regression_check(dataframe_regression, df, basename=None):
def _regression_check(dataframe_regression, df, basename=None, rtol=None):
if rtol is None:
rtol = 0.1
dataframe_regression.check(
df.select_dtypes("number")
.drop(columns=["holdfast"], errors="ignore")
.clip(-9e9, 9e9),
# pandas 1.3 handles int8 dtypes as actual numbers, so holdfast needs to be dropped manually
# we're dropping it not adding to the regression check so older pandas will also work.
basename=basename,
default_tolerance=dict(atol=1e-6, rtol=0.1)
# set a little loose, as there is sometimes a little variance in these
default_tolerance=dict(atol=1e-6, rtol=rtol)
# can set a little loose, as there is sometimes a little variance in these
# results when switching backend implementations. We're checking all
# the parameters and the log likelihood, so modest variance in individual
# parameters, especially those with high std errors, is not problematic.
Expand Down Expand Up @@ -89,16 +91,23 @@ def test_simple_simulate(est_data, num_regression, dataframe_regression, name, m


@pytest.mark.parametrize(
"name,method",
"name,method,rtol",
[
("workplace_location", "SLSQP"),
("school_location", "SLSQP"),
("non_mandatory_tour_destination", "SLSQP"),
("atwork_subtour_destination", "BHHH"),
("trip_destination", "SLSQP"),
("workplace_location", "SLSQP", None),
("school_location", "SLSQP", None),
("non_mandatory_tour_destination", "SLSQP", None),
("atwork_subtour_destination", "BHHH", None),
("trip_destination", "SLSQP", 0.12),
# trip_destination model has unusual parameter variance on a couple
# parameters when switching platforms, possibly related to default data
# types and high standard errors. Most parameters and the overall
# log likelihoods behave fine, suggesting it is just a numerical
# precision issue.
],
)
def test_location_model(est_data, num_regression, dataframe_regression, name, method):
def test_location_model(
est_data, num_regression, dataframe_regression, name, method, rtol
):
from activitysim.estimation.larch import component_model, update_size_spec

m, data = component_model(name, return_data=True)
Expand All @@ -109,7 +118,7 @@ def test_location_model(est_data, num_regression, dataframe_regression, name, me
{"loglike_prior": loglike_prior, "loglike_converge": r.loglike},
basename=f"test_loc_{name}_loglike",
)
_regression_check(dataframe_regression, m.pf)
_regression_check(dataframe_regression, m.pf, rtol=rtol)
size_spec = update_size_spec(
m,
data,
Expand All @@ -136,7 +145,7 @@ def test_location_model(est_data, num_regression, dataframe_regression, name, me
],
)
def test_scheduling_model(est_data, num_regression, dataframe_regression, name, method):
from activitysim.estimation.larch import component_model, update_size_spec
from activitysim.estimation.larch import component_model

m, data = component_model(name, return_data=True)
m.load_data()
Expand Down
5 changes: 4 additions & 1 deletion activitysim/examples/example_manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,9 @@
placeholder_psrc
- placeholder_sandag/configs_2_zone
- placeholder_sandag/data_2
- placeholder_sandag/data_3/maz_to_maz_bike.csv
data_2/maz_to_maz_bike.csv
# the original data for data_2 was corrupted, but there's no need to store this file twice in the repo
- placeholder_sandag/output_2

- name: placeholder_sandag_2_zone_full
Expand Down Expand Up @@ -870,7 +873,7 @@
2d481ec20f69204fc02a259d2d7c4e3d955d6a83b13d7bae920c9c7f8e28c517
- prototype_sandag_xborder/data/persons_xborder.csv # this matches the local tours_xborder, see below
- https://raw.githubusercontent.com/activitysim/activitysim_resources/master/sandag_xborder/tap_lines.csv
data/tap_lines.csv
data/tap_lines.csv
750745a33f39963f0c3e4efa6135ff89fb7dd49f58f17cdbd90d62e7057fea01
- https://raw.githubusercontent.com/activitysim/activitysim_resources/master/sandag_xborder/taps.csv
data/taps.csv
Expand Down
Loading

0 comments on commit 7ead422

Please sign in to comment.