Ejemplo n.º 1
0
    def test_fast_segmentation(self):
        n = 360
        k = 3
        epsilon = 1

        generate_input_file(n)
        data = np.genfromtxt("input.csv", delimiter=" ")
        p = np.c_[np.mgrid[1:n + 1], data]

        D = Coreset.build_coreset(p, k, epsilon)
        print len(D)
        x = np.empty((0, 4))
        for coreset in D:
            print "coreset range", coreset.e - coreset.b + 1
            pts = utils.pt_on_line(xrange(int(coreset.b), int(coreset.e) + 1), coreset.g)
            # TODO: 2nd parameter should be epsilon
            w = Coreset.PiecewiseCoreset(len(pts[0]), epsilon)
            p_coreset = np.column_stack((pts[0], pts[1], pts[2], w))
            p_coreset_filtered = p_coreset[p_coreset[:, 3] > 0]
            # print "weighted points", p_coreset_filtered
            x = np.append(x, p_coreset_filtered, axis=0)
        print "num of weighted points", len(x)
        dividers = ksegment.coreset_k_segment_fast_segmentation(x, k)
        print "dividers", dividers
        print "dividers-cost:", utils.calc_cost_dividers(p, dividers)
        utils.visualize_3d(p, dividers)
Ejemplo n.º 2
0
    def test_bicritiria(self):
        n = 300
        k = 8
        data = example1(n)

        p = np.c_[np.mgrid[1:n + 1], data]

        bicritiria_cost = Coreset.bicriteria(p, k)
        print "Bicritiria estimate: ", bicritiria_cost
        real_cost = utils.calc_cost_dividers(p, ksegment.k_segment(p, k))
        print "real cost: ", real_cost
        self.assertGreaterEqual(bicritiria_cost, real_cost)
Ejemplo n.º 3
0
    def test_fast_segmentation(self):
        # generate points
        n = 600
        k = 6
        epsilon = 10
        generate_input_file(n)
        data = np.genfromtxt("input.csv", delimiter=" ")
        p = np.c_[np.mgrid[1:n + 1], data]

        D = Coreset.build_coreset(p, k, epsilon)
        print D
        dividers = ksegment.coreset_k_segment_fast_segmentation(D, k, epsilon)
        print "dividers", dividers
        print "dividers-cost:", utils.calc_cost_dividers(p, dividers)