def bettiNumbers(self, *args, **kwargs):
        from gudhi import RipsComplex, plot_persistence_diagram, plot_persistence_barcode, sparsify_point_set
        import random as r
        import numpy as np
        import matplotlib.pyplot as plt
        targetCluster = kwargs.get('targetCluster', [1])
        threshold = kwargs.get('threshold', 0.05)
        sparsifyThreshold = kwargs.get('sparsifyThreshold', threshold/8)
        plot = kwargs.get('plot', False)
        pointList = []
        for point in self.points:
            if point.cluster in targetCluster:
                pointList.append(np.array(point.coordinates))

        pointList = sparsify_point_set(
            points=pointList, min_squared_dist=sparsifyThreshold**2)
        point_complex = RipsComplex(
            max_edge_length=threshold/2, points=pointList)
        simplex_tree = point_complex.create_simplex_tree(
            max_dimension=self.dimension)
        persistence = simplex_tree.persistence()
        if plot:
            plot_persistence_barcode(persistence)
            plt.plot()
            plot_persistence_diagram(persistence)
            plt.plot()
        return simplex_tree.betti_numbers()
Exemplo n.º 2
0
def test_simple_sparsify_points():
    point_set = [[0, 1], [0, 0], [1, 0], [1, 1]]
    # Test the limits
    # assert gudhi.sparsify_point_set(points = [], min_squared_dist = 0.0) == []
    # assert gudhi.sparsify_point_set(points = [], min_squared_dist = 10.0) == []
    assert gudhi.sparsify_point_set(points=point_set,
                                    min_squared_dist=0.0) == point_set
    assert gudhi.sparsify_point_set(points=point_set,
                                    min_squared_dist=0.999) == point_set
    assert gudhi.sparsify_point_set(points=point_set,
                                    min_squared_dist=1.001) == [
                                        [0, 1],
                                        [1, 0],
                                    ]
    assert gudhi.sparsify_point_set(points=point_set,
                                    min_squared_dist=1.999) == [
                                        [0, 1],
                                        [1, 0],
                                    ]
    assert gudhi.sparsify_point_set(points=point_set,
                                    min_squared_dist=2.001) == [[0, 1]]

    assert (len(
        gudhi.sparsify_point_set(off_file="subsample.off",
                                 min_squared_dist=0.0)) == 7)
    assert (len(
        gudhi.sparsify_point_set(off_file="subsample.off",
                                 min_squared_dist=30.0)) == 5)
    assert (len(
        gudhi.sparsify_point_set(off_file="subsample.off",
                                 min_squared_dist=40.1)) == 4)
    assert (len(
        gudhi.sparsify_point_set(off_file="subsample.off",
                                 min_squared_dist=89.9)) == 3)
    assert (len(
        gudhi.sparsify_point_set(off_file="subsample.off",
                                 min_squared_dist=100.0)) == 2)
    assert (len(
        gudhi.sparsify_point_set(off_file="subsample.off",
                                 min_squared_dist=324.9)) == 2)
    assert (len(
        gudhi.sparsify_point_set(off_file="subsample.off",
                                 min_squared_dist=325.01)) == 1)