Beispiel #1
0
    def test_count_children_multiple(s):
        """As previous test, but for the case with multiple children.

        This test is for the case with only one child.
        """
        clust = Depression.create(*cont5())[0]
        s.assertEqual(clust.n_children(), 3)
Beispiel #2
0
 def test_bcc_100(s):
     """For bcc_frac=1.0, a single Depression object containing all
     contours is created."""
     depr = Depression.create(s.cont, bcc_frac=1.0)
     s.assertEqual(len(depr), 1)
     res = depr[0].contours()
     s.assertCountEqual(res, s.cont)
Beispiel #3
0
 def test_path(s):
     """Return the path of the contour as a list of coordinate tuples."""
     outer_path = [(1, 1), (4, 1), (4, 5), (1, 5), (1, 1)]
     inner_path = [(2, 2), (3, 2), (3, 3), (2, 3), (2, 2)]
     cont = [ContourSimple(outer_path, 2), ContourSimple(inner_path, 1)]
     depr = Depression.create(cont)[0]
     s.assertCountEqual(depr.path(), outer_path)
Beispiel #4
0
 def setUp(s):
     s.cont, s.min = cont1()
     s.enclosing = s.cont[-1]  # sorted ascendingly by contour value
     assert contours_are_sorted(s.cont)
     shuffle_contours_assert(s.cont)
     assert not contours_are_sorted(s.cont)
     s.clust = Depression.create(s.cont, s.min)[0]
Beispiel #5
0
 def test_depression_bcc_065(s):
     """For bcc-frac=0.65, all but 1 BCCs are accepted."""
     dep = Depression.create(s.cont, [], bcc_frac=0.65)
     s.assertEqual(len(dep), 1)
     res = dep[0].contours()
     sol = s.cont[: 4 + 7]
     s.assertCountEqual(res, sol)
Beispiel #6
0
 def test_depression_bcc_100(s):
     """For bcc-frac=1.0, all 8 BCCs are accepted."""
     dep = Depression.create(s.cont, [], bcc_frac=1.0)
     s.assertEqual(len(dep), 1)
     res = dep[0].contours()
     sol = s.cont[: 4 + 8]
     s.assertCountEqual(res, sol)
Beispiel #7
0
 def test_depression_bcc_050(s):
     """For bcc-frac=0.5, only 4 BCCs are accepted."""
     dep = Depression.create(s.cont, [], bcc_frac=0.5)
     s.assertEqual(len(dep), 1)
     res = dep[0].contours()
     sol = s.cont[: 4 + 4]
     s.assertCountEqual(res, sol)
Beispiel #8
0
 def test_depression_bcc_020(s):
     """For bcc-frac=0.2, only 1 BCC is accepted."""
     dep = Depression.create(s.cont, [], bcc_frac=0.2)
     s.assertEqual(len(dep), 1)
     res = dep[0].contours()
     sol = s.cont[: 4 + 1]
     s.assertCountEqual(res, sol)
Beispiel #9
0
 def test_assign_minima_complete_list(s):
     """Assign a list of points that contains all minima (i.e. at least
     one for every innermost contour). The deepest minimum in each inner-
     most contour is retained, all other minima are discarded.
     """
     clust = Depression.create(s.cont, s.pt_all)[0]
     s.assertSetEqual(set(clust.minima()), set(s.min_complete))
Beispiel #10
0
 def test_separate_toplevel_clusters_different_levels(s):
     """Contours belonging to two separate top-level clusters are
     clustered correctly. In this case, the enclosing contours
     of the two clusters have a different value.
     """
     clust = Depression.create(*cont4())
     s.assertEqual(len(clust), 2)
Beispiel #11
0
 def setUp(s):
     """The cluster contains more than 3 minima. Thus, it is split up
     into 2 clusters which both contain 2 minima. They correspond
     to cont3 and cont5, with shared contour ratios of 0.28 and 0.57,
     respectively.
     """
     s.kwargs = KWARGS
     s.depr = Depression.create(*cont6())[0]
