How to use the gudhi.RipsComplex function in gudhi

To help you get started, we’ve selected a few gudhi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github GUDHI / gudhi-devel / src / python / example / rips_complex_diagram_persistence_from_distance_matrix_file_example.py View on Github external
"--no-diagram",
    default=False,
    action="store_true",
    help="Flag for not to display the diagrams",
)

args = parser.parse_args()

print("#####################################################################")
print("RipsComplex creation from distance matrix read in a csv file")

message = "RipsComplex with max_edge_length=" + repr(args.max_edge_length)
print(message)

distance_matrix = gudhi.read_lower_triangular_matrix_from_csv_file(csv_file=args.file)
rips_complex = gudhi.RipsComplex(
    distance_matrix=distance_matrix, max_edge_length=args.max_edge_length
)
simplex_tree = rips_complex.create_simplex_tree(max_dimension=args.max_dimension)

message = "Number of simplices=" + repr(simplex_tree.num_simplices())
print(message)

diag = simplex_tree.persistence()

print("betti_numbers()=")
print(simplex_tree.betti_numbers())

if args.no_diagram == False:
    gudhi.plot_persistence_diagram(diag, band=args.band)
    plot.show()
github GUDHI / gudhi-devel / src / cython / example / rips_complex_from_points_example.py View on Github external
This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see .
"""

__author__ = "Vincent Rouvreau"
__copyright__ = "Copyright (C) 2016 Inria"
__license__ = "GPL v3"

print("#####################################################################")
print("RipsComplex creation from points")
rips = gudhi.RipsComplex(points=[[0, 0], [1, 0], [0, 1], [1, 1]],
                         max_edge_length=42)

simplex_tree = rips.create_simplex_tree(max_dimension=1)

print("filtrations=", simplex_tree.get_filtration())
print("star([0])=", simplex_tree.get_star([0]))
print("coface([0], 1)=", simplex_tree.get_cofaces([0], 1))
github GUDHI / gudhi-devel / src / python / example / rips_complex_diagram_persistence_from_correlation_matrix_file_example.py View on Github external
print("#####################################################################")
print("RipsComplex creation from correlation matrix read in a csv file")

message = "RipsComplex with min_edge_correlation=" + repr(args.min_edge_correlation)
print(message)

correlation_matrix = gudhi.read_lower_triangular_matrix_from_csv_file(
    csv_file=args.file
)
# Given a correlation matrix M, we compute component-wise M'[i,j] = 1-M[i,j] to get a distance matrix:
distance_matrix = [
    [1.0 - correlation_matrix[i][j] for j in range(len(correlation_matrix[i]))]
    for i in range(len(correlation_matrix))
]

rips_complex = gudhi.RipsComplex(
    distance_matrix=distance_matrix, max_edge_length=1.0 - args.min_edge_correlation
)
simplex_tree = rips_complex.create_simplex_tree(max_dimension=args.max_dimension)

message = "Number of simplices=" + repr(simplex_tree.num_simplices())
print(message)

diag = simplex_tree.persistence()

print("betti_numbers()=")
print(simplex_tree.betti_numbers())

# invert the persistence diagram
invert_diag = [
    (diag[pers][0], (1.0 - diag[pers][1][0], 1.0 - diag[pers][1][1]))
    for pers in range(len(diag))
github GUDHI / gudhi-devel / src / python / example / rips_persistence_diagram.py View on Github external
See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
    Author(s):       Vincent Rouvreau

    Copyright (C) 2016 Inria

    Modification(s):
      - YYYY/MM Author: Description of the modification
"""

__author__ = "Marc Glisse"
__copyright__ = "Copyright (C) 2016 Inria"
__license__ = "MIT"

print("#####################################################################")
print("RipsComplex creation from points")
rips = gudhi.RipsComplex(points=[[0, 0], [1, 0], [0, 1], [1, 1]], max_edge_length=42)

simplex_tree = rips.create_simplex_tree(max_dimension=1)


diag = simplex_tree.persistence(homology_coeff_field=2, min_persistence=0)
print("diag=", diag)

gudhi.plot_persistence_diagram(diag)
plot.show()
github scikit-tda / cechmate / cechmate / interfaces.py View on Github external
def rips__filtration_gudhi(D, p, coeff=2, doPlot=False):
    """
    Do the rips filtration, wrapping around the GUDHI library (for comparison)
    :param X: An Nxk matrix of points
    :param p: The order of homology to go up to
    :param coeff: The field coefficient of homology
    :returns Is: A dictionary of persistence diagrams, where Is[k] is \
        the persistence diagram for Hk 
    """
    import gudhi

    rips = gudhi.RipsComplex(distance_matrix=D, max_edge_length=np.inf)
    simplex_tree = rips.create_simplex_tree(max_dimension=p + 1)
    diag = simplex_tree.persistence(homology_coeff_field=coeff, min_persistence=0)
    if doPlot:
        pplot = gudhi.plot_persistence_diagram(diag)
        pplot.show()
    Is = []
    for i in range(p + 1):
        Is.append([])
    for (i, (b, d)) in diag:
        Is[i].append([b, d])
    for i in range(len(Is)):
        Is[i] = np.array(Is[i])
    return Is
github scikit-tda / cechmate / PhatCech.py View on Github external
def rips__filtration_gudhi(D, p, coeff = 2, doPlot = False):
    """
    Do the rips filtration, wrapping around the GUDHI library (for comparison)
    :param X: An Nxk matrix of points
    :param p: The order of homology to go up to
    :param coeff: The field coefficient of homology
    :returns Is: A dictionary of persistence diagrams, where Is[k] is \
        the persistence diagram for Hk 
    """
    import gudhi
    rips = gudhi.RipsComplex(distance_matrix=D,max_edge_length=np.inf)
    simplex_tree = rips.create_simplex_tree(max_dimension=p+1)
    diag = simplex_tree.persistence(homology_coeff_field=coeff, min_persistence=0)
    if doPlot:
        pplot = gudhi.plot_persistence_diagram(diag)
        pplot.show()
    Is = []
    for i in range(p+1):
        Is.append([])
    for (i, (b, d)) in diag:
        Is[i].append([b, d])
    for i in range(len(Is)):
        Is[i] = np.array(Is[i])
    return Is
github GUDHI / gudhi-devel / src / cython / example / alpha_rips_persistence_bottleneck_distance.py View on Github external
parser.add_argument("-f", "--file", type=str, required=True)
parser.add_argument("-t", "--threshold", type=float, default=0.5)
parser.add_argument("-d", "--max_dimension", type=int, default=1)

args = parser.parse_args()
with open(args.file, 'r') as f:
    first_line = f.readline()
    if (first_line == 'OFF\n') or (first_line == 'nOFF\n'):
        point_cloud = gudhi.read_off(off_file=args.file)
        print("#####################################################################")
        print("RipsComplex creation from points read in a OFF file")

        message = "RipsComplex with max_edge_length=" + repr(args.threshold)
        print(message)

        rips_complex = gudhi.RipsComplex(points=point_cloud,
                                         max_edge_length=args.threshold)

        rips_stree = rips_complex.create_simplex_tree(max_dimension=args.max_dimension)

        message = "Number of simplices=" + repr(rips_stree.num_simplices())
        print(message)

        rips_diag = rips_stree.persistence()

        print("#####################################################################")
        print("AlphaComplex creation from points read in a OFF file")

        message = "AlphaComplex with max_edge_length=" + repr(args.threshold)
        print(message)

        alpha_complex = gudhi.AlphaComplex(points=point_cloud)