Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions activitysim/estimation/larch/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,20 @@ def apply_coefficients(coefficients, model, minimum=None, maximum=None):
explicit_value_parameters(model)
for i in coefficients.itertuples():
if i.Index in model:
holdfast = (i.constrain == "T")
if holdfast:
minimum_ = i.value
maximum_ = i.value
else:
minimum_ = minimum
maximum_ = maximum
model.set_value(
i.Index,
value=i.value,
initvalue=i.value,
holdfast=(i.constrain == "T"),
minimum=minimum,
maximum=maximum,
holdfast=holdfast,
minimum=minimum_,
maximum=maximum_,
)


Expand Down
2 changes: 1 addition & 1 deletion activitysim/estimation/larch/location_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def _read_csv(filename, **kwargs):
if size_spec.loc[i, q] != 0
)

apply_coefficients(coefficients, m)
apply_coefficients(coefficients, m, minimum=-25, maximum=25)
apply_coefficients(size_coef, m, minimum=-6, maximum=6)

m.choice_co_code = "override_choice"
Expand Down
59 changes: 26 additions & 33 deletions activitysim/estimation/test/test_larch_estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,43 @@
import pandas as pd
import pytest
import subprocess
import tempfile

from activitysim.cli.create import get_example


@pytest.fixture(scope="module")
def est_data():
# !activitysim create -e example_estimation_sf -d _test_est
if os.path.exists("_test_est"):
retain_test_data = True
else:
retain_test_data = False
get_example("example_estimation_sf", "_test_est")

# %cd _test_est

cwd = os.getcwd()
tempdir = tempfile.TemporaryDirectory()
os.chdir(tempdir.name)

get_example("example_estimation_sf", "_test_est")
os.chdir("_test_est")

# !activitysim run -c configs_estimation/configs -c configs -o output -d data_sf
if not retain_test_data:
print(f"List of files now in {os.getcwd()}")
subprocess.run(["find", "."])
print(f"\n\nrunning activitysim estimation mode in {os.getcwd()}")
subprocess.run(
[
"activitysim",
"run",
"-c",
"configs_estimation/configs",
"-c",
"configs",
"-o",
"output",
"-d",
"data_sf",
],
)
else:
print(f"reusing existing data in {os.getcwd()}")
print(f"List of files now in {os.getcwd()}")
subprocess.run(["find", "."])
print(f"\n\nrunning activitysim estimation mode in {os.getcwd()}")
subprocess.run(
[
"activitysim",
"run",
"-c",
"configs_estimation/configs",
"-c",
"configs",
"-o",
"output",
"-d",
"data_sf",
],
)

yield os.getcwd()

os.chdir(cwd)
# if not retain_test_data:
# os.remove("_test_est")


def _regression_check(dataframe_regression, df, basename=None):
Expand All @@ -54,7 +47,7 @@ def _regression_check(dataframe_regression, df, basename=None):
# 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=1e-2)
default_tolerance=dict(atol=1e-6, rtol=5e-2)
# set a little loose, as there is sometimes a little variance in these
# results when switching backend implementations.
)
Expand Down Expand Up @@ -100,7 +93,7 @@ def test_location_model(est_data, num_regression, dataframe_regression, name, me
m, data = component_model(name, return_data=True)
m.load_data()
loglike_prior = m.loglike()
r = m.maximize_loglike(method=method)
r = m.maximize_loglike(method=method, options={'maxiter': 1000})
num_regression.check(
{"loglike_prior": loglike_prior, "loglike_converge": r.loglike},
basename=f"test_loc_{name}_loglike",
Expand All @@ -112,7 +105,7 @@ def test_location_model(est_data, num_regression, dataframe_regression, name, me
dataframe_regression.check(
size_spec,
basename=f"test_loc_{name}_size_spec",
default_tolerance=dict(atol=1e-6, rtol=1e-2)
default_tolerance=dict(atol=1e-6, rtol=5e-2)
# set a little loose, as there is sometimes a little variance in these
# results when switching backend implementations.
)
Expand Down
Loading