Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fit_gev relative_fit_test check and add BIC tests #70

Merged
merged 1 commit into from
Aug 21, 2024
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
2 changes: 1 addition & 1 deletion unseen/eva.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def _fit(
result = check_gev_relative_fit(
data, L1, L2, test=relative_fit_test, alpha=alpha
)
if result is False:
if not result:
warnings.warn(
f"{relative_fit_test} test failed. Returning stationary parameters."
)
Expand Down
34 changes: 34 additions & 0 deletions unseen/tests/test_eva.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,40 @@ def test_fit_ns_gev_3d():
assert np.all(theta.isel(theta=2) > 0) # Positive trend in location


def test_fit_ns_gev_1d_relative_fit_test_bic_trend():
"""Run non-stationary fit & check 'BIC' test returns nonstationary params."""
data, _ = example_da_gev_1d()
# Add a large positive linear trend
data = add_example_gev_trend(data)
data = add_example_gev_trend(data)
covariate = np.arange(data.time.size, dtype=int)

theta = fit_gev(
data,
stationary=False,
core_dim="time",
covariate=covariate,
relative_fit_test="bic",
)
assert np.all(theta[2] > 0) # Positive trend in location


def test_fit_ns_gev_1d_relative_fit_test_bic_no_trend():
"""Run non-stationary fit & check 'BIC' test returns stationary params."""
data, _ = example_da_gev_1d()
covariate = np.arange(data.time.size, dtype=int)

theta = fit_gev(
data,
stationary=False,
core_dim="time",
covariate=covariate,
relative_fit_test="bic",
)
assert np.all(theta[2] == 0) # No trend in location
assert np.all(theta[4] == 0) # No trend in scale


def test_fit_ns_gev_3d_dask():
"""Run non-stationary fit using 3D dask array & check results."""
data, _ = example_da_gev_3d_dask()
Expand Down
Loading