-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Report all issues rather than stop at first one. (#450)
- Loading branch information
Showing
2 changed files
with
128 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import pytest | ||
import numpy as np | ||
from estimagic.exceptions import InvalidParamsError | ||
from estimagic.parameters.constraint_tools import check_constraints | ||
|
||
|
||
def test_check_constraints_are_satisfied_type_equality(): | ||
with pytest.raises(InvalidParamsError): | ||
check_constraints( | ||
params=np.array([1, 2, 3]), constraints={"type": "equality", "loc": [0, 1]} | ||
) | ||
|
||
|
||
def test_check_constraints_are_satisfied_type_increasing(): | ||
with pytest.raises(InvalidParamsError): | ||
check_constraints( | ||
params=np.array([1, 2, 3, 2, 4]), | ||
constraints={"type": "increasing", "loc": [1, 2, 3]}, | ||
) | ||
|
||
|
||
def test_check_constraints_are_satisfied_type_decreasing(): | ||
with pytest.raises(InvalidParamsError): | ||
check_constraints( | ||
params=np.array([1, 2, 3, 2, 4]), | ||
constraints={"type": "decreasing", "loc": [0, 1, 3]}, | ||
) | ||
|
||
|
||
def test_check_constraints_are_satisfied_type_pairwise_equality(): | ||
with pytest.raises(InvalidParamsError): | ||
check_constraints( | ||
params=np.array([1, 2, 3, 3, 4]), | ||
constraints={"type": "pairwise_equality", "locs": [[0, 4], [3, 2]]}, | ||
) | ||
|
||
|
||
def test_check_constraints_are_satisfied_type_probability(): | ||
with pytest.raises(InvalidParamsError): | ||
check_constraints( | ||
params=np.array([0.10, 0.25, 0.50, 1, 0.7]), | ||
constraints={"type": "probability", "loc": [0, 1, 2, 4]}, | ||
) | ||
|
||
|
||
def test_check_constraints_are_satisfied_type_linear_lower_bound(): | ||
with pytest.raises(InvalidParamsError): | ||
check_constraints( | ||
params=np.ones(5), | ||
constraints={ | ||
"type": "linear", | ||
"loc": [0, 2, 3, 4], | ||
"lower_bound": 1.1, | ||
"weights": 0.25, | ||
}, | ||
) | ||
|
||
|
||
def test_check_constraints_are_satisfied_type_linear_upper_bound(): | ||
with pytest.raises(InvalidParamsError): | ||
check_constraints( | ||
params=np.ones(5), | ||
constraints={ | ||
"type": "linear", | ||
"loc": [0, 2, 3, 4], | ||
"upper_bound": 0.9, | ||
"weights": 0.25, | ||
}, | ||
) | ||
|
||
|
||
def test_check_constraints_are_satisfied_type_linear_value(): | ||
with pytest.raises(InvalidParamsError): | ||
check_constraints( | ||
params=np.ones(5), | ||
constraints={ | ||
"type": "linear", | ||
"loc": [0, 2, 3, 4], | ||
"value": 2, | ||
"weights": 0.25, | ||
}, | ||
) | ||
|
||
|
||
def test_check_constraints_are_satisfied_type_covariance(): | ||
with pytest.raises(InvalidParamsError): | ||
check_constraints( | ||
params=[1, 1, 1, -1, 1, -1], | ||
constraints={ | ||
"type": "covariance", | ||
# "loc": [0, 1, 2], | ||
"selector": lambda params: params, | ||
}, | ||
) | ||
|
||
|
||
def test_check_constraints_are_satisfied_type_sdcorr(): | ||
with pytest.raises(InvalidParamsError): | ||
check_constraints( | ||
params=[1, 1, 1, -1, 1, 1], | ||
constraints={ | ||
"type": "sdcorr", | ||
# "loc": [0, 1, 2], | ||
"selector": lambda params: params, | ||
}, | ||
) | ||
|
||
|
||
# to ignore as per email? | ||
# def test_check_constraints_are_satisfied_type_nonlinear(): |