Beispiel #12
0
 def setUp(s):
     """The maximum contour depth of the cluster is 11.
     The outermost 8 contours are shared by all three subclusters.
     This results in a shared contour ratio of 8/11=0.73, which is
     above the threshold for TCCs.
     """
     s.kwargs = KWARGS
     s.depr = Depression.create(*cont4())[0]
Beispiel #13
0
 def setUp(s):
     """The maximum contour depth of the cluster is 7.
     The outermost 2 contours are shared by both subclusters.
     This results in a shared contour ratio of 2/7=0.28, which is
     below the threshold for DCCs.
     """
     s.kwargs = KWARGS
     s.depr = Depression.create(*cont3())[0]
Beispiel #14
0
 def test_bcc_045(s):
     """For bcc_frac=0.45, the initial Depression object is split up into
     two because all enclosing contours are discarded.
     """
     depr = Depression.create(s.cont, bcc_frac=0.45)
     s.assertEqual(len(depr), 2)
     res = depr[0].contours() + depr[1].contours()
     s.assertSetEqual(set(res), set(s.cont[:-5]))
Beispiel #15
0
 def test_depression_bcc_fraction_double_center(s):
     """Check the method Depression.bcc_fraction for a cluster with
     two centers (i.e. sub-clusters).
     """
     # cont2: 3 CCs + (2+5) BCCs = 10 Cs (deepest sub-cluster only)
     cont = cont2(cont=True)
     res = Depression.create(cont, bcc_frac=1.0)[0].bcc_fraction()
     s.assertAlmostEqual(res, 7.0 / 10.0)
Beispiel #16
0
    def test_count_children_single(s):
        """Check whether the number of children is correctly returned.

        This test is for the case with only one child.
        """
        cont, min = cncc(3, (3.0, 3.0), 0.2, (1, 1), no_min=True)
        clust = Depression.create(cont, min)[0]
        s.assertEqual(clust.n_children(), 1)
Beispiel #17
0
    def test_contours_complex(s):
        """As ~_simple, but for a complex cluster (imperfectly nested).

        All contours of the cluster and all subclusters are collected.
        """
        cont, min = cont3()
        clust = Depression.create(cont, min)[0]
        s.assertSetEqual(set(clust.contours()), set(cont))
Beispiel #18
0
    def test_perfectly_nested_true(s):
        """Test Depression.is_perfectly_nested(), which returns True if all
        contours are perfectly nested, and False if the cluster branches at
        some point into separate sub-clusters.

        This test is for a perfectly nested cluster.
        """
        s.assertTrue(Depression.create(*cont1())[0].is_perfectly_nested())
Beispiel #19
0
 def test_depression_bcc_fraction_single_center(s):
     """Check the method Depression.bcc_fraction for a simple cluster with
     only one center (i.e. a perfectly nested one).
     """
     # cont1: 4 CCs + 8 BCCs = 12 Cs
     cont = cont1(cont=True)
     # res = Depression.create(cont,bcc_frac=1.0)[0].bcc_fraction()
     d = Depression.create(cont, bcc_frac=1.0)[0]
     res = d.bcc_fraction()
     s.assertAlmostEqual(res, 8.0 / 12.0)
Beispiel #20
0
 def test_bcc_055(s):
     """For bcc_frac=0.55, a single Depression object containing all
     but the 4 outermost contours is created.
     """
     # For bcc_frac=0.55, 4/5 enclosing contours should be discarded,
     # but the Depression should not yet be split up!
     depr = Depression.create(s.cont, bcc_frac=0.55)
     s.assertEqual(len(depr), 1)
     res = depr[0].contours()
     s.assertCountEqual(res, s.cont[:-4])
