Skip to content

Commit

Permalink
added different testing module for woodgate and peng
Browse files Browse the repository at this point in the history
  • Loading branch information
banrovegrie committed Sep 3, 2022
1 parent cfd172b commit 8c7015b
Showing 1 changed file with 54 additions and 5 deletions.
59 changes: 54 additions & 5 deletions procrustes/test/test_psdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,27 @@
from procrustes.psdp import psdp_peng, psdp_woodgate


def test_psdp_identity(n=np.random.randint(50, 100)):
def test_psdp_woodgate_identity(n=np.random.randint(50, 100)):
r"""Test PSDP with identity matrix."""
a = np.eye(n)
b = np.eye(n)
res = psdp_woodgate(a=a, b=b)
s, error = res["s"], res["error"]
assert_almost_equal(s, np.eye(n))
assert_almost_equal(error, 0.0)


def test_psdp_peng_identity(n=np.random.randint(50, 100)):
r"""Test PSDP with identity matrix."""
a = np.eye(n)
b = np.eye(n)
res = psdp_peng(a=a, b=b)
s, error = res["s"], res["error"]
assert_almost_equal(s, np.eye(n))
assert_almost_equal(error, 0.0)


def test_psdp_diagonal():
def test_psdp_woodgate_diagonal():
r"""Test PSDP with diagonal matrix."""
a = np.diag([1, 2, 3, 4])
b = np.eye(4)
Expand All @@ -50,13 +56,20 @@ def test_psdp_diagonal():
actual_result = np.diag([0.99999, 0.5, 0.33333, 0.25])
assert_almost_equal(s, actual_result, decimal=5)
assert_almost_equal(error, 0.0, decimal=3)


def test_psdp_peng_diagonal():
r"""Test PSDP with diagonal matrix."""
a = np.diag([1, 2, 3, 4])
b = np.eye(4)
res = psdp_peng(a=a, b=b)
s, error = res["s"], res["error"]
actual_result = np.diag([0.99999, 0.5, 0.33333, 0.25])
assert_almost_equal(s, actual_result, decimal=5)
assert_almost_equal(error, 0.0, decimal=3)


def test_psdp_generic_square():
def test_psdp_woodgate_generic_square():
r"""Test PSDP with 2 generic square matrices."""
a = np.array([[1, 6, 0], [4, 3, 0], [0, 0, -0.5]])
b = np.array([[1, 0, 0], [0, -2, 3], [0, 2, 4]])
Expand All @@ -71,6 +84,12 @@ def test_psdp_generic_square():
)
assert_almost_equal(s, actual_result)
assert_almost_equal(error, 31.371190566800497, decimal=3)


def test_psdp_peng_generic_square():
r"""Test PSDP with 2 generic square matrices."""
a = np.array([[1, 6, 0], [4, 3, 0], [0, 0, -0.5]])
b = np.array([[1, 0, 0], [0, -2, 3], [0, 2, 4]])
res = psdp_peng(a=a, b=b)
s, error = res["s"], res["error"]
actual_result = np.array(
Expand All @@ -84,7 +103,7 @@ def test_psdp_generic_square():
assert_almost_equal(error, 33.43617791613022, decimal=3)


def test_psdp_generic_non_square():
def test_psdp_woodgate_generic_non_square():
r"""Test PSDP with 2 generic non-square matrices."""
a = np.array([[5, 1, 6, -1], [3, 2, 0, 2], [2, 4, 3, -3]])
b = np.array([[15, 1, 15 - 3, 2 + 5], [10, 5, 6, 3], [-3, 3, -3, -2 + 4]])
Expand All @@ -99,6 +118,12 @@ def test_psdp_generic_non_square():
)
assert_almost_equal(s, actual_result, decimal=5)
assert_almost_equal(error, 32.200295757989856, decimal=3)


def test_psdp_peng_generic_non_square():
r"""Test PSDP with 2 generic non-square matrices."""
a = np.array([[5, 1, 6, -1], [3, 2, 0, 2], [2, 4, 3, -3]])
b = np.array([[15, 1, 15 - 3, 2 + 5], [10, 5, 6, 3], [-3, 3, -3, -2 + 4]])
res = psdp_peng(a=a, b=b)
s, error = res["s"], res["error"]
actual_result = np.array(
Expand All @@ -112,7 +137,7 @@ def test_psdp_generic_non_square():
assert_almost_equal(error, 32.21671819685297)


def test_psdp_non_full_rank():
def test_psdp_woodgate_non_full_rank():
r"""Test PSDP when the to be transformed matrix doesn't have full rank."""
a = np.array(
[
Expand Down Expand Up @@ -148,6 +173,30 @@ def test_psdp_non_full_rank():
)
assert_almost_equal(s, actual_result, decimal=2)
assert_almost_equal(error, 0.0, decimal=2)


def test_psdp_peng_non_full_rank():
r"""Test PSDP when the to be transformed matrix doesn't have full rank."""
a = np.array(
[
[0.3452, -0.9897, 0.8082, -0.1739, -1.4692, -0.2531, 1.0339],
[0.2472, -1.4457, -0.6672, -0.5790, 1.2516, -0.8184, -0.4790],
[-1.3567, -0.9348, 0.7573, 1.7002, -0.9627, -0.5655, 2.5222],
[1.6639, 0.6111, -0.1858, 0.0485, 0.1136, 0.1372, -0.0149],
[-0.1400, -0.3303, -0.2965, 0.0218, 0.0565, -0.1907, -0.2544],
[-1.2662, 0.1905, 0.3302, -0.4041, 1.1479, -1.4716, 0.0857],
]
)
b = np.array(
[
[6.3043, -6.5364, 1.2659, -2.7625, -2.9861, -5.4362, 2.7422],
[-0.5694, -9.4371, -5.5455, -15.6041, 24.4958, -20.4567, -11.4576],
[-0.1030, 2.3164, 3.0813, 8.1280, -10.6447, 6.6903, 7.9874],
[8.1678, -4.5977, 0.0559, -2.6948, 1.1326, -6.5904, 2.0167],
[6.3043, -6.5364, 1.2659, -2.7625, -2.9861, -5.4362, 2.7422],
[-0.5694, -9.4371, -5.5455, -15.6041, 24.4958, -20.4567, -11.4576],
]
)
res = psdp_peng(a=a, b=b)
s, error = res["s"], res["error"]
actual_result = np.array(
Expand Down

0 comments on commit 8c7015b

Please sign in to comment.