Skip to content

Commit

Permalink
TST: simple ties test for hierarchical clusterers
Browse files Browse the repository at this point in the history
  • Loading branch information
sdvillal committed Mar 12, 2016
1 parent bfb092b commit b82937e
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions scipy/cluster/tests/test_hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,35 @@ def check_linkage_q(self, method):
assert_allclose(Z, expectedZ, atol=1e-06)


class TestLinkageTies(object):
_expectations = {
'single': np.array([[0, 1, 1.41421356, 2],
[2, 3, 1.41421356, 3]]),
'complete': np.array([[0, 1, 1.41421356, 2],
[2, 3, 2.82842712, 3]]),
'average': np.array([[0, 1, 1.41421356, 2],
[2, 3, 2.12132034, 3]]),
'weighted': np.array([[0, 1, 1.41421356, 2],
[2, 3, 2.12132034, 3]]),
'centroid': np.array([[0, 1, 1.41421356, 2],
[2, 3, 2.12132034, 3]]),
'median': np.array([[0, 1, 1.41421356, 2],
[2, 3, 2.12132034, 3]]),
'ward': np.array([[0, 1, 1.41421356, 2],
[2, 3, 2.44948974, 3]]),
}

def test_linkage_ties(self):
for method in ['single', 'complete', 'average', 'weighted', 'centroid', 'median', 'ward']:
yield self.check_linkage_ties, method

def check_linkage_ties(self, method):
X = np.array([[-1, -1], [0, 0], [1, 1]])
Z = linkage(X, method=method)
expectedZ = self._expectations[method]
assert_allclose(Z, expectedZ, atol=1e-06)


class TestInconsistent(object):
def test_inconsistent_tdist(self):
for depth in hierarchy_test_data.inconsistent_ytdist:
Expand Down

0 comments on commit b82937e

Please sign in to comment.