コード例 #1
0
def testWitnessStream():
    from WitnessFiltration import WitnessStream
    from WeakWitnessFiltration import WeakWitnessStream
    # mean = [0, 0]
    # cov = [[1, 0], [0, 1]]
    # matrixofpoints_inR2 = np.random.multivariate_normal(mean, cov, 100)
    # p = pc.PointCloud(matrixofpoints_inR2)
    filename = '/Users/naheed/PycharmProjects/PersistenceHomology/data/eight.mat'
    p = pc.MatlabPointCloud(filename, 'point_cloud')
    p.compute_distancematrix()
    # Create Selector
    pointcloud_sel = sel.PointCloudSelector(p, 100, "RandomSelector")
    R = float(pointcloud_sel.get_maxdistance_landmarktoPointcloud()) / 2
    # R = 0
    print 'R = ', R
    numdivision = 5
    maxdim = 3
    # ws = WitnessStream(landmarkselector=pointcloud_sel, maxdistance=R, numdivision=numdivision, maxdimension=maxdim)
    ws = WeakWitnessStream(mu=2,
                           landmarkselector=pointcloud_sel,
                           maxdistance=R,
                           numdivision=numdivision,
                           maxdimension=maxdim)

    ws.construct
    print ws
    print "Total number of Simplices in the Filtration: ", len(ws)
コード例 #2
0
def testRandomSelector():
    # Create PointCloud
    matrixofpoints_inR2 = []
    mean = [0, 0]
    cov = [[1, 0], [0, 1]]
    matrixofpoints_inR2 = np.random.multivariate_normal(mean, cov, 100)
    p = pc.PointCloud(matrixofpoints_inR2)
    # Create Selector
    s = sel.PointCloudSelector(p, 5, "RandomSelector")
    print s.getLandmarkPoints().points

    print s.getdistance_subsetstoPointcloud()
コード例 #3
0
def comparebars():
    maxdim = 2
    filename = '/Users/naheed/PycharmProjects/PersistenceHomology/data/eight.mat'
    p = pc.MatlabPointCloud(filename, 'point_cloud')
    print p.dimension, p.size
    p.compute_distancematrix()
    print p.getdistance(0, 1)
    from src.RipsFiltration import BruteForceRips
    rf = BruteForceRips(p, 100, maxdim, 0.01)
    rf.construct()
    from src.ComputeInterval import IntervalComputation
    ci = IntervalComputation(rf)
    ci.compute_intervals(maxdim)
    print ci.betti_intervals

    from src.WeakWitnessFiltration import WeakWitnessStream
    filename = '/Users/naheed/PycharmProjects/PersistenceHomology/data/eight.mat'
    p2 = pc.MatlabPointCloud(filename, 'point_cloud')
    print p2.dimension, p2.size
    p2.compute_distancematrix()
    pointcloud_sel = sel.PointCloudSelector(p2, 200, "MaxminSelector")
    pointcloud_sel.select()
    R = 0.01
    print "R= ", R
    ws = WeakWitnessStream(mu=1,
                           landmarkselector=pointcloud_sel,
                           maxdistance=R,
                           numdivision=100,
                           maxdimension=maxdim)

    ws.construct()
    ci2 = IntervalComputation(ws)
    ci2.compute_intervals(maxdim)

    # print len(ci2.betti_intervals), len(ci.betti_intervals)

    from src.Intervalviz import PersistenceViz
    pv = PersistenceViz(ci.betti_intervals, replace_Inf=rf.maxfiltration_val)
    pv.qual_compare_barcodes(ci2.betti_intervals, R)
