Skip to content

Commit dd4647a

Browse files
authored
Merge pull request #109 from EveCharbie/breaking_the_tests
TESTS WILL FAIL: SVD fix for SARA
2 parents c60db7e + 5661402 commit dd4647a

3 files changed

Lines changed: 34 additions & 23 deletions

File tree

biobuddy/model_modifiers/joint_center_tool.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -917,8 +917,7 @@ def perform_algorithm(
917917
aor_child_local /= np.linalg.norm(aor_child_local)
918918

919919
# Compute pseudo-inverse solution
920-
# cor = V[:, :5] @ np.diag(1.0 / S[:5]) @ U[:, :5].T @ b_valid # TODO: make a breaking PR for this change !!!
921-
cor = V @ np.diag(1.0 / S) @ U.T @ b_valid
920+
cor = V[:, :5] @ np.diag(1.0 / S[:5]) @ U[:, :5].T @ b_valid
922921
cor_parent_local = cor[3:]
923922
cor_child_local = cor[:3]
924923

tests/test_components_generic.py

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,8 +1632,10 @@ def test_sara():
16321632
rt_matrix_time_series = RotoTransMatrixTimeSeries(nb_frames)
16331633
for i_frame in range(nb_frames):
16341634
# Only rotate on the X-axis (with a little something on the Z-axis)
1635+
child_rotation = np.array([i_frame * 0.05, 0, i_frame * 0.0001])
1636+
child_translation = np.array([0.2, 0.2, 0.2])
16351637
rt_matrix_time_series[i_frame] = RotoTransMatrix().from_euler_angles_and_translation(
1636-
"xyz", np.array([i_frame * 0.05, 0, i_frame * 0.0001]), np.array([0.2, 0.2, 0.2])
1638+
"xyz", child_rotation, child_translation
16371639
)
16381640
child_markers = {
16391641
"child1": rt_matrix_time_series
@@ -1672,7 +1674,7 @@ def test_sara():
16721674
result_aor.start_point.position.reshape(
16731675
4,
16741676
),
1675-
np.array([-0.01913936, 0.0550008, 0.0876632, 1.0]),
1677+
np.array([0.23814297, 0.41019945, 0.57167098, 1.0]),
16761678
)
16771679
npt.assert_almost_equal(
16781680
result_aor.end_point.position.reshape(
@@ -1684,7 +1686,7 @@ def test_sara():
16841686
result_aor.axis().reshape(
16851687
4,
16861688
),
1687-
np.array([0.56057423, 0.73547957, 0.99896262, 1.0]),
1689+
np.array([0.3032919, 0.38028092, 0.51495484, 1.0]),
16881690
)
16891691

16901692
# Test that calling twice returns the same result (caching)
@@ -1732,30 +1734,38 @@ def test_sara():
17321734

17331735

17341736
def test_sara_with_expected_rotation_axis():
1735-
"""Test SARA with expected rotation axis orientation"""
1737+
"""
1738+
Test SARA with expected rotation axis orientation
1739+
Note: this test does not give the exact x-axis we were looking for :(
1740+
"""
1741+
17361742
np.random.seed(42)
17371743
nb_frames = 50
17381744

17391745
# Create parent markers
17401746
parent_markers = {
1741-
"parent1": np.random.randn(4, nb_frames) * 0.01 + np.array([[0.1], [0.2], [0.3], [1.0]]),
1742-
"parent2": np.random.randn(4, nb_frames) * 0.01 + np.array([[0.15], [0.25], [0.35], [1.0]]),
1743-
"parent3": np.random.randn(4, nb_frames) * 0.01 + np.array([[0.2], [0.3], [0.4], [1.0]]),
1747+
"parent_start": np.random.randn(4, nb_frames) * 0.00001 + np.array([[0.1], [0.002], [0.003], [1.0]]),
1748+
"parent_end": np.random.randn(4, nb_frames) * 0.00001 + np.array([[0.9], [0.002], [0.003], [1.0]]),
1749+
"parent1": np.random.randn(4, nb_frames) * 0.00001 + np.array([[0.1], [0.002], [0.003], [1.0]]),
1750+
"parent2": np.random.randn(4, nb_frames) * 0.00001 + np.array([[0.15], [0.25], [0.35], [1.0]]),
1751+
"parent3": np.random.randn(4, nb_frames) * 0.00001 + np.array([[0.2], [0.3], [0.4], [1.0]]),
17441752
}
17451753

17461754
# Create child markers rotating around X-axis
17471755
rt_matrix_time_series = RotoTransMatrixTimeSeries(nb_frames)
17481756
for i_frame in range(nb_frames):
1757+
child_rotation = np.array([i_frame * 0.1, 0, 0])
1758+
child_translation = np.array([0.2, 0.2, 0.2])
17491759
rt_matrix_time_series[i_frame] = RotoTransMatrix().from_euler_angles_and_translation(
1750-
"xyz", np.array([i_frame * 0.05, 0, 0]), np.array([0.2, 0.2, 0.2])
1760+
"xyz", child_rotation, child_translation
17511761
)
17521762
child_markers = {
17531763
"child1": rt_matrix_time_series
1754-
@ (np.random.randn(4, nb_frames) * 0.01 + np.array([[0.3], [0.4], [0.5], [1.0]])),
1764+
@ (np.random.randn(4, nb_frames) * 0.00001 + np.array([[0.3], [0.4], [0.5], [1.0]])),
17551765
"child2": rt_matrix_time_series
1756-
@ (np.random.randn(4, nb_frames) * 0.01 + np.array([[0.35], [0.45], [0.55], [1.0]])),
1766+
@ (np.random.randn(4, nb_frames) * 0.00001 + np.array([[0.35], [0.45], [0.55], [1.0]])),
17571767
"child3": rt_matrix_time_series
1758-
@ (np.random.randn(4, nb_frames) * 0.01 + np.array([[0.4], [0.5], [0.6], [1.0]])),
1768+
@ (np.random.randn(4, nb_frames) * 0.00001 + np.array([[0.4], [0.5], [0.6], [1.0]])),
17591769
}
17601770

17611771
all_markers = {**parent_markers, **child_markers}
@@ -1768,8 +1778,8 @@ def test_sara_with_expected_rotation_axis():
17681778
# Create expected rotation axis (X-axis direction)
17691779
expected_axis = Axis(
17701780
name=Axis.Name.X,
1771-
start=Marker(name="parent1", function=lambda m, bio: m.get_position(["parent1"])[:, :, 0]),
1772-
end=Marker(name="parent2", function=lambda m, bio: m.get_position(["parent2"])[:, :, 0]),
1781+
start=Marker(name="parent_start", function=lambda m, bio: m.get_position(["parent_start"])[:, :, 0]),
1782+
end=Marker(name="parent_end", function=lambda m, bio: m.get_position(["parent_end"])[:, :, 0]),
17731783
)
17741784

17751785
# Create SARA axis with expected rotation axis
@@ -1788,14 +1798,14 @@ def test_sara_with_expected_rotation_axis():
17881798

17891799
# The axis should be aligned with the expected direction (positive)
17901800
axis_vector = result_aor.axis()[:3, 0]
1791-
npt.assert_almost_equal(axis_vector, np.array([0.56073976, 0.73525461, 0.99915736]))
1801+
npt.assert_almost_equal(axis_vector, np.array([0.60139438, -0.21820071, -0.0799947]))
17921802

17931803
# Test in the other direction as well
17941804
# Create expected rotation axis (-X-axis direction)
17951805
expected_axis = Axis(
17961806
name=Axis.Name.X,
1797-
start=Marker(name="parent2", function=lambda m, bio: m.get_position(["parent1"])[:, :, 0]),
1798-
end=Marker(name="parent1", function=lambda m, bio: m.get_position(["parent2"])[:, :, 0]),
1807+
start=Marker(name="parent_end", function=lambda m, bio: m.get_position(["parent_end"])[:, :, 0]),
1808+
end=Marker(name="parent_start", function=lambda m, bio: m.get_position(["parent_start"])[:, :, 0]),
17991809
)
18001810

18011811
# Create SARA axis with expected rotation axis
@@ -1814,7 +1824,7 @@ def test_sara_with_expected_rotation_axis():
18141824

18151825
# The axis should be aligned with the expected direction (negative)
18161826
axis_vector = result_aor.axis()[:3, 0]
1817-
npt.assert_almost_equal(axis_vector, np.array([-0.22725815, -0.35192431, -0.48310486]))
1827+
npt.assert_almost_equal(axis_vector, np.array([-1.20366083, 0.4501699, 0.46319628]))
18181828

18191829
# TODO: this test should be updated when the scs origin is modified by SARA as well.
18201830

@@ -1834,8 +1844,10 @@ def test_sara_with_callable_origin_positions():
18341844
# Create child markers
18351845
rt_matrix_time_series = RotoTransMatrixTimeSeries(nb_frames)
18361846
for i_frame in range(nb_frames):
1847+
child_rotation = np.array([i_frame * 0.05, 0, 0])
1848+
child_translation = np.array([0.2, 0.2, 0.2])
18371849
rt_matrix_time_series[i_frame] = RotoTransMatrix().from_euler_angles_and_translation(
1838-
"xyz", np.array([i_frame * 0.05, 0, 0]), np.array([0.2, 0.2, 0.2])
1850+
"xyz", child_rotation, child_translation
18391851
)
18401852
child_markers = {
18411853
"child1": rt_matrix_time_series
@@ -1881,7 +1893,7 @@ def test_sara_with_callable_origin_positions():
18811893
visualize=False,
18821894
)
18831895
result_aor_no_origin = sara_axis_no_origin.to_axis(static_data, mock_model, scs=RotoTransMatrix())
1884-
npt.assert_almost_equal(result_aor_no_origin.axis()[:3, 0], np.array([0.56073976, 0.73525461, 0.99915736]))
1896+
npt.assert_almost_equal(result_aor_no_origin.axis()[:3, 0], np.array([0.30331516, 0.38009301, 0.51492922]))
18851897

18861898
assert np.all(np.abs(result_aor_no_origin.axis()[:3, 0] - result_aor.axis()[:3, 0])) > 1e-4
18871899

tests/test_joint_center_tool.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,8 +1183,8 @@ def test_sara_perform_algorithm_with_origin_positions():
11831183
npt.assert_almost_equal(aor_global_normalized, aor_expected, decimal=1)
11841184

11851185
# Check that CoR is close to expected on all axes
1186-
# npt.assert_almost_equal(cor_global, cor_expected, decimal=1)
1187-
npt.assert_almost_equal(cor_global, np.array([1.55581197, 0.01196581, 0.01794872]), decimal=6) # TODO: remove !
1186+
npt.assert_almost_equal(cor_global[1:], cor_expected[1:], decimal=1)
1187+
npt.assert_almost_equal(cor_global, np.array([0.25365385, 0.17884615, 0.26826923]), decimal=6)
11881188

11891189

11901190
def test_joint_coordinate_modifier():

0 commit comments

Comments
 (0)