예제 #1
0
    def test_equal_entries(self):
        settings = {"cubes": 10, "overlap": 0.5}

        # uniform data:
        data = np.arange(0, 100)
        data = data[:, np.newaxis]
        lens = data

        cov = Cover(settings["cubes"], settings["overlap"])

        # Prefix'ing the data with an ID column
        ids = np.array([x for x in range(lens.shape[0])])
        lens = np.c_[ids, lens]

        bins = cov.fit(lens)

        bins = list(bins)  # extract list from generator

        assert len(bins) == settings["cubes"]

        cube_entries = [cov.transform_single(lens, cube) for cube in bins]

        for c1, c2 in list(zip(cube_entries, cube_entries[1:]))[2:]:
            c1, c2 = c1[:, 0], c2[:, 0]  # indices only

            calced_overlap = len(set(list(c1)).intersection(set(list(c2)))) / max(
                len(c1), len(c2)
            )
            assert calced_overlap == pytest.approx(0.5)
예제 #2
0
    def test_entries_in_correct_cubes(self):
        # TODO: this test is a little hacky

        data_vals = np.arange(20)
        data = np.zeros((20, 2))
        data[:, 0] = np.arange(20, dtype=int)  # Index row
        data[:, 1] = data_vals

        cover = Cover(n_cubes=10, perc_overlap=0.2)
        cubes = cover.fit(data)
        cubes = list(cubes)
        entries = [cover.transform_single(data, cube) for cube in cubes]

        # inside of each cube is there. Sometimes the edges don't line up.
        for i in range(10):
            assert data[2 * i] in entries[i]
            assert data[2 * i + 1] in entries[i]
예제 #3
0
    def test_perc_overlap(self, CoverClass):
        """
        2 cubes with 50% overlap and a range of [0,1] should lead to two cubes with intervals:
            [0, .75]
            [.25, 1]
        """

        data = np.array([[0, 0], [1, 0.25], [2, 0.5], [3, 0.75], [4, 1]])

        cover = Cover(n_cubes=2, perc_overlap=0.5)
        cubes = cover.fit(data)
        cubes = list(cubes)
        entries = [cover.transform_single(data, cube) for cube in cubes]

        for i in (0, 1, 2, 3):
            assert data[i] in entries[0]
        for i in (1, 2, 3, 4):
            assert data[i] in entries[1]
예제 #4
0
    def test_125_replication(self):
        # uniform data:
        data = np.arange(0, 100)
        data = data[:, np.newaxis]
        lens = data

        cov = Cover(10, 0.5)

        # Prefix'ing the data with an ID column
        ids = np.array([x for x in range(lens.shape[0])])
        lens = np.c_[ids, lens]

        bins = cov.fit(lens)

        cube_entries = [cov.transform_single(lens, cube) for cube in bins]

        overlaps = [
            len(set(list(c1[:, 0])).intersection(set(list(c2[:, 0]))))
            for c1, c2 in zip(cube_entries, cube_entries[1:])
        ]
        assert (len(set(overlaps)) == 1
                ), "Each overlap should have the same number of entries. "
예제 #5
0
 def test_transform_runs_with_diff_bins(self):
     data = np.arange(30).reshape(10, 3)
     c = Cover(n_cubes=[5, 10])
     cubes = list(c.fit(data))
     _ = c.transform_single(data, cubes[0])