コード例 #4
0
def testWitnessStreamPH():
    from WitnessFiltration import WitnessStream
    from src.WeakWitnessFiltration import WeakWitnessStream
    from src.ComputeInterval import IntervalComputation

    # mean = [0, 0]
    # cov = [[1, 0], [0, 1]]
    # matrixofpoints_inR2 = np.random.multivariate_normal(mean, cov, 100)
    # p = pc.PointCloud(matrixofpoints_inR2)
    filename = '/Users/naheed/PycharmProjects/PersistenceHomology/data/eight.mat'
    p = pc.MatlabPointCloud(filename, 'point_cloud')
    p.compute_distancematrix()
    # Create Selector
    # pointcloud_sel = sel.PointCloudSelector(p, 10, "RandomSelector")
    pointcloud_sel = sel.PointCloudSelector(p, 50, "MaxminSelector")

    # Measuring system time elapsed since the epoch (UTC time-zone)
    start_time = time()
    pointcloud_sel.select()
    elapsed_time = time() - start_time

    R = float(pointcloud_sel.get_maxdistance_landmarktoPointcloud()) / 3
    # R = 0
    print 'R = ', R
    numdivision = 10
    maxdim = 2
    # ws = WitnessStream(landmarkselector=pointcloud_sel, maxdistance=R, numdivision=numdivision, maxdimension=maxdim)
    ws = WeakWitnessStream(mu=2,
                           landmarkselector=pointcloud_sel,
                           maxdistance=R,
                           numdivision=numdivision,
                           maxdimension=maxdim)
    ws.construct()
    print "Total number of Simplices in the Filtration: ", len(ws)
    ci = IntervalComputation(ws)
    ci.compute_intervals(
        maxdim
    )  # I should check everything is ok in this function since the deg for simplices can have real value now.
    ci.print_BettiNumbers()
コード例 #5
0
def testWitnessStreamPerCom():
    from WitnessFiltration import WitnessStream
    from src.WeakWitnessFiltration import WeakWitnessStream
    from src.AbsoluteCohomologyOptimized import *
    from src.ComputeInterval import IntervalComputation

    # mean = [0, 0]
    # cov = [[1, 0], [0, 1]]
    # matrixofpoints_inR2 = np.random.multivariate_normal(mean, cov, 100)
    # p = pc.PointCloud(matrixofpoints_inR2)
    filename = '/Users/naheed/PycharmProjects/PersistenceHomology/data/eight.mat'
    h = hpy()  # guppy heap object
    p = pc.MatlabPointCloud(filename, 'point_cloud')
    p.compute_distancematrix()
    # Create Selector
    # pointcloud_sel = sel.PointCloudSelector(p, 10, "RandomSelector")
    pointcloud_sel = sel.PointCloudSelector(p, 500, "MaxminSelector")

    # Measuring system time elapsed since the epoch (UTC time-zone)
    start_time = time()
    pointcloud_sel.select()
    elapsed_time = time() - start_time

    R = float(pointcloud_sel.get_maxdistance_landmarktoPointcloud())
    # R = 0
    print 'R = ', R
    numdivision = 10
    maxdim = 2
    # ws = WitnessStream(landmarkselector=pointcloud_sel, maxdistance=R, numdivision=numdivision, maxdimension=maxdim)
    ws = WeakWitnessStream(mu=2,
                           landmarkselector=pointcloud_sel,
                           maxdistance=R,
                           numdivision=numdivision,
                           maxdimension=maxdim)
    ws.construct()
    print "Total number of Simplices in the Filtration: ", len(ws)

    print "After ws.construct():\n", h.heap().size

    start_time = time()
    cohom = FiltrationArrayCohomologyComputer(filtr=ws,
                                              maxdim=maxdim,
                                              maxfilter=R)
    total_mem_consumed = h.heap().size
    cohom.compute()
    total_mem_consumed = h.heap().size - total_mem_consumed
    elapsed_time = time() - start_time
    print "time: ", elapsed_time
    print "After cohomology:\n", total_mem_consumed

    start_time = time()
    ci = IntervalComputation(ws)
    total_mem_consumed = h.heap().size
    ci.compute_intervals(
        maxdim
    )  # I should check everything is ok in this function since the deg for simplices can have real value now.
    total_mem_consumed = h.heap().size - total_mem_consumed
    ci.print_BettiNumbers()
    elapsed_time = time() - start_time
    print "time: ", elapsed_time
    print "After Homology:\n", total_mem_consumed