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()
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
def testRipsstream(): # maxdim = 2 # filename = '/Users/naheed/PycharmProjects/PersistenceHomology/data/pointcloud.txt' # p = pc.TextPointCloud(filename, ' ') 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.02) rf.construct() print rf.write_boundarylists_to( '/Users/naheed/PycharmProjects/PersistenceHomology/data/eight_mat.fil') print len(rf) from src.ComputeInterval import IntervalComputation ci = IntervalComputation(rf) ci.compute_intervals(maxdim) npar = ci.get_intervals_asnumpyarray() print npar[:10] print npar.shape import numpy as np with open("test.csv", 'wb') as f: f.write("Dimension,Birth,Death\n") np.savetxt(f, npar, delimiter=",", fmt='%d,%.4f,%.4f') ci.print_BettiNumbers() from src.Intervalviz import PersistenceViz pv = PersistenceViz(ci.betti_intervals, replace_Inf=rf.maxfiltration_val) pv.draw_barcodes()
def test_pers_cohomology(): from src.AbsoluteCohom import FiltrationArrayCohomologyComputer fil = Filtration() # name = "/Users/naheed/NetBeansProjects/Toy-1" # name = "/Users/naheed/NetBeansProjects/jplex_explore/3437-7" # name = "/Users/naheed/NetBeansProjects/Toy-2 262143" # name = "/Users/naheed/NetBeansProjects/Toy-3 2047 (11 Vertex Big Cylce)" # name = "/Users/naheed/NetBeansProjects/jplex_explore/netscience_10101023" # fil.add_simplices_from_cliquefiles(name) # fil.add_simplices_from_file('../../data/zomorodian_fil.txt') fil.add_simplices_from_file('../../data/test_simplexfromfile.txt') print 'total number of Simplices: ', len(fil) cohomc = FiltrationArrayCohomologyComputer(filtr=fil, maxdim=2, maxfilter=fil.maxdeg + 1) cohomc.compute() cohomc.print_BettiNumbers() ci = IntervalComputation(fil) ci.compute_intervals(2) ci.print_BettiNumbers()
def testRipsstream(): # maxdim = 2 # filename = '/Users/naheed/PycharmProjects/PersistenceHomology/data/pointcloud.txt' # p = pc.TextPointCloud(filename, ' ') 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.02) rf.construct() print rf.write_boundarylists_to('/Users/naheed/PycharmProjects/PersistenceHomology/data/eight_mat.fil') print len(rf) from src.ComputeInterval import IntervalComputation ci = IntervalComputation(rf) ci.compute_intervals(maxdim) npar= ci.get_intervals_asnumpyarray() print npar[:10] print npar.shape import numpy as np with open("test.csv",'wb') as f: f.write("Dimension,Birth,Death\n") np.savetxt(f, npar, delimiter=",", fmt='%d,%.4f,%.4f') ci.print_BettiNumbers() from src.Intervalviz import PersistenceViz pv = PersistenceViz(ci.betti_intervals, replace_Inf=rf.maxfiltration_val) pv.draw_barcodes()
def test_persistencehomology(): fil = Filtration() # name = "/Users/naheed/NetBeansProjects/Toy-1" # name = "/Users/naheed/NetBeansProjects/jplex_explore/3437-7" # name = "/Users/naheed/NetBeansProjects/Toy-2 262143" # name = "/Users/naheed/NetBeansProjects/Toy-3 2047 (11 Vertex Big Cylce)" # name = "/Users/naheed/NetBeansProjects/jplex_explore/netscience_10101023" # fil.add_simplices_from_cliquefiles(name) # fil.add_simplices_from_file('../../data/zomorodian_fil.txt') fil.add_simplices_from_file('../../data/test_simplexfromfile.txt') print 'total number of Simplices: ', len(fil) ci = IntervalComputation(fil) ci.compute_intervals(3) ci.print_BettiNumbers() ci.get_representativs()
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)
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()
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)
def test_persistence_algorithm(N=10, D=50): from time import time from src.WeakWitnessFiltration import WeakWitnessStream import src.Selector as sel import src.PointCloud as pc abs_cohom_exectime = [0.0] * N abs_hom_exectime = [0.0] * N filtration_sizes = [0.0] * N for n in xrange(N): # print "Iteration: ", n # 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() # Typically for 2D, according to paper <= N/20. so N/20, N/25, N/30, N/35, N/40 is fine NumLandmarks = int(p.size / D) # print "#Landmark: ", NumLandmarks # Create Selector # pointcloud_sel = sel.PointCloudSelector(p, 10, "RandomSelector") pointcloud_sel = sel.PointCloudSelector(p, NumLandmarks, "MaxminSelector") # Select point pointcloud_sel.select() R = float(pointcloud_sel.get_maxdistance_landmarktoPointcloud()) # R = 0 # print 'R = ', R numdivision = 10 maxdim = 2 # Run Lazy Witness stream ws = WeakWitnessStream(mu=2, landmarkselector=pointcloud_sel, maxdistance=R, numdivision=numdivision, maxdimension=maxdim) ws.construct() filtration_sizes[n] = len(ws) start_time = time() cohom = FiltrationArrayCohomologyComputer(ws, maxdim, R) cohom.compute() abs_cohom_exectime[n] = time() - start_time start_time = time() ci = IntervalComputation(ws) ci.compute_intervals(maxdim) # I should abs_hom_exectime[n] = time() - start_time abs_hom_exectime = np.array(abs_hom_exectime) abs_cohom_exectime = np.array(abs_cohom_exectime) print "Average number of simplices in the filtration: \n", np.mean( filtration_sizes) print "Mean (,", N, " run) runtime for Absolute Homology: \n", np.mean( abs_hom_exectime) print "Standard deviation (", N, " run) runtime for Absolute Homology: \n", np.std( abs_hom_exectime) print "Mean (,", N, " run) runtime for Absolute Cohomology: \n", np.mean( abs_cohom_exectime) print "Standard deviation (", N, " run) runtime for Absolute Cohomology: \n", np.std( abs_cohom_exectime)
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
def test_persistence_algorithm(N=10, D=50): from time import time from src.WeakWitnessFiltration import WeakWitnessStream import src.Selector as sel import src.PointCloud as pc abs_cohom_exectime = [0.0] * N abs_hom_exectime = [0.0] * N filtration_sizes = [0.0] * N for n in xrange(N): # print "Iteration: ", n # 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() # Typically for 2D, according to paper <= N/20. so N/20, N/25, N/30, N/35, N/40 is fine NumLandmarks = int(p.size / D) # print "#Landmark: ", NumLandmarks # Create Selector # pointcloud_sel = sel.PointCloudSelector(p, 10, "RandomSelector") pointcloud_sel = sel.PointCloudSelector(p, NumLandmarks, "MaxminSelector") # Select point pointcloud_sel.select() R = float(pointcloud_sel.get_maxdistance_landmarktoPointcloud()) # R = 0 # print 'R = ', R numdivision = 10 maxdim = 2 # Run Lazy Witness stream ws = WeakWitnessStream(mu=2, landmarkselector=pointcloud_sel, maxdistance=R, numdivision=numdivision, maxdimension=maxdim) ws.construct() filtration_sizes[n] = len(ws) start_time = time() cohom = FiltrationArrayCohomologyComputer(ws, maxdim, R) cohom.compute() abs_cohom_exectime[n] = time() - start_time start_time = time() ci = IntervalComputation(ws) ci.compute_intervals(maxdim) # I should abs_hom_exectime[n] = time() - start_time abs_hom_exectime = np.array(abs_hom_exectime) abs_cohom_exectime = np.array(abs_cohom_exectime) print "Average number of simplices in the filtration: \n", np.mean(filtration_sizes) print "Mean (,", N, " run) runtime for Absolute Homology: \n", np.mean(abs_hom_exectime) print "Standard deviation (", N, " run) runtime for Absolute Homology: \n", np.std( abs_hom_exectime) print "Mean (,", N, " run) runtime for Absolute Cohomology: \n", np.mean(abs_cohom_exectime) print "Standard deviation (", N, " run) runtime for Absolute Cohomology: \n", np.std( abs_cohom_exectime)
def test_manual_Filtration(): # This example is a challenging one for cohomology fil = Filtration() # fil.add_simplex_toith_filtration(0, [0]) # fil.add_simplex_toith_filtration(0, [1]) # fil.add_simplex_toith_filtration(1, [2]) # fil.add_simplex_toith_filtration(1, [3]) # fil.add_simplex_toith_filtration(1, [0, 1]) # fil.add_simplex_toith_filtration(1, [1, 2]) # The simplices should be sorted # fil.add_simplex_toith_filtration(2, [0, 2]) # Another example. a square shape # print fil # fil.add_simplex_toith_filtration(0, [0]) # fil.add_simplex_toith_filtration(1, [1]) # # fil.add_simplex_toith_filtration(3, [3]) # fil.add_simplex_toith_filtration(2, [2]) # fil.add_simplex_toith_filtration(3, [3]) # fil.add_simplex_toith_filtration(4, [0, 1]) # fil.add_simplex_toith_filtration(5, [1, 2]) # fil.add_simplex_toith_filtration(6, [2, 3]) # fil.add_simplex_toith_filtration(7, [0, 3]) # fil.add_simplex_toith_filtration(8, [0, 2]) # fil.add_simplex_toith_filtration(9, [1, 3]) # fil.add_simplex_toith_filtration(10, [0, 2, 3]) # fil.add_simplex_toith_filtration(11, [0, 1, 2]) # fil.add_simplex_toith_filtration(12, [1, 2, 3]) # fil.add_simplex_toith_filtration(13, [0, 1, 3]) fil.add_simplex_toith_filtration(0, [0]) fil.add_simplex_toith_filtration(0, [1]) fil.add_simplex_toith_filtration(0, [2]) fil.add_simplex_toith_filtration(0, [3]) fil.add_simplex_toith_filtration(0, [0, 1]) fil.add_simplex_toith_filtration(0, [1, 2]) fil.add_simplex_toith_filtration(0, [2, 3]) fil.add_simplex_toith_filtration(0, [0, 3]) fil.add_simplex_toith_filtration(0, [0, 2]) fil.add_simplex_toith_filtration(0, [1, 3]) fil.add_simplex_toith_filtration(0, [0, 1, 2]) fil.add_simplex_toith_filtration(0, [0, 2, 3]) fil.add_simplex_toith_filtration(0, [0, 1, 3]) fil.add_simplex_toith_filtration(13, [1, 2, 3]) # print [str(sigma)+" id: "+ str(sigma.id) for sigma in fil.get_ksimplices_from_ithFiltration(0,0)] from src.AbsoluteCohom import * # simplices = [ # [0], [1],[0,1],[3],[1,3],[0,3],[0,1,3] # ] # filtration_vals = [0, 1, 2, 3, 4, 5, 6] # cohomc = NaiveCohomologyComputer(simplices,filtration_vals) # print cohomc.compute() cohomc = FiltrationArrayCohomologyComputer(filtr=fil, maxdim=2, maxfilter=16) cohomc.compute() cohomc.print_BettiNumbers() print "\n\n" ci = IntervalComputation(fil) ci.compute_intervals(2) ci.print_BettiNumbers()