Beispiel #21
0
 def test_bcc_020(s):
     """For bcc_frac=0.2, two Depression objects are created, but neither
     contains any BCCs.
     """
     depr = Depression.create(s.cont, bcc_frac=0.20)
     s.assertEqual(len(depr), 2)
     res = depr[0].contours() + depr[1].contours()
     # This is quite messy...
     sol = s.cont[:3] + s.cont[5:9]
     s.assertSetEqual(set(res), set(sol))
Beispiel #22
0
 def test_depression_bcc_fraction_double_center_equal_depth(s):
     """Check the method Depression.bcc_fraction for a cluster with
     two centers, which have equal depth but different number of BCCs.
     The sub-cluster with more BCCs is used for the computation.
     """
     # Remove the innermost contour from the deeper cluster so both
     # have equal depth, but different numbers of BCCs (0/4 and 2/4).
     # The resulting total depth is 4+5=9.
     cont = cont2(cont=True)[1:]
     res = Depression.create(cont, bcc_frac=1.0)[0].bcc_fraction()
     s.assertAlmostEqual(res, 7.0 / 9.0)
Beispiel #23
0
    def setUp(s):
        """The maximum contour depth of the cluster is 10.
        The outermost 3 contours are shared by both subclusters.
        This results in a shared contour ratio of 3/10=0.30, which is
        below the threshold for TCCs. The cluster is therefore split up.

        The maximum depth of the subcluster which contains two minimums
        is 7, which, given 4 shared contours, results in a shared contour
        ratio of 4/7=0.57, which is above the threshold for DCCs.
        """
        s.kwargs = KWARGS
        s.depr = Depression.create(*cont5())[0]
Beispiel #24
0
    def test_two_minima(s):
        """Two centers of different depths.

         - Enclosing contour: level 6
         - Minimum 1 @ (6,3): level 0 -> rel. depth 6 -> weight 0.66
         - Minimum 2 @ (7,4): level 3 -> rel. depth 3 -> weight 0.33

         -> Center: 2/3*(6,3) + 1/3*(7,4) = (4+2.33,2+1.33) = (6.33,3.33)
        """
        clust = Depression.create(*cont3())[0]
        res = clust.center()
        sol = (6.33, 3.33)
        assert_almost_equal(sol, res, 2)
Beispiel #25
0
    def test_three_minima(s):
        """Three centers of different depths.

         - Enclosing contour: level 8
         - Minimum 1 @ (3,3): level 2 -> rel. depth 6 -> weight 0.32
         - Minimum 2 @ (6,3): level 0 -> rel. depth 8 -> weight 0.42
         - Minimum 3 @ (7,4): level 3 -> rel. depth 5 -> weight 0.26

         -> Center: 0.32*(3,3) + 0.42*(6,5) + 0.26*(7,4) = (5.32,3.26)
        """
        clust = Depression.create(*cont6())[0]
        res = clust.center()
        sol = (5.32, 3.26)
        assert_almost_equal(sol, res, 2)
Beispiel #26
0
 def setUp(s):
     """The cluster contains 1 subclusters, one of which contains
     1 minimum, the other 2.
     """
     cont, min = cont6()
     s.depr = Depression.create(cont, min)[0]
Beispiel #27
0
 def setUp(s):
     """
     2 + 2|5 contours = 4|7 contours
     2 + 2|5 contours + minimum = 4.0|7.0
     """
     s.clust = Depression.create(*cont3())[0]
Beispiel #28
0
 def setUp(s):
     """The cluster consists of 5 contours and one minimum, which amounts
     to a total depth of 5.0.
     """
     s.clust = Depression.create(*cont1())[0]
Beispiel #29
0
 def test_innermost_contours(s):
     """Return a list containing the innermost contours."""
     clust = Depression.create(s.cont, s.pt_all)[0]
     foo = clust.innermost_contours()
     s.assertSetEqual(set(foo), set(s.cont_inner))
Beispiel #30
0
 def test_contours_simple(s):
     """Test the contours method for a simple cluster (perfectly nested)."""
     cont, min = cont1()
     clust = Depression.create(cont, min)[0]
     s.assertSetEqual(set(clust.contours()), set(cont))