-
Notifications
You must be signed in to change notification settings - Fork 6
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
Remove cvxpy for weight minimization, fix test values and refactor tests codes #120
Changes from 6 commits
6a0b55d
b20f1be
1ed7094
534f621
675ee69
debc7bc
4407df7
1c590a4
47bb88a
c8258de
81c402e
71c017f
da7dda1
a5e2eae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
**Added:** | ||
|
||
* L-BFGS-B method in scipy for weight optimization in def get_weights | ||
* Support for Python 3.13 | ||
|
||
**Changed:** | ||
|
||
* <news item> | ||
|
||
**Deprecated:** | ||
|
||
* <news item> | ||
|
||
**Removed:** | ||
|
||
* cvxpy depenedency for linear weight optmization in def get_weights | ||
* Support for Python 3.10 | ||
|
||
**Fixed:** | ||
|
||
* Absolute tolerance for updated weighted matrix from 0.5 to 1e-05 in test_subroutines.py | ||
|
||
**Security:** | ||
|
||
* <news item> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
numpy | ||
scipy | ||
cvxpy | ||
diffpy.utils | ||
numdifftools |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
numpy | ||
scipy | ||
cvxpy | ||
diffpy.utils | ||
numdifftools |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,9 @@ | |
|
||
from diffpy.snmf.optimizers import get_weights | ||
|
||
tm = [ | ||
([[[1, 0], [0, 1]], [1, 1], [0, 0], [1, 1]], [0, 0]), | ||
test_matrix = [ | ||
# ([stretched_component_gram_matrix, linear_coefficient, lower_bound, upper_bound], expected) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added an in-line comment to see the order of the input data in the test matrix |
||
([[[1, 0], [0, 1]], [1, 1], 0, 0], [0, 0]), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixing syntax bug - fixing from
|
||
([[[1, 0], [0, 1]], [1, 1], -1, 1], [-1, -1]), | ||
([[[1.75, 0], [0, 1.5]], [1, 1.2], -1, 1], [-0.571428571428571, -0.8]), | ||
([[[0.75, 0.2], [0.2, 0.75]], [-0.1, -0.2], -1, 1], [0.066985645933014, 0.248803827751196]), | ||
|
@@ -13,8 +14,12 @@ | |
] | ||
|
||
|
||
@pytest.mark.parametrize("tm", tm) | ||
@pytest.mark.parametrize("tm", test_matrix) | ||
def test_get_weights(tm): | ||
stretched_component_gram_matrix = tm[0][0] | ||
linear_coefficient = tm[0][1] | ||
lower_bound = tm[0][2] | ||
upper_bound = tm[0][3] | ||
expected = tm[1] | ||
actual = get_weights(tm[0][0], tm[0][1], tm[0][2], tm[0][3]) | ||
actual = get_weights(stretched_component_gram_matrix, linear_coefficient, lower_bound, upper_bound) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pass variables instead of |
||
assert actual == pytest.approx(expected, rel=1e-4, abs=1e-6) |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Problem- the previous code in line 212 in this file had an absolute tolerance of 0.5!
When I modified
the original code started to fail (3-4 out of 7-8 test cases failed). Since our new |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,7 +125,7 @@ def test_get_stretched_component(tgso): | |
[[0.78, 0.12], [0.5, 0.5]], | ||
None, | ||
], | ||
[[0, 1], [1, 1]], | ||
[[0.533333, 0.933333], [0.533333, 0.933333]], | ||
), | ||
( | ||
[2, 3, [[0.5], [0.5]], [[1, 2.5], [1.5, 3], [2, 3.5]], [[1, 2], [3, 4], [5, 6]], 1, [[0.5], [0.5]], None], | ||
|
@@ -155,7 +155,7 @@ def test_get_stretched_component(tgso): | |
[[0.9, 0.4, 0.5], [1, 0, 0.4], [0, 0, 0.98]], | ||
None, | ||
], | ||
[[1, 0.0651, 0], [0.5848, 0.0381, 0.1857], [0, 1, 1]], | ||
[[1.0, 0.0900485, 0.0], [0.585632, 0.497497, 0.179719], [0.0, 0.52223655, 1.0]], | ||
), | ||
([2, 2, [[0.5], [0.5]], [[0, 0], [0, 0]], [[0, 0], [0, 0]], 1, [[0.6], [0.4]], "align"], [[0], [0]]), | ||
([1, 3, [[0.5, 0.3]], [[1], [1.1], [1.3]], [[1, 2], [2, 3], [3, 2]], 2, [[0.6, 0.4]], None], [[1, 1]]), | ||
|
@@ -170,7 +170,7 @@ def test_get_stretched_component(tgso): | |
[[0.78, 0.12], [0.5, 0.5]], | ||
"align", | ||
], | ||
[[0, 0], [1.0466, 1.46]], | ||
[[0, 0], [0.8, 1.4]], | ||
), | ||
( | ||
[ | ||
|
@@ -196,7 +196,7 @@ def test_get_stretched_component(tgso): | |
[[0.9, 0.4, 0.5], [1, 0, 0.4], [0, 0, 0.98]], | ||
"align", | ||
], | ||
[[1.2605, 0.0552, 0], [0.2723, 0, 0], [0, 1.0538, 1.1696]], | ||
[[1.281265, 0.104355, 0], [0.0, 0.0, 0.0], [0.239578, 0.965215, 1.162571]], | ||
), | ||
([2, 2, [[0.5], [0.5]], [[0, 0], [0, 0]], [[0, 0], [0, 0]], 1, [[0.6], [0.4]], "align"], [[0], [0]]), | ||
([1, 3, [[0.5, 0.3]], [[1], [1.1], [1.3]], [[1, 2], [2, 3], [3, 2]], 2, [[0.6, 0.4]], "align"], [[1.3383, 2]]), | ||
|
@@ -208,8 +208,11 @@ def test_update_weights_matrix(tuwm): | |
actual = update_weights_matrix( | ||
tuwm[0][0], tuwm[0][1], tuwm[0][2], tuwm[0][3], tuwm[0][4], tuwm[0][5], tuwm[0][6], tuwm[0][7] | ||
) | ||
|
||
print("Actual test get stretched component", actual) | ||
print("Expected test get stretched component", tuwm[1]) | ||
expected = tuwm[1] | ||
np.testing.assert_allclose(actual, expected, rtol=1e-03, atol=0.5) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
np.testing.assert_allclose(actual, expected, rtol=1e-03, atol=1e-05) | ||
|
||
|
||
tgrm = [ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As intended