From 7fc669975e7fdb626ede64f2a13adec54cfbc0d2 Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Sun, 17 Jul 2016 12:56:35 +0200 Subject: removed unnecessary files --- benchmarks/benchmarks.txt | 10 - benchmarks/examples.txt | 4 - benchmarks/sphere_3_192/dionysus.txt | 28 -- benchmarks/sphere_3_192/dipha.txt | 58 --- benchmarks/sphere_3_192/gudhi.txt | 18 - benchmarks/sphere_3_192/phat.txt | 17 - benchmarks/sphere_3_192/ripser.txt | 268 ------------- benchmarks/sphere_3_64/dionysus.txt | 28 -- benchmarks/sphere_3_64/dipha.txt | 58 --- benchmarks/sphere_3_64/gudhi.txt | 18 - benchmarks/sphere_3_64/phat.txt | 17 - benchmarks/sphere_3_64/ripser.txt | 103 ----- examples/almostlinear4.lower_distance_matrix | 3 - examples/almostlinear4a.lower_distance_matrix | 3 - examples/almostlinear4b.lower_distance_matrix | 3 - examples/almostlinear4c.lower_distance_matrix | 3 - examples/linear5.lower_distance_matrix | 4 - ...ve_plane.compressed_lower_distance_matrix.dipha | Bin 1376 -> 0 bytes ...ne.compressed_lower_distance_matrix.dipha_pairs | Bin 384 -> 0 bytes examples/projective_plane.csv | 13 - examples/random20.lower_distance_matrix | 1 - examples/test.lower_distance_matrix | 4 - examples/test.upper_distance_matrix | 5 - examples/test2.lower_distance_matrix | 5 - examples/test2.upper_distance_matrix | 5 - prettyprint.hpp | 445 --------------------- ripser.xcodeproj/project.pbxproj | 252 ------------ 27 files changed, 1373 deletions(-) delete mode 100644 benchmarks/benchmarks.txt delete mode 100644 benchmarks/examples.txt delete mode 100644 benchmarks/sphere_3_192/dionysus.txt delete mode 100644 benchmarks/sphere_3_192/dipha.txt delete mode 100644 benchmarks/sphere_3_192/gudhi.txt delete mode 100644 benchmarks/sphere_3_192/phat.txt delete mode 100644 benchmarks/sphere_3_192/ripser.txt delete mode 100644 benchmarks/sphere_3_64/dionysus.txt delete mode 100644 benchmarks/sphere_3_64/dipha.txt delete mode 100644 benchmarks/sphere_3_64/gudhi.txt delete mode 100644 benchmarks/sphere_3_64/phat.txt delete mode 100644 benchmarks/sphere_3_64/ripser.txt delete mode 100644 examples/almostlinear4.lower_distance_matrix delete mode 100644 examples/almostlinear4a.lower_distance_matrix delete mode 100644 examples/almostlinear4b.lower_distance_matrix delete mode 100644 examples/almostlinear4c.lower_distance_matrix delete mode 100644 examples/linear5.lower_distance_matrix delete mode 100644 examples/projective_plane.compressed_lower_distance_matrix.dipha delete mode 100644 examples/projective_plane.compressed_lower_distance_matrix.dipha_pairs delete mode 100644 examples/projective_plane.csv delete mode 100644 examples/random20.lower_distance_matrix delete mode 100644 examples/test.lower_distance_matrix delete mode 100644 examples/test.upper_distance_matrix delete mode 100644 examples/test2.lower_distance_matrix delete mode 100644 examples/test2.upper_distance_matrix delete mode 100644 prettyprint.hpp delete mode 100644 ripser.xcodeproj/project.pbxproj diff --git a/benchmarks/benchmarks.txt b/benchmarks/benchmarks.txt deleted file mode 100644 index 9fbc688..0000000 --- a/benchmarks/benchmarks.txt +++ /dev/null @@ -1,10 +0,0 @@ -/usr/bin/time -l ~/Source/Dionysus/examples/cohomology/rips-pairwise-cohomology -s3 -p2 ~/Bitbucket/phat-paper/benchmark/point\ cloud/sphere_3_192_points.dat - -/usr/bin/time -l ~/Bitbucket/phat/benchmark --primal --bit_tree_pivot_column --twist ~/Bitbucket/phat-paper/benchmark/sphere_3_192_coboundary.phat - -/usr/bin/time -l ~/Bitbucket/dipha/dipha --benchmark --upper_dim 3 --dual ~/Bitbucket/phat-paper/benchmark/dipha/sphere_3_192.complex /dev/null - -/usr/bin/time -l ~/Source/Gudhi_library_1.3.0/example/Persistent_cohomology/rips_persistence -d3 -p2 ~/Bitbucket/phat-paper/benchmark/point\ cloud/sphere_3_192_points.dat -o/dev/null - -c++ -std=c++11 ripser.cpp -o ripser -Ofast -D NDEBUG -D FILE_FORMAT_DIPHA -D PRINT_PERSISTENCE_PAIRS && /usr/bin/time -l ./ripser --top_dim 2 ~/Bitbucket/phat-paper/benchmark/dipha/sphere_3_192.complex - diff --git a/benchmarks/examples.txt b/benchmarks/examples.txt deleted file mode 100644 index 39afeb6..0000000 --- a/benchmarks/examples.txt +++ /dev/null @@ -1,4 +0,0 @@ -c++ -std=c++14 ripser.cpp -o ripser -Ofast -D NDEBUG -D STORE_DIAMETERS -D FILE_FORMAT_UPPER_TRIANGULAR_CSV -D PRINT_PERSISTENCE_PAIRS && /usr/bin/time -l ./ripser --top_dim 1 ~/Downloads/avian_all_nt_concat_jukes_cantor.csv - -c++ -std=c++14 ripser.cpp -o ripser -Ofast -D NDEBUG -D STORE_DIAMETERS -D FILE_FORMAT_DIPHA -D PRINT_PERSISTENCE_PAIRS && /usr/bin/time -l ./ripser --top_dim 2 ~/Bitbucket/phat-paper/benchmark/dipha/sphere_3_192.complex - diff --git a/benchmarks/sphere_3_192/dionysus.txt b/benchmarks/sphere_3_192/dionysus.txt deleted file mode 100644 index 56e23d1..0000000 --- a/benchmarks/sphere_3_192/dionysus.txt +++ /dev/null @@ -1,28 +0,0 @@ -uli:Dionysus uli$ /usr/bin/time -l ~/Source/Dionysus/examples/cohomology/rips-pairwise-cohomology -s3 -p2 ~/Bitbucket/phat-paper/benchmark/point\ cloud/sphere_3_192_points.dat -Boundary matrix: -Cocycles: *.ccl -Vertices: -Diagram: -Simplex vector generated, size: 56050288 - -0% 10 20 30 40 50 60 70 80 90 100% -|----|----|----|----|----|----|----|----|----|----| -*************************************************** -Rips timer : Elapsed time [393.20] seconds -Persistence timer : Elapsed time [322.41] seconds -Total timer : Elapsed time [807.98] seconds - 843.40 real 787.80 user 26.13 sys -3240779776 maximum resident set size - 0 average shared memory size - 0 average unshared data size - 0 average unshared stack size - 4808144 page reclaims - 0 page faults - 0 swaps - 11 block input operations - 0 block output operations - 0 messages sent - 0 messages received - 0 signals received - 11585 voluntary context switches - 691823 involuntary context switches diff --git a/benchmarks/sphere_3_192/dipha.txt b/benchmarks/sphere_3_192/dipha.txt deleted file mode 100644 index 38cc112..0000000 --- a/benchmarks/sphere_3_192/dipha.txt +++ /dev/null @@ -1,58 +0,0 @@ -uli:dipha uli$ /usr/bin/time -l ~/Bitbucket/dipha/dipha --benchmark --upper_dim 3 --dual ~/Bitbucket/phat-paper/benchmark/dipha/sphere_3_192.complex /dev/null - -Input filename: -/Users/uli/Bitbucket/phat-paper/benchmark/dipha/sphere_3_192.complex - -upper_dim: 3 - -Number of processes used: -1 - -Detailed information for rank 0: - time prior mem peak mem bytes recv - 0.0s 3 MB 4 MB 0 MB complex.load_binary( input_filename, upper_dim ); - -Number of cells in input: -56050288 - 20.1s 4 MB 1714 MB 0 MB get_filtration_to_cell_map( complex, dualize, filtration_to_cell_map ); - 11.5s 431 MB 2756 MB 855 MB get_cell_to_filtration_map( complex.get_num_cells(), filtration_to_cell_map, cell_to_filtration_map ); - 1.9s 1713 MB 2756 MB 0 MB generate_unreduced_columns( complex, filtration_to_cell_map, cell_to_filtration_map, cur_dim, dualize, unreduced_columns ); - 0.0s 2144 MB 2756 MB 0 MB reduction_kernel( complex.get_num_cells(), unreduced_columns, reduced_columns ); - 1.7s 2145 MB 2756 MB 53 MB generate_unreduced_columns( complex, filtration_to_cell_map, cell_to_filtration_map, cur_dim, dualize, unreduced_columns ); - 0.1s 2226 MB 2756 MB 0 MB reduction_kernel( complex.get_num_cells(), unreduced_columns, reduced_columns ); - 35.9s 2244 MB 2809 MB 3349 MB generate_unreduced_columns( complex, filtration_to_cell_map, cell_to_filtration_map, cur_dim, dualize, unreduced_columns ); - 17.1s 1359 MB 2809 MB 0 MB reduction_kernel( complex.get_num_cells(), unreduced_columns, reduced_columns ); - 14.9s 943 MB 3638 MB 106 MB dipha::outputs::save_persistence_diagram( output_filename, complex, filtration_to_cell_map, reduced_columns, dualize, upper_dim ); - -Overall running time in seconds: -104.5 - -Reduction kernel running time in seconds: -17.2 - -Overall peak mem in GB of all ranks: -3.6 - -Individual peak mem in GB of per rank: -3.6 - -Maximal communication traffic (without sorting) in GB between any pair of nodes: -4.3 - -Total communication traffic (without sorting) in GB between all pairs of nodes: -4.3 - 104.51 real 71.06 user 25.97 sys -3815686144 maximum resident set size - 0 average shared memory size - 0 average unshared data size - 0 average unshared stack size - 8788553 page reclaims - 0 page faults - 0 swaps - 0 block input operations - 4 block output operations - 0 messages sent - 0 messages received - 0 signals received - 2337 voluntary context switches - 238131 involuntary context switches diff --git a/benchmarks/sphere_3_192/gudhi.txt b/benchmarks/sphere_3_192/gudhi.txt deleted file mode 100644 index 87763c8..0000000 --- a/benchmarks/sphere_3_192/gudhi.txt +++ /dev/null @@ -1,18 +0,0 @@ -uli:Gudhi_library_1.3.0 uli$ /usr/bin/time -l ~/Source/Gudhi_library_1.3.0/example/Persistent_cohomology/rips_persistence -d3 -p2 ~/Bitbucket/phat-paper/benchmark/point\ cloud/sphere_3_192_points.dat -o/dev/null -The complex contains 56050288 simplices - and has dimension 3 - 71.98 real 120.27 user 5.86 sys -2905890816 maximum resident set size - 0 average shared memory size - 0 average unshared data size - 0 average unshared stack size - 1535169 page reclaims - 129 page faults - 0 swaps - 0 block input operations - 0 block output operations - 0 messages sent - 0 messages received - 0 signals received - 1957 voluntary context switches - 168798 involuntary context switches diff --git a/benchmarks/sphere_3_192/phat.txt b/benchmarks/sphere_3_192/phat.txt deleted file mode 100644 index 3ebcfff..0000000 --- a/benchmarks/sphere_3_192/phat.txt +++ /dev/null @@ -1,17 +0,0 @@ -uli:phat uli$ /usr/bin/time -l ~/Bitbucket/phat/benchmark --primal --bit_tree_pivot_column --twist ~/Bitbucket/phat-paper/benchmark/sphere_3_192_coboundary.phat -/Users/uli/Bitbucket/phat-paper/benchmark/sphere_3_192_coboundary.phat, bit_tree_pivot_column, twist, primal, Reduction time: 2.649s - 16.91 real 12.22 user 4.38 sys -3742277632 maximum resident set size - 0 average shared memory size - 0 average unshared data size - 0 average unshared stack size - 1568913 page reclaims - 8 page faults - 0 swaps - 10 block input operations - 0 block output operations - 0 messages sent - 0 messages received - 0 signals received - 20 voluntary context switches - 13471 involuntary context switches diff --git a/benchmarks/sphere_3_192/ripser.txt b/benchmarks/sphere_3_192/ripser.txt deleted file mode 100644 index 60b7939..0000000 --- a/benchmarks/sphere_3_192/ripser.txt +++ /dev/null @@ -1,268 +0,0 @@ -uli:ripser uli$ c++ -std=c++11 ripser.cpp -o ripser -Ofast -D NDEBUG -D FILE_FORMAT_DIPHA -D PRINT_PERSISTENCE_PAIRS && /usr/bin/time -l ./ripser --top_dim 2 ~/Bitbucket/phat-paper/benchmark/dipha/sphere_3_192.complex -distance matrix with 192 points -distance matrix transformed to lower triangular form -value range: [0.00367531,2] -persistence intervals in dim 0: - [0,0.145018) - [0,0.0831521) - [0,0.115939) - [0,0.202564) - [0,0.0217315) - [0,0.127383) - [0,0.0387451) - [0,0.0623736) - [0,0.282169) - [0,0.126595) - [0,0.195722) - [0,0.0792212) - [0,0.149226) - [0,0.2286) - [0,0.197377) - [0,0.0651112) - [0,0.138674) - [0,0.147427) - [0,0.124774) - [0,0.293466) - [0,0.17493) - [0,0.131438) - [0,0.151643) - [0,0.208063) - [0,0.129741) - [0,0.127864) - [0,0.131638) - [0,0.0959033) - [0,0.150747) - [0,0.119187) - [0,0.0870489) - [0,0.165592) - [0,0.121955) - [0,0.1569) - [0,0.0433426) - [0,0.280629) - [0,0.0487061) - [0,0.0746054) - [0,0.0728647) - [0,0.0471186) - [0,0.0988752) - [0,0.111131) - [0,0.141823) - [0,0.249345) - [0,0.283881) - [0,0.0522132) - [0,0.157293) - [0,0.0496187) - [0,0.143151) - [0,0.135402) - [0,0.192733) - [0,0.057488) - [0,0.0311057) - [0,0.159282) - [0,0.109526) - [0,0.234112) - [0,0.084341) - [0,0.0593071) - [0,0.133033) - [0,0.240632) - [0,0.248879) - [0,0.134886) - [0,0.228917) - [0,0.249339) - [0,0.204544) - [0,0.048826) - [0,0.143085) - [0,0.231675) - [0,0.191661) - [0,0.0637053) - [0,0.0560443) - [0,0.142537) - [0,0.00367531) - [0,0.257997) - [0,0.037954) - [0,0.204208) - [0,0.201961) - [0,0.215759) - [0,0.162464) - [0,0.0692368) - [0,0.145725) - [0,0.205389) - [0,0.203812) - [0,0.15587) - [0,0.123527) - [0,0.108768) - [0,0.165314) - [0,0.0782455) - [0,0.0173134) - [0,0.176306) - [0,0.0741239) - [0,0.0831358) - [0,0.266592) - [0,0.0515157) - [0,0.223232) - [0,0.0120098) - [0,0.122089) - [0,0.147203) - [0,0.283562) - [0,0.304062) - [0,0.253227) - [0,0.164809) - [0,0.149017) - [0,0.133525) - [0,0.237571) - [0,0.0743236) - [0,0.0672609) - [0,0.218526) - [0,0.0559886) - [0,0.165907) - [0,0.0800348) - [0,0.192356) - [0,0.164815) - [0,0.142834) - [0,0.174172) - [0,0.0714516) - [0,0.227933) - [0,0.0702075) - [0,0.18428) - [0,0.0970981) - [0,0.133722) - [0,0.0753955) - [0,0.0884133) - [0,0.15244) - [0,0.157373) - [0,0.234969) - [0,0.173412) - [0,0.193791) - [0,0.147289) - [0,0.111798) - [0,0.277191) - [0,0.167455) - [0,0.189106) - [0,0.179609) - [0,0.297053) - [0,0.158413) - [0,0.165494) - [0,0.199673) - [0,0.227524) - [0,0.076909) - [0,0.332695) - [0,0.0802451) - [0,0.0994522) - [0,0.154095) - [0,0.274611) - [0,0.24348) - [0,0.207016) - [0,0.218561) - [0,0.270996) - [0,0.214018) - [0,0.323964) - [0,0.184757) - [0,0.193804) - [0,0.276431) - [0,0.175016) - [0,0.142152) - [0,0.0857401) - [0,0.207714) - [0,0.00391946) - [0,0.168587) - [0,0.192406) - [0,0.246491) - [0,0.148506) - [0,0.25725) - [0,0.165202) - [0,0.0814685) - [0,0.247042) - [0,0.0633425) - [0,0.253163) - [0,0.157251) - [0,0.285416) - [0,0.173586) - [0,0.210372) - [0,0.266635) - [0,0.316023) - [0,0.287316) - [0,0.264334) - [0,0.208851) - [0,0.277582) - [0,0.288591) - [0,0.231179) - [0,0.190642) - [0,0.24509) - [0,0.319493) - [0,0.207261) - [0,0.173684) - [0,0.264483) - [0,0.289189) - [0,0.23879) - [0,0.297933) - [0,0.268806) - [0, ) -persistence intervals in dim 1: - [0.542696,0.558863) - [0.531636,0.578093) - [0.530723,0.576869) - [0.463389,0.505345) - [0.445398,0.448892) - [0.443911,0.54761) - [0.431628,0.477277) - [0.413789,0.487379) - [0.412572,0.46308) - [0.411549,0.471715) - [0.409968,0.478461) - [0.386278,0.4922) - [0.381084,0.421374) - [0.377729,0.514046) - [0.377147,0.414788) - [0.377019,0.434385) - [0.374531,0.477153) - [0.370051,0.483155) - [0.361715,0.403181) - [0.354747,0.454956) - [0.352356,0.541947) - [0.350913,0.369543) - [0.35058,0.580726) - [0.347806,0.638039) - [0.347388,0.559978) - [0.344005,0.387193) - [0.34298,0.65758) - [0.339394,0.463666) - [0.33836,0.350411) - [0.33392,0.35111) - [0.33364,0.3797) - [0.331259,0.356381) - [0.329066,0.386148) - [0.324571,0.343083) - [0.324159,0.399094) - [0.322683,0.482958) - [0.318032,0.417462) - [0.317521,0.349622) - [0.316534,0.682559) - [0.309419,0.37151) - [0.309336,0.310216) - [0.308779,0.346297) - [0.304761,0.647803) - [0.301986,0.478334) - [0.301045,0.303943) - [0.29997,0.311993) - [0.298341,0.360737) - [0.279016,0.301331) - [0.2576,0.373749) - [0.253337,0.292286) - [0.24546,0.248903) - [0.240869,0.288747) - [0.189652,0.197515) -persistence intervals in dim 2: - [0.720484,1.65562) - 2.22 real 2.09 user 0.11 sys - 182439936 maximum resident set size - 0 average shared memory size - 0 average unshared data size - 0 average unshared stack size - 44546 page reclaims - 9 page faults - 0 swaps - 0 block input operations - 0 block output operations - 0 messages sent - 0 messages received - 0 signals received - 1 voluntary context switches - 1307 involuntary context switches diff --git a/benchmarks/sphere_3_64/dionysus.txt b/benchmarks/sphere_3_64/dionysus.txt deleted file mode 100644 index 52b879d..0000000 --- a/benchmarks/sphere_3_64/dionysus.txt +++ /dev/null @@ -1,28 +0,0 @@ -uli:Dionysus uli$ /usr/bin/time -l ~/Source/Dionysus/examples/cohomology/rips-pairwise-cohomology -s3 -p2 ~/Bitbucket/phat-paper/benchmark/point\ cloud/sphere_3_64_points.dat -Boundary matrix: -Cocycles: *.ccl -Vertices: -Diagram: -Simplex vector generated, size: 679120 - -0% 10 20 30 40 50 60 70 80 90 100% -|----|----|----|----|----|----|----|----|----|----| -*************************************************** -Rips timer : Elapsed time [3.01] seconds -Persistence timer : Elapsed time [1.98] seconds -Total timer : Elapsed time [5.85] seconds - 5.94 real 5.85 user 0.05 sys - 76812288 maximum resident set size - 0 average shared memory size - 0 average unshared data size - 0 average unshared stack size - 18766 page reclaims - 0 page faults - 0 swaps - 0 block input operations - 0 block output operations - 0 messages sent - 0 messages received - 0 signals received - 0 voluntary context switches - 2160 involuntary context switches diff --git a/benchmarks/sphere_3_64/dipha.txt b/benchmarks/sphere_3_64/dipha.txt deleted file mode 100644 index 67534d6..0000000 --- a/benchmarks/sphere_3_64/dipha.txt +++ /dev/null @@ -1,58 +0,0 @@ -uli:dipha uli$ /usr/bin/time -l ~/Bitbucket/dipha/dipha --benchmark --upper_dim 3 --dual ~/Bitbucket/phat-paper/benchmark/dipha/sphere_3_64.complex /dev/null - -Input filename: -/Users/uli/Bitbucket/phat-paper/benchmark/dipha/sphere_3_64.complex - -upper_dim: 3 - -Number of processes used: -1 - -Detailed information for rank 0: - time prior mem peak mem bytes recv - 0.0s 3 MB 3 MB 0 MB complex.load_binary( input_filename, upper_dim ); - -Number of cells in input: -679120 - 0.2s 3 MB 24 MB 0 MB get_filtration_to_cell_map( complex, dualize, filtration_to_cell_map ); - 0.1s 24 MB 69 MB 10 MB get_cell_to_filtration_map( complex.get_num_cells(), filtration_to_cell_map, cell_to_filtration_map ); - 0.0s 84 MB 85 MB 0 MB generate_unreduced_columns( complex, filtration_to_cell_map, cell_to_filtration_map, cur_dim, dualize, unreduced_columns ); - 0.0s 85 MB 85 MB 0 MB reduction_kernel( complex.get_num_cells(), unreduced_columns, reduced_columns ); - 0.0s 85 MB 88 MB 1 MB generate_unreduced_columns( complex, filtration_to_cell_map, cell_to_filtration_map, cur_dim, dualize, unreduced_columns ); - 0.0s 88 MB 89 MB 0 MB reduction_kernel( complex.get_num_cells(), unreduced_columns, reduced_columns ); - 0.3s 89 MB 122 MB 38 MB generate_unreduced_columns( complex, filtration_to_cell_map, cell_to_filtration_map, cur_dim, dualize, unreduced_columns ); - 0.1s 102 MB 142 MB 0 MB reduction_kernel( complex.get_num_cells(), unreduced_columns, reduced_columns ); - 0.1s 141 MB 142 MB 3 MB dipha::outputs::save_persistence_diagram( output_filename, complex, filtration_to_cell_map, reduced_columns, dualize, upper_dim ); - -Overall running time in seconds: -0.8 - -Reduction kernel running time in seconds: -0.1 - -Overall peak mem in GB of all ranks: -0.1 - -Individual peak mem in GB of per rank: -0.1 - -Maximal communication traffic (without sorting) in GB between any pair of nodes: -0.1 - -Total communication traffic (without sorting) in GB between all pairs of nodes: -0.1 - 0.81 real 0.65 user 0.13 sys - 149577728 maximum resident set size - 0 average shared memory size - 0 average unshared data size - 0 average unshared stack size - 51467 page reclaims - 0 page faults - 0 swaps - 0 block input operations - 1 block output operations - 0 messages sent - 0 messages received - 0 signals received - 7 voluntary context switches - 1069 involuntary context switches diff --git a/benchmarks/sphere_3_64/gudhi.txt b/benchmarks/sphere_3_64/gudhi.txt deleted file mode 100644 index ee69c4a..0000000 --- a/benchmarks/sphere_3_64/gudhi.txt +++ /dev/null @@ -1,18 +0,0 @@ -uli:Gudhi_library_1.3.0 uli$ /usr/bin/time -l ~/Source/Gudhi_library_1.3.0/example/Persistent_cohomology/rips_persistence -d3 -p2 ~/Bitbucket/phat-paper/benchmark/point\ cloud/sphere_3_64_points.dat -o/dev/null -The complex contains 679120 simplices - and has dimension 3 - 0.45 real 0.75 user 0.02 sys - 37740544 maximum resident set size - 0 average shared memory size - 0 average unshared data size - 0 average unshared stack size - 9124 page reclaims - 122 page faults - 0 swaps - 1 block input operations - 0 block output operations - 0 messages sent - 0 messages received - 0 signals received - 14 voluntary context switches - 2324 involuntary context switches diff --git a/benchmarks/sphere_3_64/phat.txt b/benchmarks/sphere_3_64/phat.txt deleted file mode 100644 index 0dff324..0000000 --- a/benchmarks/sphere_3_64/phat.txt +++ /dev/null @@ -1,17 +0,0 @@ -uli:phat uli$ /usr/bin/time -l ~/Bitbucket/phat/benchmark --primal --bit_tree_pivot_column --twist ~/Bitbucket/phat-paper/benchmark/sphere_3_64_coboundary.phat -/Users/uli/Bitbucket/phat-paper/benchmark/sphere_3_64_coboundary.phat, bit_tree_pivot_column, twist, primal, Reduction time: 0.019s - 0.22 real 0.15 user 0.04 sys - 47742976 maximum resident set size - 0 average shared memory size - 0 average unshared data size - 0 average unshared stack size - 11669 page reclaims - 2 page faults - 0 swaps - 2 block input operations - 0 block output operations - 0 messages sent - 0 messages received - 0 signals received - 4 voluntary context switches - 106 involuntary context switches diff --git a/benchmarks/sphere_3_64/ripser.txt b/benchmarks/sphere_3_64/ripser.txt deleted file mode 100644 index 016143d..0000000 --- a/benchmarks/sphere_3_64/ripser.txt +++ /dev/null @@ -1,103 +0,0 @@ -uli:ripser uli$ c++ -std=c++11 ripser.cpp -o ripser -Ofast -D NDEBUG -D FILE_FORMAT_DIPHA -D PRINT_PERSISTENCE_PAIRS && /usr/bin/time -l ./ripser --top_dim 2 ~/Bitbucket/phat-paper/benchmark/dipha/sphere_3_64.complex -distance matrix with 64 points -distance matrix transformed to lower triangular form -value range: [0.00391946,1.99927] -persistence intervals in dim 0: - [0,0.147289) - [0,0.111798) - [0,0.279354) - [0,0.379849) - [0,0.217485) - [0,0.179609) - [0,0.297053) - [0,0.227524) - [0,0.334523) - [0,0.205129) - [0,0.266643) - [0,0.076909) - [0,0.424333) - [0,0.0802451) - [0,0.141103) - [0,0.154095) - [0,0.280747) - [0,0.561426) - [0,0.255364) - [0,0.218561) - [0,0.344005) - [0,0.457212) - [0,0.339394) - [0,0.184757) - [0,0.193804) - [0,0.276431) - [0,0.276383) - [0,0.273482) - [0,0.162738) - [0,0.208851) - [0,0.00391946) - [0,0.168587) - [0,0.231288) - [0,0.370337) - [0,0.151879) - [0,0.336643) - [0,0.176636) - [0,0.0814685) - [0,0.287316) - [0,0.0633425) - [0,0.46675) - [0,0.169115) - [0,0.387245) - [0,0.354112) - [0,0.236525) - [0,0.377019) - [0,0.396994) - [0,0.58991) - [0,0.374531) - [0,0.374138) - [0,0.439977) - [0,0.487279) - [0,0.231179) - [0,0.200333) - [0,0.401576) - [0,0.574945) - [0,0.252863) - [0,0.173684) - [0,0.284319) - [0,0.355419) - [0,0.23879) - [0,0.381084) - [0,0.532104) - [0, ) -persistence intervals in dim 1: - [0.84172,1.04196) - [0.763446,0.863406) - [0.727244,0.74155) - [0.708398,0.757279) - [0.655113,0.849319) - [0.62495,0.753672) - [0.60904,0.682559) - [0.607973,0.672219) - [0.606907,0.829538) - [0.588045,1.04527) - [0.57698,0.769491) - [0.559498,0.586113) - [0.525224,0.645181) - [0.445398,0.448892) - [0.412572,0.478334) - [0.376457,0.63549) -persistence intervals in dim 2: - [1.10328,1.67029) - 0.05 real 0.05 user 0.00 sys - 4300800 maximum resident set size - 0 average shared memory size - 0 average unshared data size - 0 average unshared stack size - 1054 page reclaims - 9 page faults - 0 swaps - 0 block input operations - 0 block output operations - 0 messages sent - 0 messages received - 0 signals received - 1 voluntary context switches - 10 involuntary context switches diff --git a/examples/almostlinear4.lower_distance_matrix b/examples/almostlinear4.lower_distance_matrix deleted file mode 100644 index 0992677..0000000 --- a/examples/almostlinear4.lower_distance_matrix +++ /dev/null @@ -1,3 +0,0 @@ -1, -2,1, -1,1.9,1 diff --git a/examples/almostlinear4a.lower_distance_matrix b/examples/almostlinear4a.lower_distance_matrix deleted file mode 100644 index c0e94e6..0000000 --- a/examples/almostlinear4a.lower_distance_matrix +++ /dev/null @@ -1,3 +0,0 @@ -1, -2,1, -3,4,5 diff --git a/examples/almostlinear4b.lower_distance_matrix b/examples/almostlinear4b.lower_distance_matrix deleted file mode 100644 index c990b9b..0000000 --- a/examples/almostlinear4b.lower_distance_matrix +++ /dev/null @@ -1,3 +0,0 @@ -1, -2,1, -3,5,4 diff --git a/examples/almostlinear4c.lower_distance_matrix b/examples/almostlinear4c.lower_distance_matrix deleted file mode 100644 index da2bb0f..0000000 --- a/examples/almostlinear4c.lower_distance_matrix +++ /dev/null @@ -1,3 +0,0 @@ -1, -2,1, -4,3,5 diff --git a/examples/linear5.lower_distance_matrix b/examples/linear5.lower_distance_matrix deleted file mode 100644 index 9a6f670..0000000 --- a/examples/linear5.lower_distance_matrix +++ /dev/null @@ -1,4 +0,0 @@ -1, -2,1, -3,4,5, - diff --git a/examples/projective_plane.compressed_lower_distance_matrix.dipha b/examples/projective_plane.compressed_lower_distance_matrix.dipha deleted file mode 100644 index 8f091e0..0000000 Binary files a/examples/projective_plane.compressed_lower_distance_matrix.dipha and /dev/null differ diff --git a/examples/projective_plane.compressed_lower_distance_matrix.dipha_pairs b/examples/projective_plane.compressed_lower_distance_matrix.dipha_pairs deleted file mode 100644 index 2018749..0000000 Binary files a/examples/projective_plane.compressed_lower_distance_matrix.dipha_pairs and /dev/null differ diff --git a/examples/projective_plane.csv b/examples/projective_plane.csv deleted file mode 100644 index 6353b07..0000000 --- a/examples/projective_plane.csv +++ /dev/null @@ -1,13 +0,0 @@ -0,1,1,1,1,1,1,1,1,2,2,2,2 -1,0,2,2,2,1,2,1,2,1,2,2,2 -1,2,0,2,2,2,1,2,1,1,2,2,2 -1,2,2,0,2,1,2,2,1,2,2,2,1 -1,2,2,2,0,2,1,1,2,2,2,2,1 -1,1,2,1,2,0,2,2,2,1,1,2,1 -1,2,1,2,1,2,0,2,2,1,1,2,1 -1,1,2,2,1,2,2,0,2,1,2,1,1 -1,2,1,1,2,2,2,2,0,1,2,1,1 -2,1,1,2,2,1,1,1,1,0,1,1,2 -2,2,2,2,2,1,1,2,2,1,0,2,1 -2,2,2,2,2,2,2,1,1,1,2,0,1 -2,2,2,1,1,1,1,1,1,2,1,1,0 \ No newline at end of file diff --git a/examples/random20.lower_distance_matrix b/examples/random20.lower_distance_matrix deleted file mode 100644 index 241408f..0000000 --- a/examples/random20.lower_distance_matrix +++ /dev/null @@ -1 +0,0 @@ -68,6,155,10,173,171,168,52,32,63,136,16,78,163,8,175,28,70,107,165,18,97,99,118,49,76,48,133,58,92,44,57,190,101,25,94,148,37,2,146,56,95,125,121,142,31,21,152,154,124,75,120,112,45,39,115,170,179,157,183,15,14,38,182,151,164,185,96,127,41,53,180,166,122,134,100,20,169,36,40,87,46,140,82,187,71,12,178,159,184,189,3,86,61,137,93,116,167,150,186,126,172,29,34,135,27,144,177,73,19,147,17,26,1,139,22,69,9,138,160,181,105,24,129,91,11,64,103,132,130,4,47,66,85,65,149,109,161,81,128,7,113,67,77,54,35,30,74,98,114,5,176,158,62,89,79,156,102,119,141,51,143,108,131,106,33,123,43,174,55,83,80,145,104,153,13,188,90,117,111,60,84,23,59,88,110,42,50,72,162 \ No newline at end of file diff --git a/examples/test.lower_distance_matrix b/examples/test.lower_distance_matrix deleted file mode 100644 index e1aac02..0000000 --- a/examples/test.lower_distance_matrix +++ /dev/null @@ -1,4 +0,0 @@ -1, -2,3, -4,5,6, -7,8,9,10 diff --git a/examples/test.upper_distance_matrix b/examples/test.upper_distance_matrix deleted file mode 100644 index 274f252..0000000 --- a/examples/test.upper_distance_matrix +++ /dev/null @@ -1,5 +0,0 @@ -1, -3,4 -4,3,1, -3,4,3,1 -1,3,4,3,1 diff --git a/examples/test2.lower_distance_matrix b/examples/test2.lower_distance_matrix deleted file mode 100644 index 4bb81a4..0000000 --- a/examples/test2.lower_distance_matrix +++ /dev/null @@ -1,5 +0,0 @@ -1, -3,1, -4,3,1, -3,4,3,1, -1,3,4,3,1 diff --git a/examples/test2.upper_distance_matrix b/examples/test2.upper_distance_matrix deleted file mode 100644 index 9d4e39e..0000000 --- a/examples/test2.upper_distance_matrix +++ /dev/null @@ -1,5 +0,0 @@ -1,3,4,3,1, - 1,3,4,3, - 1,3,4, - 1,3, - 1 diff --git a/prettyprint.hpp b/prettyprint.hpp deleted file mode 100644 index 6bf2543..0000000 --- a/prettyprint.hpp +++ /dev/null @@ -1,445 +0,0 @@ -// Copyright Louis Delacroix 2010 - 2014. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// -// A pretty printing library for C++ -// -// Usage: -// Include this header, and operator<< will "just work". - -#ifndef H_PRETTY_PRINT -#define H_PRETTY_PRINT - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace pretty_print -{ - namespace detail - { - // SFINAE type trait to detect whether T::const_iterator exists. - - struct sfinae_base - { - using yes = char; - using no = yes[2]; - }; - - template - struct has_const_iterator : private sfinae_base - { - private: - template static yes & test(typename C::const_iterator*); - template static no & test(...); - public: - static const bool value = sizeof(test(nullptr)) == sizeof(yes); - using type = T; - }; - - template - struct has_begin_end : private sfinae_base - { - private: - template - static yes & f(typename std::enable_if< - std::is_same(&C::begin)), - typename C::const_iterator(C::*)() const>::value>::type *); - - template static no & f(...); - - template - static yes & g(typename std::enable_if< - std::is_same(&C::end)), - typename C::const_iterator(C::*)() const>::value, void>::type*); - - template static no & g(...); - - public: - static bool const beg_value = sizeof(f(nullptr)) == sizeof(yes); - static bool const end_value = sizeof(g(nullptr)) == sizeof(yes); - }; - - } // namespace detail - - - // Holds the delimiter values for a specific character type - - template - struct delimiters_values - { - using char_type = TChar; - const char_type * prefix; - const char_type * delimiter; - const char_type * postfix; - }; - - - // Defines the delimiter values for a specific container and character type - - template - struct delimiters - { - using type = delimiters_values; - static const type values; - }; - - - // Functor to print containers. You can use this directly if you want - // to specificy a non-default delimiters type. The printing logic can - // be customized by specializing the nested template. - - template , - typename TDelimiters = delimiters> - struct print_container_helper - { - using delimiters_type = TDelimiters; - using ostream_type = std::basic_ostream; - - template - struct printer - { - static void print_body(const U & c, ostream_type & stream) - { - using std::begin; - using std::end; - - auto it = begin(c); - const auto the_end = end(c); - - if (it != the_end) - { - for ( ; ; ) - { - stream << *it; - - if (++it == the_end) break; - - if (delimiters_type::values.delimiter != NULL) - stream << delimiters_type::values.delimiter; - } - } - } - }; - - print_container_helper(const T & container) - : container_(container) - { } - - inline void operator()(ostream_type & stream) const - { - if (delimiters_type::values.prefix != NULL) - stream << delimiters_type::values.prefix; - - printer::print_body(container_, stream); - - if (delimiters_type::values.postfix != NULL) - stream << delimiters_type::values.postfix; - } - - private: - const T & container_; - }; - - // Specialization for pairs - - template - template - struct print_container_helper::printer> - { - using ostream_type = print_container_helper::ostream_type; - - static void print_body(const std::pair & c, ostream_type & stream) - { - stream << c.first; - if (print_container_helper::delimiters_type::values.delimiter != NULL) - stream << print_container_helper::delimiters_type::values.delimiter; - stream << c.second; - } - }; - - // Specialization for tuples - - template - template - struct print_container_helper::printer> - { - using ostream_type = print_container_helper::ostream_type; - using element_type = std::tuple; - - template struct Int { }; - - static void print_body(const element_type & c, ostream_type & stream) - { - tuple_print(c, stream, Int<0>()); - } - - static void tuple_print(const element_type &, ostream_type &, Int) - { - } - - static void tuple_print(const element_type & c, ostream_type & stream, - typename std::conditional, std::nullptr_t>::type) - { - stream << std::get<0>(c); - tuple_print(c, stream, Int<1>()); - } - - template - static void tuple_print(const element_type & c, ostream_type & stream, Int) - { - if (print_container_helper::delimiters_type::values.delimiter != NULL) - stream << print_container_helper::delimiters_type::values.delimiter; - - stream << std::get(c); - - tuple_print(c, stream, Int()); - } - }; - - // Prints a print_container_helper to the specified stream. - - template - inline std::basic_ostream & operator<<( - std::basic_ostream & stream, - const print_container_helper & helper) - { - helper(stream); - return stream; - } - - - // Basic is_container template; specialize to derive from std::true_type for all desired container types - - template - struct is_container : public std::integral_constant::value && - detail::has_begin_end::beg_value && - detail::has_begin_end::end_value> { }; - - template - struct is_container : std::true_type { }; - - template - struct is_container : std::false_type { }; - - template - struct is_container> : std::true_type { }; - - template - struct is_container> : std::true_type { }; - - template - struct is_container> : std::true_type { }; - - - // Default delimiters - - template struct delimiters { static const delimiters_values values; }; - template const delimiters_values delimiters::values = { "[", ", ", "]" }; - template struct delimiters { static const delimiters_values values; }; - template const delimiters_values delimiters::values = { L"[", L", ", L"]" }; - - - // Delimiters for (multi)set and unordered_(multi)set - - template - struct delimiters< ::std::set, char> { static const delimiters_values values; }; - - template - const delimiters_values delimiters< ::std::set, char>::values = { "{", ", ", "}" }; - - template - struct delimiters< ::std::set, wchar_t> { static const delimiters_values values; }; - - template - const delimiters_values delimiters< ::std::set, wchar_t>::values = { L"{", L", ", L"}" }; - - template - struct delimiters< ::std::multiset, char> { static const delimiters_values values; }; - - template - const delimiters_values delimiters< ::std::multiset, char>::values = { "{", ", ", "}" }; - - template - struct delimiters< ::std::multiset, wchar_t> { static const delimiters_values values; }; - - template - const delimiters_values delimiters< ::std::multiset, wchar_t>::values = { L"{", L", ", L"}" }; - - template - struct delimiters< ::std::unordered_set, char> { static const delimiters_values values; }; - - template - const delimiters_values delimiters< ::std::unordered_set, char>::values = { "{", ", ", "}" }; - - template - struct delimiters< ::std::unordered_set, wchar_t> { static const delimiters_values values; }; - - template - const delimiters_values delimiters< ::std::unordered_set, wchar_t>::values = { L"{", L", ", L"}" }; - - template - struct delimiters< ::std::unordered_multiset, char> { static const delimiters_values values; }; - - template - const delimiters_values delimiters< ::std::unordered_multiset, char>::values = { "{", ", ", "}" }; - - template - struct delimiters< ::std::unordered_multiset, wchar_t> { static const delimiters_values values; }; - - template - const delimiters_values delimiters< ::std::unordered_multiset, wchar_t>::values = { L"{", L", ", L"}" }; - - - // Delimiters for pair and tuple - - template struct delimiters, char> { static const delimiters_values values; }; - template const delimiters_values delimiters, char>::values = { "(", ", ", ")" }; - template struct delimiters< ::std::pair, wchar_t> { static const delimiters_values values; }; - template const delimiters_values delimiters< ::std::pair, wchar_t>::values = { L"(", L", ", L")" }; - - template struct delimiters, char> { static const delimiters_values values; }; - template const delimiters_values delimiters, char>::values = { "(", ", ", ")" }; - template struct delimiters< ::std::tuple, wchar_t> { static const delimiters_values values; }; - template const delimiters_values delimiters< ::std::tuple, wchar_t>::values = { L"(", L", ", L")" }; - - - // Type-erasing helper class for easy use of custom delimiters. - // Requires TCharTraits = std::char_traits and TChar = char or wchar_t, and MyDelims needs to be defined for TChar. - // Usage: "cout << pretty_print::custom_delims(x)". - - struct custom_delims_base - { - virtual ~custom_delims_base() { } - virtual std::ostream & stream(::std::ostream &) = 0; - virtual std::wostream & stream(::std::wostream &) = 0; - }; - - template - struct custom_delims_wrapper : custom_delims_base - { - custom_delims_wrapper(const T & t_) : t(t_) { } - - std::ostream & stream(std::ostream & s) - { - return s << print_container_helper, Delims>(t); - } - - std::wostream & stream(std::wostream & s) - { - return s << print_container_helper, Delims>(t); - } - - private: - const T & t; - }; - - template - struct custom_delims - { - template - custom_delims(const Container & c) : base(new custom_delims_wrapper(c)) { } - - std::unique_ptr base; - }; - - template - inline std::basic_ostream & operator<<(std::basic_ostream & s, const custom_delims & p) - { - return p.base->stream(s); - } - - - // A wrapper for a C-style array given as pointer-plus-size. - // Usage: std::cout << pretty_print_array(arr, n) << std::endl; - - template - struct array_wrapper_n - { - typedef const T * const_iterator; - typedef T value_type; - - array_wrapper_n(const T * const a, size_t n) : _array(a), _n(n) { } - inline const_iterator begin() const { return _array; } - inline const_iterator end() const { return _array + _n; } - - private: - const T * const _array; - size_t _n; - }; - - - // A wrapper for hash-table based containers that offer local iterators to each bucket. - // Usage: std::cout << bucket_print(m, 4) << std::endl; (Prints bucket 5 of container m.) - - template - struct bucket_print_wrapper - { - typedef typename T::const_local_iterator const_iterator; - typedef typename T::size_type size_type; - - const_iterator begin() const - { - return m_map.cbegin(n); - } - - const_iterator end() const - { - return m_map.cend(n); - } - - bucket_print_wrapper(const T & m, size_type bucket) : m_map(m), n(bucket) { } - - private: - const T & m_map; - const size_type n; - }; - -} // namespace pretty_print - - -// Global accessor functions for the convenience wrappers - -template -inline pretty_print::array_wrapper_n pretty_print_array(const T * const a, size_t n) -{ - return pretty_print::array_wrapper_n(a, n); -} - -template pretty_print::bucket_print_wrapper -bucket_print(const T & m, typename T::size_type n) -{ - return pretty_print::bucket_print_wrapper(m, n); -} - - -// Main magic entry point: An overload snuck into namespace std. -// Can we do better? - -namespace std -{ - // Prints a container to the stream using default delimiters - - template - inline typename enable_if< ::pretty_print::is_container::value, - basic_ostream &>::type - operator<<(basic_ostream & stream, const T & container) - { - return stream << ::pretty_print::print_container_helper(container); - } -} - - - -#endif // H_PRETTY_PRINT diff --git a/ripser.xcodeproj/project.pbxproj b/ripser.xcodeproj/project.pbxproj deleted file mode 100644 index d924596..0000000 --- a/ripser.xcodeproj/project.pbxproj +++ /dev/null @@ -1,252 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 46; - objects = { - -/* Begin PBXBuildFile section */ - 55E113311BD63CF3002B6F51 /* ripser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 55E113301BD63CF3002B6F51 /* ripser.cpp */; settings = {ASSET_TAGS = (); }; }; -/* End PBXBuildFile section */ - -/* Begin PBXCopyFilesBuildPhase section */ - 551018461BD63CB300990BFF /* CopyFiles */ = { - isa = PBXCopyFilesBuildPhase; - buildActionMask = 2147483647; - dstPath = /usr/share/man/man1/; - dstSubfolderSpec = 0; - files = ( - ); - runOnlyForDeploymentPostprocessing = 1; - }; -/* End PBXCopyFilesBuildPhase section */ - -/* Begin PBXFileReference section */ - 551018481BD63CB300990BFF /* ripser */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = ripser; sourceTree = BUILT_PRODUCTS_DIR; }; - 55E113301BD63CF3002B6F51 /* ripser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ripser.cpp; sourceTree = SOURCE_ROOT; }; -/* End PBXFileReference section */ - -/* Begin PBXFrameworksBuildPhase section */ - 551018451BD63CB300990BFF /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - -/* Begin PBXGroup section */ - 5510183F1BD63CB300990BFF = { - isa = PBXGroup; - children = ( - 5510184A1BD63CB300990BFF /* ripser */, - 551018491BD63CB300990BFF /* Products */, - ); - sourceTree = ""; - }; - 551018491BD63CB300990BFF /* Products */ = { - isa = PBXGroup; - children = ( - 551018481BD63CB300990BFF /* ripser */, - ); - name = Products; - sourceTree = ""; - }; - 5510184A1BD63CB300990BFF /* ripser */ = { - isa = PBXGroup; - children = ( - 55E113301BD63CF3002B6F51 /* ripser.cpp */, - ); - path = ripser; - sourceTree = ""; - }; -/* End PBXGroup section */ - -/* Begin PBXNativeTarget section */ - 551018471BD63CB300990BFF /* ripser */ = { - isa = PBXNativeTarget; - buildConfigurationList = 5510184F1BD63CB300990BFF /* Build configuration list for PBXNativeTarget "ripser" */; - buildPhases = ( - 551018441BD63CB300990BFF /* Sources */, - 551018451BD63CB300990BFF /* Frameworks */, - 551018461BD63CB300990BFF /* CopyFiles */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = ripser; - productName = ripser; - productReference = 551018481BD63CB300990BFF /* ripser */; - productType = "com.apple.product-type.tool"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - 551018401BD63CB300990BFF /* Project object */ = { - isa = PBXProject; - attributes = { - LastUpgradeCheck = 0700; - ORGANIZATIONNAME = "ulrich-bauer.org"; - TargetAttributes = { - 551018471BD63CB300990BFF = { - CreatedOnToolsVersion = 7.0.1; - }; - }; - }; - buildConfigurationList = 551018431BD63CB300990BFF /* Build configuration list for PBXProject "ripser" */; - compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; - hasScannedForEncodings = 0; - knownRegions = ( - en, - ); - mainGroup = 5510183F1BD63CB300990BFF; - productRefGroup = 551018491BD63CB300990BFF /* Products */; - projectDirPath = ""; - projectRoot = ""; - targets = ( - 551018471BD63CB300990BFF /* ripser */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXSourcesBuildPhase section */ - 551018441BD63CB300990BFF /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 55E113311BD63CF3002B6F51 /* ripser.cpp in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - -/* Begin XCBuildConfiguration section */ - 5510184D1BD63CB300990BFF /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = dwarf; - ENABLE_STRICT_OBJC_MSGSEND = YES; - ENABLE_TESTABILITY = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_DYNAMIC_NO_PIC = NO; - GCC_NO_COMMON_BLOCKS = YES; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - HEADER_SEARCH_PATHS = /opt/local/include; - MACOSX_DEPLOYMENT_TARGET = 10.11; - MTL_ENABLE_DEBUG_INFO = YES; - ONLY_ACTIVE_ARCH = YES; - SDKROOT = macosx; - }; - name = Debug; - }; - 5510184E1BD63CB300990BFF /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - ENABLE_NS_ASSERTIONS = NO; - ENABLE_STRICT_OBJC_MSGSEND = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_NO_COMMON_BLOCKS = YES; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - HEADER_SEARCH_PATHS = /opt/local/include; - MACOSX_DEPLOYMENT_TARGET = 10.11; - MTL_ENABLE_DEBUG_INFO = NO; - SDKROOT = macosx; - }; - name = Release; - }; - 551018501BD63CB300990BFF /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - GCC_PREPROCESSOR_DEFINITIONS = ( - "$(inherited)", - FILE_FORMAT_UPPER_TRIANGULAR_CSV, - USE_COEFFICIENTS, - STORE_DIAMETERS, - PRINT_PERSISTENCE_PAIRS, - ); - PRODUCT_NAME = "$(TARGET_NAME)"; - }; - name = Debug; - }; - 551018511BD63CB300990BFF /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - PRODUCT_NAME = "$(TARGET_NAME)"; - }; - name = Release; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - 551018431BD63CB300990BFF /* Build configuration list for PBXProject "ripser" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 5510184D1BD63CB300990BFF /* Debug */, - 5510184E1BD63CB300990BFF /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 5510184F1BD63CB300990BFF /* Build configuration list for PBXNativeTarget "ripser" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 551018501BD63CB300990BFF /* Debug */, - 551018511BD63CB300990BFF /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; -/* End XCConfigurationList section */ - }; - rootObject = 551018401BD63CB300990BFF /* Project object */; -} -- cgit v1.2.3 From 257abf0674e7cf81e43c674d7b92a69c67ab7f00 Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Thu, 15 Sep 2016 16:25:21 +0200 Subject: upgraded XCode project --- ripser.xcodeproj/project.pbxproj | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ripser.xcodeproj/project.pbxproj b/ripser.xcodeproj/project.pbxproj index 04bc3a6..2aa6179 100644 --- a/ripser.xcodeproj/project.pbxproj +++ b/ripser.xcodeproj/project.pbxproj @@ -88,7 +88,7 @@ 551018401BD63CB300990BFF /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0700; + LastUpgradeCheck = 0800; ORGANIZATIONNAME = "ulrich-bauer.org"; TargetAttributes = { 551018471BD63CB300990BFF = { @@ -138,8 +138,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; @@ -181,8 +183,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; -- cgit v1.2.3 From 09ad67d33adeb7443685214954c7b447a94ebdc2 Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Thu, 15 Sep 2016 16:25:39 +0200 Subject: added first version of sparse distance matrix --- ripser.cpp | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/ripser.cpp b/ripser.cpp index 5568f32..b2226fc 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -294,6 +294,27 @@ public: size_t size() const { return rows.size(); } }; +class sparse_distance_matrix { +public: + std::vector> neighbors; + + template + sparse_distance_matrix(const DistanceMatrix& mat, value_t threshold) + : neighbors(mat.size()) + { + + for (index_t i = 1; i < size(); ++i) + for (index_t j = 0; j < size(); ++j) + if (mat(i, j) <= threshold) + neighbors[i].push_back(diameter_index_t(mat(i, j), j)); + } + + value_t operator()(const index_t i, const index_t j) const; + + size_t size() const { return neighbors.size(); } +}; + + template <> void compressed_distance_matrix::init_rows() { value_t* pointer = &distances[0]; for (index_t i = 1; i < size(); ++i) { @@ -468,6 +489,11 @@ void assemble_columns_to_reduce(std::vector& columns_to_reduce index_t n, value_t threshold, const binomial_coeff_table& binomial_coeff) { index_t num_simplices = binomial_coeff(n, dim + 2); + // iterate over all (previous) columns_to_reduce + // find cofaces, additional vertices + // if additional vertex is larger than all current ones: append to columns_to_reduce + + columns_to_reduce.clear(); #ifdef INDICATE_PROGRESS @@ -584,6 +610,9 @@ void compute_pairs(std::vector& columns_to_reduce, hash_map Date: Fri, 16 Sep 2016 14:47:38 +0200 Subject: intermediate commit --- ripser.cpp | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/ripser.cpp b/ripser.cpp index b2226fc..a477ce6 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -315,6 +315,87 @@ public: }; +template +class set_intersection_enumerator { +public: + InputIteratorCollection first, last; + + set_intersection_enumerator (InputIteratorCollection _first, InputIteratorCollection _last) : first(_first), last(_last) {} + +// template +// set_intersection_enumerator (InputCollection _set) : first(_first), last(_last) {} + + bool has_next() { + for (auto &it0 = first[0], end0 = last[0]; it0 != end0; ++it0) { + auto x = *it0; + for (size_t idx = 1; idx < first.size(); ++idx) { + auto &it = first[idx], end = last[idx]; + while (*it < x) if (++it == end) return false; + if (*it > x) goto continue_outer; + } + return true; + continue_outer: ; + } + return false; + } + + // only valid after has_next() has been called + decltype(*first[0]) next() { + return *first[0]++; + } +}; + + +class simplex_coboundary_enumerator_sparse { +private: + index_t idx, modified_idx, v, k; + const binomial_coeff_table& binomial_coeff; + const sparse_distance_matrix& sparse_dist; + std::vector vertices; + + std::vector::const_reverse_iterator> ii, ee; + set_intersection_enumerator v_intersection; + +public: + simplex_coboundary_enumerator_sparse(index_t _idx, index_t _dim, index_t _n, const binomial_coeff_table& _binomial_coeff, sparse_distance_matrix& _sparse_dist) + : idx(_idx), modified_idx(_idx), v(_n - 1), k(_dim + 1), binomial_coeff(_binomial_coeff), sparse_dist(_sparse_dist), v_intersection(ii, ee) + { + get_simplex_vertices(idx, _dim, _n, _binomial_coeff, std::back_inserter(vertices)); + + for (auto v: vertices) { + ii.push_back(sparse_dist.neighbors[v].rbegin()); + ee.push_back(sparse_dist.neighbors[v].rend()); + } + + vertices.push_back(-1); + + } + + bool has_next() { + return v_intersection.has_next(); + } + + std::pair next() { + + auto v = v_intersection.has_next(); + + while (k > 0 && vertices[k - 1] > v) { + vertices[k] = vertices[k - 1]; + --k; + } + + vertices[k] = v; + + //... + auto result = std::make_pair(make_entry(modified_idx + binomial_coeff(v, k + 1), k & 1 ? -1 : 1), v); + + + return result; + } +}; + + + template <> void compressed_distance_matrix::init_rows() { value_t* pointer = &distances[0]; for (index_t i = 1; i < size(); ++i) { -- cgit v1.2.3 From 01f16a612b8d30a1cc7dc000a5e7d79f00238b2d Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Fri, 16 Sep 2016 19:57:59 +0200 Subject: sparse coboundary enumerator (untested) --- ripser.cpp | 72 ++++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 39 insertions(+), 33 deletions(-) diff --git a/ripser.cpp b/ripser.cpp index 28c8b3c..2a62170 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -94,30 +94,36 @@ std::vector multiplicative_inverse_vector(const coefficient_t m) return inverse; } +void get_next_vertex(index_t& v, const index_t idx, const index_t k, const binomial_coeff_table& binomial_coeff) { + + if (binomial_coeff(v, k) > idx) { + index_t count = v; + while (count > 0) { + index_t i = v; + index_t step = count >> 1; + i -= step; + if (binomial_coeff(i, k) > idx) { + v = --i; + count -= step + 1; + } else + count = step; + } + } + assert(binomial_coeff(v, k) <= idx); + assert(binomial_coeff(v + 1, k) > idx); +} + + template -OutputIterator get_simplex_vertices(index_t idx, const index_t dim, index_t n, +OutputIterator get_simplex_vertices(index_t idx, const index_t dim, index_t v, const binomial_coeff_table& binomial_coeff, OutputIterator out) { - --n; + --v; for (index_t k = dim + 1; k > 0; --k) { - if (binomial_coeff(n, k) > idx) { - index_t count = n; - while (count > 0) { - index_t i = n; - index_t step = count >> 1; - i -= step; - if (binomial_coeff(i, k) > idx) { - n = --i; - count -= step + 1; - } else - count = step; - } - } - assert(binomial_coeff(n, k) <= idx); - assert(binomial_coeff(n + 1, k) > idx); + get_next_vertex(v, idx, k, binomial_coeff); - *out++ = n; - idx -= binomial_coeff(n, k); + *out++ = v; + idx -= binomial_coeff(v, k); } return out; @@ -349,7 +355,7 @@ public: class simplex_coboundary_enumerator_sparse { private: - index_t idx, modified_idx, v, k; + index_t idx_below, idx_above, v, k, w; const binomial_coeff_table& binomial_coeff; const sparse_distance_matrix& sparse_dist; std::vector vertices; @@ -359,16 +365,14 @@ private: public: simplex_coboundary_enumerator_sparse(index_t _idx, index_t _dim, index_t _n, const binomial_coeff_table& _binomial_coeff, sparse_distance_matrix& _sparse_dist) - : idx(_idx), modified_idx(_idx), v(_n - 1), k(_dim + 1), binomial_coeff(_binomial_coeff), sparse_dist(_sparse_dist), v_intersection(ii, ee) + : idx_below(_idx), idx_above(0), v(_n - 1), k(_dim + 1), w(_n - 1), binomial_coeff(_binomial_coeff), sparse_dist(_sparse_dist), v_intersection(ii, ee) { - get_simplex_vertices(idx, _dim, _n, _binomial_coeff, std::back_inserter(vertices)); + get_simplex_vertices(idx_below, _dim, _n, _binomial_coeff, std::back_inserter(vertices)); for (auto v: vertices) { ii.push_back(sparse_dist.neighbors[v].rbegin()); ee.push_back(sparse_dist.neighbors[v].rend()); } - - vertices.push_back(-1); } @@ -378,17 +382,19 @@ public: std::pair next() { - auto v = v_intersection.has_next(); - - while (k > 0 && vertices[k - 1] > v) { - vertices[k] = vertices[k - 1]; - --k; - } + index_t v = get_index(v_intersection.next()); + + while (w > v && idx_below > 0) { + get_next_vertex(w, idx_below, k, binomial_coeff); - vertices[k] = v; + idx_below -= binomial_coeff(w, k); + idx_above += binomial_coeff(w, k + 1); - //... - auto result = std::make_pair(make_entry(modified_idx + binomial_coeff(v, k + 1), k & 1 ? -1 : 1), v); + --k; + assert(k != -1); + } + + auto result = std::make_pair(make_entry(idx_above + binomial_coeff(v, k + 1) + idx_below, k & 1 ? -1 : 1), v); return result; -- cgit v1.2.3 From 5d356d18ab38d85c255927419a45ff6736e1595d Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Fri, 16 Sep 2016 21:14:04 +0200 Subject: sparse coboundary enumerator --- ripser.cpp | 50 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/ripser.cpp b/ripser.cpp index 2a62170..85e94f6 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -310,9 +310,9 @@ public: : neighbors(mat.size()) { - for (index_t i = 1; i < size(); ++i) + for (index_t i = 0; i < size(); ++i) for (index_t j = 0; j < size(); ++j) - if (mat(i, j) <= threshold) + if (i != j && mat(i, j) <= threshold) neighbors[i].push_back(diameter_index_t(mat(i, j), j)); } @@ -322,23 +322,42 @@ public: }; -template +template +struct second_argument_greater { + bool operator()(const T &lhs, const T &rhs) const + { + return lhs.second > rhs.second; + } +}; + +template +struct second_argument_equal_to { + bool operator()(const T &lhs, const T &rhs) const + { + return lhs.second == rhs.second; + } +}; + +template class set_intersection_enumerator { public: - InputIteratorCollection first, last; - - set_intersection_enumerator (InputIteratorCollection _first, InputIteratorCollection _last) : first(_first), last(_last) {} + InputIteratorCollection &first, &last; + Compare comp; + Equal equal; + + set_intersection_enumerator (InputIteratorCollection& _first, InputIteratorCollection& _last) : first(_first), last(_last) {} // template // set_intersection_enumerator (InputCollection _set) : first(_first), last(_last) {} bool has_next() { - for (auto &it0 = first[0], end0 = last[0]; it0 != end0; ++it0) { + for (auto &it0 = first[0], &end0 = last[0]; it0 != end0; ++it0) { auto x = *it0; for (size_t idx = 1; idx < first.size(); ++idx) { auto &it = first[idx], end = last[idx]; - while (*it < x) if (++it == end) return false; - if (*it > x) goto continue_outer; + while (comp(*it, x)) if (++it == end) return false; + auto y = *it; + if (!equal(y, x)) goto continue_outer; } return true; continue_outer: ; @@ -361,7 +380,7 @@ private: std::vector vertices; std::vector::const_reverse_iterator> ii, ee; - set_intersection_enumerator v_intersection; + set_intersection_enumerator, second_argument_equal_to> v_intersection; public: simplex_coboundary_enumerator_sparse(index_t _idx, index_t _dim, index_t _n, const binomial_coeff_table& _binomial_coeff, sparse_distance_matrix& _sparse_dist) @@ -373,7 +392,8 @@ public: ii.push_back(sparse_dist.neighbors[v].rbegin()); ee.push_back(sparse_dist.neighbors[v].rend()); } - + + get_next_vertex(w, idx_below, k, binomial_coeff); } bool has_next() { @@ -384,13 +404,17 @@ public: index_t v = get_index(v_intersection.next()); + + while (w > v && idx_below > 0) { - get_next_vertex(w, idx_below, k, binomial_coeff); - idx_below -= binomial_coeff(w, k); idx_above += binomial_coeff(w, k + 1); --k; + + get_next_vertex(w, idx_below, k, binomial_coeff); + + assert(k != -1); } -- cgit v1.2.3 From 29b383df930009dfe43d9629bc666d18345a96ac Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Fri, 16 Sep 2016 21:38:57 +0200 Subject: sparse coboundary enumerator --- ripser.cpp | 29 +++++------------------------ 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/ripser.cpp b/ripser.cpp index 85e94f6..820a3d3 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -94,7 +94,7 @@ std::vector multiplicative_inverse_vector(const coefficient_t m) return inverse; } -void get_next_vertex(index_t& v, const index_t idx, const index_t k, const binomial_coeff_table& binomial_coeff) { +index_t get_next_vertex(index_t& v, const index_t idx, const index_t k, const binomial_coeff_table& binomial_coeff) { if (binomial_coeff(v, k) > idx) { index_t count = v; @@ -111,6 +111,8 @@ void get_next_vertex(index_t& v, const index_t idx, const index_t k, const binom } assert(binomial_coeff(v, k) <= idx); assert(binomial_coeff(v + 1, k) > idx); + + return v; } @@ -321,7 +323,6 @@ public: size_t size() const { return neighbors.size(); } }; - template struct second_argument_greater { bool operator()(const T &lhs, const T &rhs) const @@ -347,9 +348,6 @@ public: set_intersection_enumerator (InputIteratorCollection& _first, InputIteratorCollection& _last) : first(_first), last(_last) {} -// template -// set_intersection_enumerator (InputCollection _set) : first(_first), last(_last) {} - bool has_next() { for (auto &it0 = first[0], &end0 = last[0]; it0 != end0; ++it0) { auto x = *it0; @@ -371,7 +369,6 @@ public: } }; - class simplex_coboundary_enumerator_sparse { private: index_t idx_below, idx_above, v, k, w; @@ -392,8 +389,6 @@ public: ii.push_back(sparse_dist.neighbors[v].rbegin()); ee.push_back(sparse_dist.neighbors[v].rend()); } - - get_next_vertex(w, idx_below, k, binomial_coeff); } bool has_next() { @@ -401,32 +396,18 @@ public: } std::pair next() { - index_t v = get_index(v_intersection.next()); - - - while (w > v && idx_below > 0) { + while (k > 0 && get_next_vertex(w, idx_below, k, binomial_coeff) > v) { idx_below -= binomial_coeff(w, k); idx_above += binomial_coeff(w, k + 1); - --k; - - get_next_vertex(w, idx_below, k, binomial_coeff); - - - assert(k != -1); } - auto result = std::make_pair(make_entry(idx_above + binomial_coeff(v, k + 1) + idx_below, k & 1 ? -1 : 1), v); - - - return result; + return std::make_pair(make_entry(idx_above + binomial_coeff(v, k + 1) + idx_below, k & 1 ? -1 : 1), v); } }; - - template <> void compressed_distance_matrix::init_rows() { value_t* pointer = &distances[0]; for (index_t i = 1; i < size(); ++i) { -- cgit v1.2.3 From 5794ba59f5621c6ec70ffa75a938d61c9342d4e3 Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Mon, 19 Sep 2016 10:02:02 +0200 Subject: restructured coboundary enumerator --- ripser.cpp | 292 ++++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 181 insertions(+), 111 deletions(-) diff --git a/ripser.cpp b/ripser.cpp index 208ebb0..80b00d3 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -111,11 +111,10 @@ index_t get_next_vertex(index_t& v, const index_t idx, const index_t k, const bi } assert(binomial_coeff(v, k) <= idx); assert(binomial_coeff(v + 1, k) > idx); - + return v; } - template OutputIterator get_simplex_vertices(index_t idx, const index_t dim, index_t v, const binomial_coeff_table& binomial_coeff, OutputIterator out) { @@ -246,14 +245,26 @@ public: } }; -class simplex_coboundary_enumerator { +template class simplex_coboundary_enumerator { private: index_t idx_below, idx_above, v, k; + + std::vector vertices; + + const diameter_entry_t simplex; + + const coefficient_t modulus; + const DistanceMatrix& dist; const binomial_coeff_table& binomial_coeff; public: - simplex_coboundary_enumerator(index_t _idx, index_t _dim, index_t _n, const binomial_coeff_table& _binomial_coeff) - : idx_below(_idx), idx_above(0), v(_n - 1), k(_dim + 1), binomial_coeff(_binomial_coeff) {} + simplex_coboundary_enumerator(const diameter_entry_t _simplex, index_t _dim, index_t _n, + const coefficient_t _modulus, const DistanceMatrix& _dist, + const binomial_coeff_table& _binomial_coeff) + : simplex(_simplex), idx_below(get_index(_simplex)), idx_above(0), v(_n - 1), k(_dim + 1), modulus(_modulus), + binomial_coeff(_binomial_coeff), dist(_dist), vertices(_dim + 1) { + get_simplex_vertices(get_index(_simplex), _dim, _n, binomial_coeff, vertices.begin()); + } bool has_next() { while ((v != -1) && (binomial_coeff(v, k) <= idx_below)) { @@ -267,8 +278,16 @@ public: return v != -1; } - std::pair next() { - auto result = std::make_pair(make_entry(idx_above + binomial_coeff(v, k + 1) + idx_below, k & 1 ? -1 : 1), v); + std::pair next() { + + value_t coface_diameter = get_diameter(simplex); + for (index_t w : vertices) { coface_diameter = std::max(coface_diameter, dist(v, w)); } + + coefficient_t coface_coefficient = (k & 1 ? -1 + modulus : 1) * get_coefficient(simplex) % modulus; + + auto result = std::make_pair( + make_diameter_entry(coface_diameter, idx_above + binomial_coeff(v, k + 1) + idx_below, coface_coefficient), + v); --v; return result; } @@ -308,14 +327,11 @@ public: std::vector> neighbors; template - sparse_distance_matrix(const DistanceMatrix& mat, value_t threshold) - : neighbors(mat.size()) - { + sparse_distance_matrix(const DistanceMatrix& mat, value_t threshold) : neighbors(mat.size()) { for (index_t i = 0; i < size(); ++i) for (index_t j = 0; j < size(); ++j) - if (i != j && mat(i, j) <= threshold) - neighbors[i].push_back(diameter_index_t(mat(i, j), j)); + if (i != j && mat(i, j) <= threshold) neighbors[i].push_back(diameter_index_t(mat(i, j), j)); } value_t operator()(const index_t i, const index_t j) const; @@ -323,88 +339,107 @@ public: size_t size() const { return neighbors.size(); } }; -template -struct second_argument_greater { - bool operator()(const T &lhs, const T &rhs) const - { - return lhs.second > rhs.second; - } +template struct second_argument_greater { + bool operator()(const T& lhs, const T& rhs) const { return lhs.second > rhs.second; } }; -template -struct second_argument_equal_to { - bool operator()(const T &lhs, const T &rhs) const - { - return lhs.second == rhs.second; - } +template struct second_argument_equal_to { + bool operator()(const T& lhs, const T& rhs) const { return lhs.second == rhs.second; } }; -template +template class set_intersection_enumerator { public: - InputIteratorCollection &first, &last; + InputIteratorCollection &ii, ⅇ Compare comp; Equal equal; - - set_intersection_enumerator (InputIteratorCollection& _first, InputIteratorCollection& _last) : first(_first), last(_last) {} - - bool has_next() { - for (auto &it0 = first[0], &end0 = last[0]; it0 != end0; ++it0) { - auto x = *it0; - for (size_t idx = 1; idx < first.size(); ++idx) { - auto &it = first[idx], end = last[idx]; - while (comp(*it, x)) if (++it == end) return false; + Representative rep; + + set_intersection_enumerator(InputIteratorCollection& _first, InputIteratorCollection& _last) + : ii(_first), ee(_last) {} + + bool has_next() { + for (auto &it0 = ii[0], &end0 = ee[0]; it0 != end0; ++it0) { + auto x = *it0; + for (size_t idx = 1; idx < ii.size(); ++idx) { + auto &it = ii[idx], end = ee[idx]; + while (comp(*it, x)) + if (++it == end) return false; auto y = *it; - if (!equal(y, x)) goto continue_outer; - } - return true; - continue_outer: ; - } - return false; - } - - // only valid after has_next() has been called - decltype(*first[0]) next() { - return *first[0]++; - } + if (!equal(y, x)) + goto continue_outer; + else + x = rep(x, y); + } + return true; + continue_outer:; + } + return false; + } + + // only valid after has_next() has been called + decltype(*ii[0]) next() { return *ii[0]++; } }; class simplex_coboundary_enumerator_sparse { private: - index_t idx_below, idx_above, v, k, w; + index_t idx_below, idx_above, v, k, max_vertex_below; const binomial_coeff_table& binomial_coeff; - const sparse_distance_matrix& sparse_dist; - std::vector vertices; - - std::vector::const_reverse_iterator> ii, ee; - set_intersection_enumerator, second_argument_equal_to> v_intersection; + const sparse_distance_matrix& sparse_dist; + std::vector vertices; + + const value_t simplex_diameter; + + std::vector::const_reverse_iterator> ii, ee; + + diameter_index_t x; public: - simplex_coboundary_enumerator_sparse(index_t _idx, index_t _dim, index_t _n, const binomial_coeff_table& _binomial_coeff, sparse_distance_matrix& _sparse_dist) - : idx_below(_idx), idx_above(0), v(_n - 1), k(_dim + 1), w(_n - 1), binomial_coeff(_binomial_coeff), sparse_dist(_sparse_dist), v_intersection(ii, ee) - { - get_simplex_vertices(idx_below, _dim, _n, _binomial_coeff, std::back_inserter(vertices)); - - for (auto v: vertices) { - ii.push_back(sparse_dist.neighbors[v].rbegin()); - ee.push_back(sparse_dist.neighbors[v].rend()); - } - } + simplex_coboundary_enumerator_sparse(diameter_index_t _simplex, index_t _dim, index_t _n, + const binomial_coeff_table& _binomial_coeff, + const sparse_distance_matrix& _sparse_dist) + : simplex_diameter(get_diameter(_simplex)), idx_below(get_index(_simplex)), idx_above(0), v(_n - 1), + k(_dim + 1), max_vertex_below(_n - 1), binomial_coeff(_binomial_coeff), sparse_dist(_sparse_dist) { + get_simplex_vertices(idx_below, _dim, _n, _binomial_coeff, std::back_inserter(vertices)); + + for (auto v : vertices) { + ii.push_back(sparse_dist.neighbors[v].rbegin()); + ee.push_back(sparse_dist.neighbors[v].rend()); + } + } bool has_next() { - return v_intersection.has_next(); + for (auto &it0 = ii[0], &end0 = ee[0]; it0 != end0; ++it0) { + x = *it0; + for (size_t idx = 1; idx < ii.size(); ++idx) { + auto &it = ii[idx], end = ee[idx]; + while (get_index(*it) > get_index(x)) + if (++it == end) return false; + auto y = *it; + if (get_index(y) != get_index(x)) + goto continue_outer; + else + x = std::min(x, y, greater_diameter_or_smaller_index()); + } + return true; + continue_outer:; + } + return false; } - std::pair next() { - index_t v = get_index(v_intersection.next()); - - while (k > 0 && get_next_vertex(w, idx_below, k, binomial_coeff) > v) { - idx_below -= binomial_coeff(w, k); - idx_above += binomial_coeff(w, k + 1); + std::pair next() { + index_t covertex = get_index(x); + + while (k > 0 && get_next_vertex(max_vertex_below, idx_below, k, binomial_coeff) > covertex) { + idx_below -= binomial_coeff(max_vertex_below, k); + idx_above += binomial_coeff(max_vertex_below, k + 1); --k; } - - return std::make_pair(make_entry(idx_above + binomial_coeff(v, k + 1) + idx_below, k & 1 ? -1 : 1), v); + + return std::make_pair(make_diameter_entry(get_diameter(x), + idx_above + binomial_coeff(covertex, k + 1) + idx_below, + k & 1 ? -1 : 1), + covertex); } }; @@ -582,10 +617,60 @@ void assemble_columns_to_reduce(std::vector& columns_to_reduce index_t n, value_t threshold, const binomial_coeff_table& binomial_coeff) { index_t num_simplices = binomial_coeff(n, dim + 2); - // iterate over all (previous) columns_to_reduce - // find cofaces, additional vertices - // if additional vertex is larger than all current ones: append to columns_to_reduce + columns_to_reduce.clear(); + +#ifdef INDICATE_PROGRESS + std::cout << "\033[K" + << "assembling " << num_simplices << " columns" << std::flush << "\r"; +#endif + + for (index_t index = 0; index < num_simplices; ++index) { + if (pivot_column_index.find(index) == pivot_column_index.end()) { + value_t diameter = comp.diameter(index); + if (diameter <= threshold) columns_to_reduce.push_back(std::make_pair(diameter, index)); + } + } + +#ifdef INDICATE_PROGRESS + std::cout << "\033[K" + << "sorting " << num_simplices << " columns" << std::flush << "\r"; +#endif + std::sort(columns_to_reduce.begin(), columns_to_reduce.end(), + greater_diameter_or_smaller_index()); +#ifdef INDICATE_PROGRESS + std::cout << "\033[K"; +#endif +} + +template +void assemble_columns_to_reduce_sparse(std::vector& columns_to_reduce, + hash_map& pivot_column_index, const Comparator& comp, + index_t dim, index_t n, value_t threshold, + const binomial_coeff_table& binomial_coeff, + const sparse_distance_matrix& sparse_dist) { + index_t num_simplices = binomial_coeff(n, dim + 2); + + // iterate over all (previous) columns_to_reduce + // find cofaces, additional vertices + // if additional vertex is larger than all current ones: append to columns_to_reduce + + std::vector previous_columns_to_reduce; + previous_columns_to_reduce.swap(columns_to_reduce); + for (diameter_index_t simplex : previous_columns_to_reduce) { + // coface_entries.clear(); + simplex_coboundary_enumerator_sparse cofaces(simplex, dim, n, binomial_coeff, sparse_dist); + + while (cofaces.has_next()) { + auto coface_descriptor = cofaces.next(); + auto coface = coface_descriptor.first; + index_t covertex = get_index(coface_descriptor.second); + index_t coface_index = get_index(coface); + value_t coface_diameter = get_diameter(coface_descriptor.first); + // for (index_t v : vertices) { coface_diameter = std::max(coface_diameter, dist(v, covertex)); } + assert(comp.diameter(coface_index) == coface_diameter); + } + } columns_to_reduce.clear(); @@ -615,9 +700,9 @@ void assemble_columns_to_reduce(std::vector& columns_to_reduce template void compute_pairs(std::vector& columns_to_reduce, hash_map& pivot_column_index, - const DistanceMatrix& dist, const ComparatorCofaces& comp, const Comparator& comp_prev, index_t dim, - index_t n, value_t threshold, coefficient_t modulus, - const std::vector& multiplicative_inverse, + index_t dim, index_t n, value_t threshold, coefficient_t modulus, + const std::vector& multiplicative_inverse, const DistanceMatrix& dist, + const ComparatorCofaces& comp, const Comparator& comp_prev, const binomial_coeff_table& binomial_coeff) { #ifdef PRINT_PERSISTENCE_PAIRS @@ -682,51 +767,36 @@ void compute_pairs(std::vector& columns_to_reduce, hash_map cofaces(simplex, dim, n, modulus, dist, binomial_coeff); + while (cofaces.has_next()) { - auto coface_descriptor = cofaces.next(); - entry_t coface = coface_descriptor.first; - index_t covertex = coface_descriptor.second; - index_t coface_index = get_index(coface); - value_t coface_diameter = get_diameter(simplex); - for (index_t v : vertices) { coface_diameter = std::max(coface_diameter, dist(v, covertex)); } - assert(comp.diameter(coface_index) == coface_diameter); - - if (coface_diameter <= threshold) { - coefficient_t coface_coefficient = - (get_coefficient(coface) + modulus) * simplex_coefficient % modulus; - assert(coface_coefficient >= 0); - - diameter_entry_t coface_entry = - make_diameter_entry(coface_diameter, coface_index, coface_coefficient); - coface_entries.push_back(coface_entry); - - if (might_be_apparent_pair && (get_diameter(simplex) == coface_diameter)) { - if (pivot_column_index.find(coface_index) == pivot_column_index.end()) { - pivot = coface_entry; + diameter_entry_t coface = cofaces.next().first; + assert(comp.diameter(get_index(coface)) == get_diameter(coface)); + + if (get_diameter(coface) <= threshold) { + coface_entries.push_back(coface); + + if (might_be_apparent_pair && (get_diameter(simplex) == get_diameter(coface))) { + if (pivot_column_index.find(get_index(coface)) == pivot_column_index.end()) { + pivot = coface; goto found_persistence_pair; } might_be_apparent_pair = false; @@ -1064,8 +1134,8 @@ int main(int argc, char** argv) { hash_map pivot_column_index; pivot_column_index.reserve(columns_to_reduce.size()); - compute_pairs(columns_to_reduce, pivot_column_index, dist, comp, comp_prev, dim, n, threshold, modulus, - multiplicative_inverse, binomial_coeff); + compute_pairs(columns_to_reduce, pivot_column_index, dim, n, threshold, modulus, multiplicative_inverse, dist, + comp, comp_prev, binomial_coeff); if (dim < dim_max) { assemble_columns_to_reduce(columns_to_reduce, pivot_column_index, comp, dim, n, threshold, binomial_coeff); -- cgit v1.2.3 From 51b07afc8e3d68d2c8dac8ef2916672ecffd9bfa Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Mon, 19 Sep 2016 18:05:09 +0200 Subject: cleanup --- ripser.cpp | 112 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 55 insertions(+), 57 deletions(-) diff --git a/ripser.cpp b/ripser.cpp index 80b00d3..c2213df 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -178,7 +178,11 @@ template struct smaller_index { bool operator()(const Entry& a, const Entry& b) { return get_index(a) < get_index(b); } }; -typedef std::pair diameter_index_t; +class diameter_index_t: public std::pair { +public: + diameter_index_t() : std::pair() {} + diameter_index_t(std::pair p) : std::pair(p) {} +}; value_t get_diameter(diameter_index_t i) { return i.first; } index_t get_index(diameter_index_t i) { return i.second; } @@ -187,6 +191,12 @@ public: diameter_entry_t(std::pair p) : std::pair(p) {} diameter_entry_t(entry_t e) : std::pair(0, e) {} diameter_entry_t() : diameter_entry_t(0) {} + diameter_entry_t(value_t _diameter, index_t _index, coefficient_t _coefficient) + : std::pair(_diameter, make_entry(_index, _coefficient)) {} + diameter_entry_t(diameter_index_t _diameter_index, coefficient_t _coefficient) + : std::pair(get_diameter(_diameter_index), + make_entry(get_index(_diameter_index), _coefficient)) {} + diameter_entry_t(diameter_index_t _diameter_index) : diameter_entry_t(_diameter_index, 1) {} }; const entry_t& get_entry(const diameter_entry_t& p) { return p.second; } @@ -195,12 +205,6 @@ const index_t get_index(const diameter_entry_t& p) { return get_index(get_entry( const coefficient_t get_coefficient(const diameter_entry_t& p) { return get_coefficient(get_entry(p)); } const value_t& get_diameter(const diameter_entry_t& p) { return p.first; } void set_coefficient(diameter_entry_t& p, const coefficient_t c) { set_coefficient(get_entry(p), c); } -diameter_entry_t make_diameter_entry(value_t _diameter, index_t _index, coefficient_t _coefficient) { - return std::make_pair(_diameter, make_entry(_index, _coefficient)); -} -diameter_entry_t make_diameter_entry(diameter_index_t _diameter_index, coefficient_t _coefficient) { - return std::make_pair(get_diameter(_diameter_index), make_entry(get_index(_diameter_index), _coefficient)); -} template struct greater_diameter_or_smaller_index { bool operator()(const Entry& a, const Entry& b) { @@ -278,18 +282,16 @@ public: return v != -1; } - std::pair next() { + index_t next_index() { return idx_above + binomial_coeff(v--, k + 1) + idx_below; } + + diameter_entry_t next() { value_t coface_diameter = get_diameter(simplex); for (index_t w : vertices) { coface_diameter = std::max(coface_diameter, dist(v, w)); } coefficient_t coface_coefficient = (k & 1 ? -1 + modulus : 1) * get_coefficient(simplex) % modulus; - auto result = std::make_pair( - make_diameter_entry(coface_diameter, idx_above + binomial_coeff(v, k + 1) + idx_below, coface_coefficient), - v); - --v; - return result; + return diameter_entry_t(coface_diameter, idx_above + binomial_coeff(v, k + 1) + idx_below, coface_coefficient); } }; @@ -388,18 +390,20 @@ private: const sparse_distance_matrix& sparse_dist; std::vector vertices; - const value_t simplex_diameter; + const diameter_entry_t simplex; std::vector::const_reverse_iterator> ii, ee; diameter_index_t x; + const coefficient_t modulus; + public: - simplex_coboundary_enumerator_sparse(diameter_index_t _simplex, index_t _dim, index_t _n, - const binomial_coeff_table& _binomial_coeff, - const sparse_distance_matrix& _sparse_dist) - : simplex_diameter(get_diameter(_simplex)), idx_below(get_index(_simplex)), idx_above(0), v(_n - 1), - k(_dim + 1), max_vertex_below(_n - 1), binomial_coeff(_binomial_coeff), sparse_dist(_sparse_dist) { + simplex_coboundary_enumerator_sparse(const diameter_entry_t _simplex, index_t _dim, index_t _n, + const coefficient_t _modulus, const sparse_distance_matrix& _sparse_dist, + const binomial_coeff_table& _binomial_coeff) + : simplex(_simplex), idx_below(get_index(_simplex)), idx_above(0), v(_n - 1), k(_dim + 1), + max_vertex_below(_n - 1), modulus(_modulus), sparse_dist(_sparse_dist), binomial_coeff(_binomial_coeff) { get_simplex_vertices(idx_below, _dim, _n, _binomial_coeff, std::back_inserter(vertices)); for (auto v : vertices) { @@ -427,19 +431,21 @@ public: return false; } - std::pair next() { - index_t covertex = get_index(x); + diameter_entry_t next() { - while (k > 0 && get_next_vertex(max_vertex_below, idx_below, k, binomial_coeff) > covertex) { + while (k > 0 && get_next_vertex(max_vertex_below, idx_below, k, binomial_coeff) > get_index(x)) { idx_below -= binomial_coeff(max_vertex_below, k); idx_above += binomial_coeff(max_vertex_below, k + 1); --k; } - return std::make_pair(make_diameter_entry(get_diameter(x), - idx_above + binomial_coeff(covertex, k + 1) + idx_below, - k & 1 ? -1 : 1), - covertex); + value_t coface_diameter = std::max(get_diameter(simplex), get_diameter(x)); + + coefficient_t coface_coefficient = (k & 1 ? -1 + modulus : 1) * get_coefficient(simplex) % modulus; + + return diameter_entry_t(get_diameter(x), + idx_above + binomial_coeff(get_index(x), k + 1) + idx_below, + k & 1 ? -1 : 1); } }; @@ -646,10 +652,9 @@ void assemble_columns_to_reduce(std::vector& columns_to_reduce template void assemble_columns_to_reduce_sparse(std::vector& columns_to_reduce, hash_map& pivot_column_index, const Comparator& comp, - index_t dim, index_t n, value_t threshold, - const binomial_coeff_table& binomial_coeff, - const sparse_distance_matrix& sparse_dist) { - index_t num_simplices = binomial_coeff(n, dim + 2); + index_t dim, index_t n, value_t threshold, const coefficient_t modulus, + const sparse_distance_matrix& sparse_dist, + const binomial_coeff_table& binomial_coeff) { // iterate over all (previous) columns_to_reduce // find cofaces, additional vertices @@ -659,16 +664,12 @@ void assemble_columns_to_reduce_sparse(std::vector& columns_to previous_columns_to_reduce.swap(columns_to_reduce); for (diameter_index_t simplex : previous_columns_to_reduce) { // coface_entries.clear(); - simplex_coboundary_enumerator_sparse cofaces(simplex, dim, n, binomial_coeff, sparse_dist); + simplex_coboundary_enumerator_sparse cofaces(simplex, dim, n, modulus, sparse_dist, binomial_coeff); while (cofaces.has_next()) { - auto coface_descriptor = cofaces.next(); - auto coface = coface_descriptor.first; - index_t covertex = get_index(coface_descriptor.second); - index_t coface_index = get_index(coface); - value_t coface_diameter = get_diameter(coface_descriptor.first); - // for (index_t v : vertices) { coface_diameter = std::max(coface_diameter, dist(v, covertex)); } - assert(comp.diameter(coface_index) == coface_diameter); + auto coface = cofaces.next(); + + columns_to_reduce.push_back(std::make_pair(get_diameter(coface), get_index(coface))); } } @@ -679,12 +680,12 @@ void assemble_columns_to_reduce_sparse(std::vector& columns_to << "assembling " << num_simplices << " columns" << std::flush << "\r"; #endif - for (index_t index = 0; index < num_simplices; ++index) { - if (pivot_column_index.find(index) == pivot_column_index.end()) { - value_t diameter = comp.diameter(index); - if (diameter <= threshold) columns_to_reduce.push_back(std::make_pair(diameter, index)); - } - } +// for (index_t index = 0; index < num_simplices; ++index) { +// if (pivot_column_index.find(index) == pivot_column_index.end()) { +// value_t diameter = comp.diameter(index); +// if (diameter <= threshold) columns_to_reduce.push_back(std::make_pair(diameter, index)); +// } +// } #ifdef INDICATE_PROGRESS std::cout << "\033[K" @@ -745,15 +746,15 @@ void compute_pairs(std::vector& columns_to_reduce, hash_map& columns_to_reduce, hash_map cofaces(simplex, dim, n, modulus, dist, binomial_coeff); while (cofaces.has_next()) { - diameter_entry_t coface = cofaces.next().first; + diameter_entry_t coface = cofaces.next(); assert(comp.diameter(get_index(coface)) == get_diameter(coface)); if (get_diameter(coface) <= threshold) { @@ -848,20 +849,17 @@ void compute_pairs(std::vector& columns_to_reduce, hash_map 0); -#else - const coefficient_t coefficient = 1; + set_coefficient(e, inverse * get_coefficient(e) % modulus); + assert(get_coefficient(e) > 0); #endif - reduction_matrix.push_back(make_diameter_entry(get_diameter(e), index, coefficient)); + reduction_matrix.push_back(e); } #else #ifdef USE_COEFFICIENTS reduction_coefficients.pop_back(); - reduction_coefficients.push_back(make_diameter_entry(column_to_reduce, inverse)); + reduction_coefficients.push_back(diameter_entry_t(column_to_reduce, inverse)); #endif #endif break; @@ -1097,7 +1095,7 @@ int main(int argc, char** argv) { rips_filtration_comparator comp(dist, 1, binomial_coeff); for (index_t index = binomial_coeff(n, 2); index-- > 0;) { value_t diameter = comp.diameter(index); - if (diameter <= threshold) edges.push_back(diameter_index_t(diameter, index)); + if (diameter <= threshold) edges.push_back(std::make_pair(diameter, index)); } std::sort(edges.rbegin(), edges.rend(), greater_diameter_or_smaller_index()); -- cgit v1.2.3 From ad46246d05aaef70d523b96d483e5a6407404cb1 Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Mon, 19 Sep 2016 18:22:37 +0200 Subject: small bugs fixed --- ripser.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ripser.cpp b/ripser.cpp index c2213df..1405865 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -291,7 +291,7 @@ public: coefficient_t coface_coefficient = (k & 1 ? -1 + modulus : 1) * get_coefficient(simplex) % modulus; - return diameter_entry_t(coface_diameter, idx_above + binomial_coeff(v, k + 1) + idx_below, coface_coefficient); + return diameter_entry_t(coface_diameter, idx_above + binomial_coeff(v--, k + 1) + idx_below, coface_coefficient); } }; @@ -443,9 +443,9 @@ public: coefficient_t coface_coefficient = (k & 1 ? -1 + modulus : 1) * get_coefficient(simplex) % modulus; - return diameter_entry_t(get_diameter(x), + return diameter_entry_t(coface_diameter, idx_above + binomial_coeff(get_index(x), k + 1) + idx_below, - k & 1 ? -1 : 1); + coface_coefficient); } }; -- cgit v1.2.3 From 42a60a47c9bf12c5249fdea9b354fe352170950f Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Tue, 20 Sep 2016 09:35:45 +0200 Subject: bug fix in sparse coboundary enumerator --- ripser.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ripser.cpp b/ripser.cpp index 1405865..e16679c 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -333,7 +333,7 @@ public: for (index_t i = 0; i < size(); ++i) for (index_t j = 0; j < size(); ++j) - if (i != j && mat(i, j) <= threshold) neighbors[i].push_back(diameter_index_t(mat(i, j), j)); + if (i != j && mat(i, j) <= threshold) neighbors[i].push_back(std::make_pair(mat(i, j), j)); } value_t operator()(const index_t i, const index_t j) const; @@ -432,6 +432,7 @@ public: } diameter_entry_t next() { + ++ii[0]; while (k > 0 && get_next_vertex(max_vertex_below, idx_below, k, binomial_coeff) > get_index(x)) { idx_below -= binomial_coeff(max_vertex_below, k); -- cgit v1.2.3 From ab9fadd86b09a34e159fa12bdf0ab285ca252c3f Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Tue, 20 Sep 2016 11:08:59 +0200 Subject: fixes to sparse cobounrady computation --- ripser.cpp | 44 +++++++++++++++++++++++++--------------- ripser.xcodeproj/project.pbxproj | 11 +++++----- 2 files changed, 34 insertions(+), 21 deletions(-) diff --git a/ripser.cpp b/ripser.cpp index e16679c..5bbfe5c 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -168,7 +168,7 @@ typedef index_t entry_t; const index_t get_index(entry_t i) { return i; } index_t get_coefficient(entry_t i) { return 1; } entry_t make_entry(index_t _index, coefficient_t _value) { return entry_t(_index); } -void set_coefficient(index_t& e, const coefficient_t c) { e = c; } +void set_coefficient(index_t& e, const coefficient_t c) { } #endif @@ -336,8 +336,6 @@ public: if (i != j && mat(i, j) <= threshold) neighbors[i].push_back(std::make_pair(mat(i, j), j)); } - value_t operator()(const index_t i, const index_t j) const; - size_t size() const { return neighbors.size(); } }; @@ -383,7 +381,8 @@ public: decltype(*ii[0]) next() { return *ii[0]++; } }; -class simplex_coboundary_enumerator_sparse { +template<> +class simplex_coboundary_enumerator { private: index_t idx_below, idx_above, v, k, max_vertex_below; const binomial_coeff_table& binomial_coeff; @@ -399,7 +398,7 @@ private: const coefficient_t modulus; public: - simplex_coboundary_enumerator_sparse(const diameter_entry_t _simplex, index_t _dim, index_t _n, + simplex_coboundary_enumerator(const diameter_entry_t _simplex, index_t _dim, index_t _n, const coefficient_t _modulus, const sparse_distance_matrix& _sparse_dist, const binomial_coeff_table& _binomial_coeff) : simplex(_simplex), idx_below(get_index(_simplex)), idx_above(0), v(_n - 1), k(_dim + 1), @@ -661,11 +660,19 @@ void assemble_columns_to_reduce_sparse(std::vector& columns_to // find cofaces, additional vertices // if additional vertex is larger than all current ones: append to columns_to_reduce +#ifdef INDICATE_PROGRESS + std::cout << "\033[K" + << "assembling columns" << std::flush << "\r"; +#endif + std::vector previous_columns_to_reduce; previous_columns_to_reduce.swap(columns_to_reduce); + + columns_to_reduce.clear(); + for (diameter_index_t simplex : previous_columns_to_reduce) { // coface_entries.clear(); - simplex_coboundary_enumerator_sparse cofaces(simplex, dim, n, modulus, sparse_dist, binomial_coeff); + simplex_coboundary_enumerator cofaces(simplex, dim, n, modulus, sparse_dist, binomial_coeff); while (cofaces.has_next()) { auto coface = cofaces.next(); @@ -674,12 +681,6 @@ void assemble_columns_to_reduce_sparse(std::vector& columns_to } } - columns_to_reduce.clear(); - -#ifdef INDICATE_PROGRESS - std::cout << "\033[K" - << "assembling " << num_simplices << " columns" << std::flush << "\r"; -#endif // for (index_t index = 0; index < num_simplices; ++index) { // if (pivot_column_index.find(index) == pivot_column_index.end()) { @@ -690,7 +691,7 @@ void assemble_columns_to_reduce_sparse(std::vector& columns_to #ifdef INDICATE_PROGRESS std::cout << "\033[K" - << "sorting " << num_simplices << " columns" << std::flush << "\r"; + << "sorting " << columns_to_reduce.size() << " columns" << std::flush << "\r"; #endif std::sort(columns_to_reduce.begin(), columns_to_reduce.end(), @@ -700,10 +701,12 @@ void assemble_columns_to_reduce_sparse(std::vector& columns_to #endif } -template +template void compute_pairs(std::vector& columns_to_reduce, hash_map& pivot_column_index, index_t dim, index_t n, value_t threshold, coefficient_t modulus, const std::vector& multiplicative_inverse, const DistanceMatrix& dist, +// const FullDistanceMatrix& dist_full, const ComparatorCofaces& comp, const Comparator& comp_prev, const binomial_coeff_table& binomial_coeff) { @@ -783,15 +786,22 @@ void compute_pairs(std::vector& columns_to_reduce, hash_map cofaces(simplex, dim, n, modulus, dist, binomial_coeff); +// simplex_coboundary_enumerator cofaces_full(simplex, dim, n, modulus, dist_full, binomial_coeff); while (cofaces.has_next()) { +// assert(cofaces_full.has_next()); diameter_entry_t coface = cofaces.next(); - assert(comp.diameter(get_index(coface)) == get_diameter(coface)); +// , coface_full = cofaces_full.next(); +// value_t diameter = comp.diameter(get_index(coface)); +// assert(comp.diameter(get_index(coface)) == get_diameter(coface)); if (get_diameter(coface) <= threshold) { coface_entries.push_back(coface); @@ -1083,6 +1093,8 @@ int main(int argc, char** argv) { auto value_range = std::minmax_element(dist.distances.begin(), dist.distances.end()); std::cout << "value range: [" << *value_range.first << "," << *value_range.second << "]" << std::endl; + sparse_distance_matrix sparse_dist(dist, threshold); + dim_max = std::min(dim_max, n - 2); binomial_coeff_table binomial_coeff(n, dim_max + 2); @@ -1133,7 +1145,7 @@ int main(int argc, char** argv) { hash_map pivot_column_index; pivot_column_index.reserve(columns_to_reduce.size()); - compute_pairs(columns_to_reduce, pivot_column_index, dim, n, threshold, modulus, multiplicative_inverse, dist, + compute_pairs(columns_to_reduce, pivot_column_index, dim, n, threshold, modulus, multiplicative_inverse, sparse_dist, //dist, comp, comp_prev, binomial_coeff); if (dim < dim_max) { diff --git a/ripser.xcodeproj/project.pbxproj b/ripser.xcodeproj/project.pbxproj index 2aa6179..24c7d8b 100644 --- a/ripser.xcodeproj/project.pbxproj +++ b/ripser.xcodeproj/project.pbxproj @@ -129,7 +129,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; @@ -148,7 +148,7 @@ DEBUG_INFORMATION_FORMAT = dwarf; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_C_LANGUAGE_STANDARD = c11; GCC_DYNAMIC_NO_PIC = NO; GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; @@ -174,7 +174,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; @@ -193,7 +193,7 @@ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_C_LANGUAGE_STANDARD = c11; GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; @@ -216,7 +216,8 @@ _FILE_FORMAT_DISTANCE_MATRIX, _FILE_FORMAT_LOWER_DISTANCE_MATRIX, _FILE_FORMAT_POINT_CLOUD, - USE_COEFFICIENTS, + _USE_COEFFICIENTS, + INDICATE_PROGRESS, ); PRODUCT_NAME = "$(TARGET_NAME)"; }; -- cgit v1.2.3 From c6d9d81dc7f445a0bcbcc7e943b514edad448389 Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Tue, 20 Sep 2016 13:36:51 +0200 Subject: finished first version of sparse matrix support --- ripser.cpp | 96 +++++++++++++++++++++++--------------------------------------- 1 file changed, 35 insertions(+), 61 deletions(-) diff --git a/ripser.cpp b/ripser.cpp index 5bbfe5c..9f4e5e5 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -347,39 +347,6 @@ template struct second_argument_equal_to { bool operator()(const T& lhs, const T& rhs) const { return lhs.second == rhs.second; } }; -template -class set_intersection_enumerator { -public: - InputIteratorCollection &ii, ⅇ - Compare comp; - Equal equal; - Representative rep; - - set_intersection_enumerator(InputIteratorCollection& _first, InputIteratorCollection& _last) - : ii(_first), ee(_last) {} - - bool has_next() { - for (auto &it0 = ii[0], &end0 = ee[0]; it0 != end0; ++it0) { - auto x = *it0; - for (size_t idx = 1; idx < ii.size(); ++idx) { - auto &it = ii[idx], end = ee[idx]; - while (comp(*it, x)) - if (++it == end) return false; - auto y = *it; - if (!equal(y, x)) - goto continue_outer; - else - x = rep(x, y); - } - return true; - continue_outer:; - } - return false; - } - - // only valid after has_next() has been called - decltype(*ii[0]) next() { return *ii[0]++; } -}; template<> class simplex_coboundary_enumerator { @@ -411,7 +378,7 @@ public: } } - bool has_next() { + bool has_next(bool all_cofaces = true) { for (auto &it0 = ii[0], &end0 = ee[0]; it0 != end0; ++it0) { x = *it0; for (size_t idx = 1; idx < ii.size(); ++idx) { @@ -424,7 +391,7 @@ public: else x = std::min(x, y, greater_diameter_or_smaller_index()); } - return true; + return all_cofaces || !(k > 0 && get_next_vertex(max_vertex_below, idx_below, k, binomial_coeff) > get_index(x)); continue_outer:; } return false; @@ -634,6 +601,11 @@ void assemble_columns_to_reduce(std::vector& columns_to_reduce if (pivot_column_index.find(index) == pivot_column_index.end()) { value_t diameter = comp.diameter(index); if (diameter <= threshold) columns_to_reduce.push_back(std::make_pair(diameter, index)); +#ifdef INDICATE_PROGRESS + if ((index + 1) % 1000 == 0) + std::cout << "\033[K" + << "assembled " << columns_to_reduce.size() << " out of " << (index + 1) << "/" << num_simplices << " columns" << std::flush << "\r"; +#endif } } @@ -649,11 +621,15 @@ void assemble_columns_to_reduce(std::vector& columns_to_reduce #endif } + + template -void assemble_columns_to_reduce_sparse(std::vector& columns_to_reduce, - hash_map& pivot_column_index, const Comparator& comp, +void assemble_columns_to_reduce(std::vector& simplices, + std::vector& columns_to_reduce, + hash_map& pivot_column_index, + const sparse_distance_matrix& sparse_dist, + const Comparator& comp, index_t dim, index_t n, value_t threshold, const coefficient_t modulus, - const sparse_distance_matrix& sparse_dist, const binomial_coeff_table& binomial_coeff) { // iterate over all (previous) columns_to_reduce @@ -665,30 +641,26 @@ void assemble_columns_to_reduce_sparse(std::vector& columns_to << "assembling columns" << std::flush << "\r"; #endif - std::vector previous_columns_to_reduce; - previous_columns_to_reduce.swap(columns_to_reduce); - columns_to_reduce.clear(); + + std::vector next_simplices; - for (diameter_index_t simplex : previous_columns_to_reduce) { + for (diameter_index_t simplex : simplices) { // coface_entries.clear(); - simplex_coboundary_enumerator cofaces(simplex, dim, n, modulus, sparse_dist, binomial_coeff); + simplex_coboundary_enumerator cofaces(simplex, dim, n, modulus, sparse_dist, binomial_coeff); - while (cofaces.has_next()) { + while (cofaces.has_next(false)) { auto coface = cofaces.next(); + + next_simplices.push_back(std::make_pair(get_diameter(coface), get_index(coface))); - columns_to_reduce.push_back(std::make_pair(get_diameter(coface), get_index(coface))); + if (pivot_column_index.find(get_index(coface)) == pivot_column_index.end()) + columns_to_reduce.push_back(std::make_pair(get_diameter(coface), get_index(coface))); } } - - -// for (index_t index = 0; index < num_simplices; ++index) { -// if (pivot_column_index.find(index) == pivot_column_index.end()) { -// value_t diameter = comp.diameter(index); -// if (diameter <= threshold) columns_to_reduce.push_back(std::make_pair(diameter, index)); -// } -// } - + + simplices.swap(next_simplices); + #ifdef INDICATE_PROGRESS std::cout << "\033[K" << "sorting " << columns_to_reduce.size() << " columns" << std::flush << "\r"; @@ -1102,14 +1074,16 @@ int main(int argc, char** argv) { std::vector columns_to_reduce; + std::vector simplices , &edges = simplices; + rips_filtration_comparator comp(dist, 1, binomial_coeff); + for (index_t index = binomial_coeff(n, 2); index-- > 0;) { + value_t diameter = comp.diameter(index); + if (diameter <= threshold) edges.push_back(std::make_pair(diameter, index)); + } + { union_find dset(n); - std::vector edges; - rips_filtration_comparator comp(dist, 1, binomial_coeff); - for (index_t index = binomial_coeff(n, 2); index-- > 0;) { - value_t diameter = comp.diameter(index); - if (diameter <= threshold) edges.push_back(std::make_pair(diameter, index)); - } + std::sort(edges.rbegin(), edges.rend(), greater_diameter_or_smaller_index()); #ifdef PRINT_PERSISTENCE_PAIRS @@ -1149,7 +1123,7 @@ int main(int argc, char** argv) { comp, comp_prev, binomial_coeff); if (dim < dim_max) { - assemble_columns_to_reduce(columns_to_reduce, pivot_column_index, comp, dim, n, threshold, binomial_coeff); + assemble_columns_to_reduce(simplices, columns_to_reduce, pivot_column_index, sparse_dist, comp, dim, n, threshold, modulus, binomial_coeff); } } } -- cgit v1.2.3 From f31f1d94bc2367c27e306562c2f0492d2f0e87ab Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Thu, 22 Sep 2016 13:53:04 +0200 Subject: cleaned up comments --- ripser.cpp | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/ripser.cpp b/ripser.cpp index 9f4e5e5..713c70b 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -632,10 +632,6 @@ void assemble_columns_to_reduce(std::vector& simplices, index_t dim, index_t n, value_t threshold, const coefficient_t modulus, const binomial_coeff_table& binomial_coeff) { - // iterate over all (previous) columns_to_reduce - // find cofaces, additional vertices - // if additional vertex is larger than all current ones: append to columns_to_reduce - #ifdef INDICATE_PROGRESS std::cout << "\033[K" << "assembling columns" << std::flush << "\r"; @@ -646,7 +642,6 @@ void assemble_columns_to_reduce(std::vector& simplices, std::vector next_simplices; for (diameter_index_t simplex : simplices) { - // coface_entries.clear(); simplex_coboundary_enumerator cofaces(simplex, dim, n, modulus, sparse_dist, binomial_coeff); while (cofaces.has_next(false)) { @@ -673,12 +668,11 @@ void assemble_columns_to_reduce(std::vector& simplices, #endif } -template void compute_pairs(std::vector& columns_to_reduce, hash_map& pivot_column_index, index_t dim, index_t n, value_t threshold, coefficient_t modulus, const std::vector& multiplicative_inverse, const DistanceMatrix& dist, -// const FullDistanceMatrix& dist_full, const ComparatorCofaces& comp, const Comparator& comp_prev, const binomial_coeff_table& binomial_coeff) { @@ -758,22 +752,14 @@ void compute_pairs(std::vector& columns_to_reduce, hash_map cofaces(simplex, dim, n, modulus, dist, binomial_coeff); -// simplex_coboundary_enumerator cofaces_full(simplex, dim, n, modulus, dist_full, binomial_coeff); while (cofaces.has_next()) { -// assert(cofaces_full.has_next()); diameter_entry_t coface = cofaces.next(); -// , coface_full = cofaces_full.next(); -// value_t diameter = comp.diameter(get_index(coface)); -// assert(comp.diameter(get_index(coface)) == get_diameter(coface)); if (get_diameter(coface) <= threshold) { coface_entries.push_back(coface); @@ -1119,7 +1105,7 @@ int main(int argc, char** argv) { hash_map pivot_column_index; pivot_column_index.reserve(columns_to_reduce.size()); - compute_pairs(columns_to_reduce, pivot_column_index, dim, n, threshold, modulus, multiplicative_inverse, sparse_dist, //dist, + compute_pairs(columns_to_reduce, pivot_column_index, dim, n, threshold, modulus, multiplicative_inverse, sparse_dist, comp, comp_prev, binomial_coeff); if (dim < dim_max) { -- cgit v1.2.3 From 5adf0472e278034d155395cb8a95c017b30f0acb Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Thu, 29 Sep 2016 18:16:54 +0200 Subject: rearranged reduction columns code --- ripser.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/ripser.cpp b/ripser.cpp index ec73f6d..4067018 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -685,7 +685,7 @@ void compute_pairs(std::vector& columns_to_reduce, hash_map reduction_matrix; + compressed_sparse_matrix reduction_coefficients; #else #ifdef USE_COEFFICIENTS std::vector reduction_coefficients; @@ -723,9 +723,9 @@ void compute_pairs(std::vector& columns_to_reduce, hash_map& columns_to_reduce, hash_map& columns_to_reduce, hash_map& columns_to_reduce, hash_map 0); #endif - reduction_matrix.push_back(e); + reduction_coefficients.push_back(e); } #else #ifdef USE_COEFFICIENTS -- cgit v1.2.3 From 43d28e6cea16062d0cefaf16979d07837cc788d6 Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Thu, 29 Sep 2016 23:02:29 +0200 Subject: removed comparator --- ripser.cpp | 88 +++----------------------------------------------------------- 1 file changed, 3 insertions(+), 85 deletions(-) diff --git a/ripser.cpp b/ripser.cpp index 713c70b..f5384e9 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -213,42 +213,6 @@ template struct greater_diameter_or_smaller_index { } }; -template class rips_filtration_comparator { -public: - const DistanceMatrix& dist; - const index_t dim; - -private: - mutable std::vector vertices; - const binomial_coeff_table& binomial_coeff; - -public: - rips_filtration_comparator(const DistanceMatrix& _dist, const index_t _dim, - const binomial_coeff_table& _binomial_coeff) - : dist(_dist), dim(_dim), vertices(_dim + 1), binomial_coeff(_binomial_coeff){}; - - value_t diameter(const index_t index) const { - value_t diam = 0; - get_simplex_vertices(index, dim, dist.size(), binomial_coeff, vertices.begin()); - - for (index_t i = 0; i <= dim; ++i) - for (index_t j = 0; j < i; ++j) { diam = std::max(diam, dist(vertices[i], vertices[j])); } - return diam; - } - - bool operator()(const index_t a, const index_t b) const { - assert(a < binomial_coeff(dist.size(), dim + 1)); - assert(b < binomial_coeff(dist.size(), dim + 1)); - - return greater_diameter_or_smaller_index()(diameter_index_t(diameter(a), a), - diameter_index_t(diameter(b), b)); - } - - template bool operator()(const Entry& a, const Entry& b) const { - return operator()(get_index(a), get_index(b)); - } -}; - template class simplex_coboundary_enumerator { private: index_t idx_below, idx_above, v, k; @@ -584,51 +548,10 @@ template void push_entry(Heap& column, index_t i, coefficient_t column.push(std::make_pair(diameter, e)); } -template -void assemble_columns_to_reduce(std::vector& columns_to_reduce, - hash_map& pivot_column_index, const Comparator& comp, index_t dim, - index_t n, value_t threshold, const binomial_coeff_table& binomial_coeff) { - index_t num_simplices = binomial_coeff(n, dim + 2); - - columns_to_reduce.clear(); - -#ifdef INDICATE_PROGRESS - std::cout << "\033[K" - << "assembling " << num_simplices << " columns" << std::flush << "\r"; -#endif - - for (index_t index = 0; index < num_simplices; ++index) { - if (pivot_column_index.find(index) == pivot_column_index.end()) { - value_t diameter = comp.diameter(index); - if (diameter <= threshold) columns_to_reduce.push_back(std::make_pair(diameter, index)); -#ifdef INDICATE_PROGRESS - if ((index + 1) % 1000 == 0) - std::cout << "\033[K" - << "assembled " << columns_to_reduce.size() << " out of " << (index + 1) << "/" << num_simplices << " columns" << std::flush << "\r"; -#endif - } - } - -#ifdef INDICATE_PROGRESS - std::cout << "\033[K" - << "sorting " << num_simplices << " columns" << std::flush << "\r"; -#endif - - std::sort(columns_to_reduce.begin(), columns_to_reduce.end(), - greater_diameter_or_smaller_index()); -#ifdef INDICATE_PROGRESS - std::cout << "\033[K"; -#endif -} - - - -template void assemble_columns_to_reduce(std::vector& simplices, std::vector& columns_to_reduce, hash_map& pivot_column_index, const sparse_distance_matrix& sparse_dist, - const Comparator& comp, index_t dim, index_t n, value_t threshold, const coefficient_t modulus, const binomial_coeff_table& binomial_coeff) { @@ -668,12 +591,10 @@ void assemble_columns_to_reduce(std::vector& simplices, #endif } -template +template void compute_pairs(std::vector& columns_to_reduce, hash_map& pivot_column_index, index_t dim, index_t n, value_t threshold, coefficient_t modulus, const std::vector& multiplicative_inverse, const DistanceMatrix& dist, - const ComparatorCofaces& comp, const Comparator& comp_prev, const binomial_coeff_table& binomial_coeff) { #ifdef PRINT_PERSISTENCE_PAIRS @@ -1099,17 +1020,14 @@ int main(int argc, char** argv) { } for (index_t dim = 1; dim <= dim_max; ++dim) { - rips_filtration_comparator comp(dist, dim + 1, binomial_coeff); - rips_filtration_comparator comp_prev(dist, dim, binomial_coeff); - hash_map pivot_column_index; pivot_column_index.reserve(columns_to_reduce.size()); compute_pairs(columns_to_reduce, pivot_column_index, dim, n, threshold, modulus, multiplicative_inverse, sparse_dist, - comp, comp_prev, binomial_coeff); + binomial_coeff); if (dim < dim_max) { - assemble_columns_to_reduce(simplices, columns_to_reduce, pivot_column_index, sparse_dist, comp, dim, n, threshold, modulus, binomial_coeff); + assemble_columns_to_reduce(simplices, columns_to_reduce, pivot_column_index, sparse_dist, dim, n, threshold, modulus, binomial_coeff); } } } -- cgit v1.2.3 From 77deb431e86bab1b4d3716909fc061ac52f692f1 Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Thu, 29 Sep 2016 23:03:12 +0200 Subject: sparse graph support for dim 0 --- ripser.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/ripser.cpp b/ripser.cpp index f5384e9..561f7bf 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -982,17 +982,22 @@ int main(int argc, char** argv) { std::vector columns_to_reduce; std::vector simplices , &edges = simplices; - rips_filtration_comparator comp(dist, 1, binomial_coeff); - for (index_t index = binomial_coeff(n, 2); index-- > 0;) { - value_t diameter = comp.diameter(index); - if (diameter <= threshold) edges.push_back(std::make_pair(diameter, index)); + + for (index_t i = 0; i < n; ++i) { + simplex_coboundary_enumerator cofaces(i, 0, n, modulus, sparse_dist, binomial_coeff); + + while (cofaces.has_next(false)) { + auto coface = cofaces.next(); + value_t diameter = get_diameter(coface); + if (diameter <= threshold) edges.push_back(std::make_pair(diameter, get_index(coface))); + } + + std::sort(edges.rbegin(), edges.rend(), greater_diameter_or_smaller_index()); } { union_find dset(n); - std::sort(edges.rbegin(), edges.rend(), greater_diameter_or_smaller_index()); - #ifdef PRINT_PERSISTENCE_PAIRS std::cout << "persistence intervals in dim 0:" << std::endl; #endif -- cgit v1.2.3 From 7cd0e22d554207e420d4dcedbe7e753bac64c3c3 Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Fri, 30 Sep 2016 18:43:48 +0200 Subject: pretty-print --- ripser.cpp | 90 +++++++++++++++++++++++++++++--------------------------------- 1 file changed, 42 insertions(+), 48 deletions(-) diff --git a/ripser.cpp b/ripser.cpp index 6faa9c4..3effc85 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -18,7 +18,6 @@ with this program. If not, see . */ - //#define ASSEMBLE_REDUCTION_MATRIX //#define USE_COEFFICIENTS @@ -167,7 +166,7 @@ typedef index_t entry_t; const index_t get_index(entry_t i) { return i; } index_t get_coefficient(entry_t i) { return 1; } entry_t make_entry(index_t _index, coefficient_t _value) { return entry_t(_index); } -void set_coefficient(index_t& e, const coefficient_t c) { } +void set_coefficient(index_t& e, const coefficient_t c) {} #endif @@ -177,7 +176,7 @@ template struct smaller_index { bool operator()(const Entry& a, const Entry& b) { return get_index(a) < get_index(b); } }; -class diameter_index_t: public std::pair { +class diameter_index_t : public std::pair { public: diameter_index_t() : std::pair() {} diameter_index_t(std::pair p) : std::pair(p) {} @@ -284,7 +283,8 @@ public: value_t coface_diameter = get_diameter(simplex); for (index_t w : vertices) coface_diameter = std::max(coface_diameter, dist(v, w)); coefficient_t coface_coefficient = (k & 1 ? -1 + modulus : 1) * get_coefficient(simplex) % modulus; - return diameter_entry_t(coface_diameter, idx_above + binomial_coeff(v--, k + 1) + idx_below, coface_coefficient); + return diameter_entry_t(coface_diameter, idx_above + binomial_coeff(v--, k + 1) + idx_below, + coface_coefficient); } }; @@ -340,9 +340,7 @@ template struct second_argument_equal_to { bool operator()(const T& lhs, const T& rhs) const { return lhs.second == rhs.second; } }; - -template<> -class simplex_coboundary_enumerator { +template <> class simplex_coboundary_enumerator { private: index_t idx_below, idx_above, v, k, max_vertex_below; const binomial_coeff_table& binomial_coeff; @@ -359,8 +357,8 @@ private: public: simplex_coboundary_enumerator(const diameter_entry_t _simplex, index_t _dim, index_t _n, - const coefficient_t _modulus, const sparse_distance_matrix& _sparse_dist, - const binomial_coeff_table& _binomial_coeff) + const coefficient_t _modulus, const sparse_distance_matrix& _sparse_dist, + const binomial_coeff_table& _binomial_coeff) : simplex(_simplex), idx_below(get_index(_simplex)), idx_above(0), v(_n - 1), k(_dim + 1), max_vertex_below(_n - 1), modulus(_modulus), sparse_dist(_sparse_dist), binomial_coeff(_binomial_coeff) { get_simplex_vertices(idx_below, _dim, _n, _binomial_coeff, std::back_inserter(vertices)); @@ -384,7 +382,8 @@ public: else x = std::min(x, y, greater_diameter_or_smaller_index()); } - return all_cofaces || !(k > 0 && get_next_vertex(max_vertex_below, idx_below, k, binomial_coeff) > get_index(x)); + return all_cofaces || + !(k > 0 && get_next_vertex(max_vertex_below, idx_below, k, binomial_coeff) > get_index(x)); continue_outer:; } return false; @@ -403,9 +402,8 @@ public: coefficient_t coface_coefficient = (k & 1 ? -1 + modulus : 1) * get_coefficient(simplex) % modulus; - return diameter_entry_t(coface_diameter, - idx_above + binomial_coeff(get_index(x), k + 1) + idx_below, - coface_coefficient); + return diameter_entry_t(coface_diameter, idx_above + binomial_coeff(get_index(x), k + 1) + idx_below, + coface_coefficient); } }; @@ -595,9 +593,10 @@ void assemble_columns_to_reduce(std::vector& columns_to_reduce value_t diameter = comp.diameter(index); if (diameter <= threshold) columns_to_reduce.push_back(std::make_pair(diameter, index)); #ifdef INDICATE_PROGRESS - if ((index + 1) % 1000 == 0) - std::cout << "\033[K" - << "assembled " << columns_to_reduce.size() << " out of " << (index + 1) << "/" << num_simplices << " columns" << std::flush << "\r"; + if ((index + 1) % 1000 == 0) + std::cout << "\033[K" + << "assembled " << columns_to_reduce.size() << " out of " << (index + 1) << "/" + << num_simplices << " columns" << std::flush << "\r"; #endif } } @@ -614,16 +613,13 @@ void assemble_columns_to_reduce(std::vector& columns_to_reduce #endif } - - template void assemble_columns_to_reduce(std::vector& simplices, - std::vector& columns_to_reduce, - hash_map& pivot_column_index, - const sparse_distance_matrix& sparse_dist, - const Comparator& comp, - index_t dim, index_t n, value_t threshold, const coefficient_t modulus, - const binomial_coeff_table& binomial_coeff) { + std::vector& columns_to_reduce, + hash_map& pivot_column_index, + const sparse_distance_matrix& sparse_dist, const Comparator& comp, index_t dim, + index_t n, value_t threshold, const coefficient_t modulus, + const binomial_coeff_table& binomial_coeff) { #ifdef INDICATE_PROGRESS std::cout << "\033[K" @@ -631,24 +627,25 @@ void assemble_columns_to_reduce(std::vector& simplices, #endif columns_to_reduce.clear(); - + std::vector next_simplices; for (diameter_index_t simplex : simplices) { - simplex_coboundary_enumerator cofaces(simplex, dim, n, modulus, sparse_dist, binomial_coeff); + simplex_coboundary_enumerator cofaces(simplex, dim, n, modulus, sparse_dist, + binomial_coeff); while (cofaces.has_next(false)) { auto coface = cofaces.next(); - + next_simplices.push_back(std::make_pair(get_diameter(coface), get_index(coface))); - + if (pivot_column_index.find(get_index(coface)) == pivot_column_index.end()) columns_to_reduce.push_back(std::make_pair(get_diameter(coface), get_index(coface))); } } - + simplices.swap(next_simplices); - + #ifdef INDICATE_PROGRESS std::cout << "\033[K" << "sorting " << columns_to_reduce.size() << " columns" << std::flush << "\r"; @@ -661,12 +658,10 @@ void assemble_columns_to_reduce(std::vector& simplices, #endif } -template +template void compute_pairs(std::vector& columns_to_reduce, hash_map& pivot_column_index, index_t dim, index_t n, value_t threshold, coefficient_t modulus, - const std::vector& multiplicative_inverse, - const DistanceMatrix& dist, + const std::vector& multiplicative_inverse, const DistanceMatrix& dist, const ComparatorCofaces& comp, const Comparator& comp_prev, const binomial_coeff_table& binomial_coeff) { @@ -736,8 +731,7 @@ void compute_pairs(std::vector& columns_to_reduce, hash_map columns_to_reduce; - std::vector simplices , &edges = simplices; - rips_filtration_comparator comp(dist, 1, binomial_coeff); - for (index_t index = binomial_coeff(n, 2); index-- > 0;) { - value_t diameter = comp.diameter(index); - if (diameter <= threshold) edges.push_back(std::make_pair(diameter, index)); - } - + std::vector simplices, &edges = simplices; + rips_filtration_comparator comp(dist, 1, binomial_coeff); + for (index_t index = binomial_coeff(n, 2); index-- > 0;) { + value_t diameter = comp.diameter(index); + if (diameter <= threshold) edges.push_back(std::make_pair(diameter, index)); + } + { union_find dset(n); @@ -1071,8 +1065,7 @@ int main(int argc, char** argv) { if (u != v) { #ifdef PRINT_PERSISTENCE_PAIRS - if (get_diameter(e) > 0) - std::cout << " [0," << get_diameter(e) << ")" << std::endl; + if (get_diameter(e) > 0) std::cout << " [0," << get_diameter(e) << ")" << std::endl; #endif dset.link(u, v); } else @@ -1093,11 +1086,12 @@ int main(int argc, char** argv) { hash_map pivot_column_index; pivot_column_index.reserve(columns_to_reduce.size()); - compute_pairs(columns_to_reduce, pivot_column_index, dim, n, threshold, modulus, multiplicative_inverse, sparse_dist, - comp, comp_prev, binomial_coeff); + compute_pairs(columns_to_reduce, pivot_column_index, dim, n, threshold, modulus, multiplicative_inverse, + sparse_dist, comp, comp_prev, binomial_coeff); if (dim < dim_max) { - assemble_columns_to_reduce(simplices, columns_to_reduce, pivot_column_index, sparse_dist, comp, dim, n, threshold, modulus, binomial_coeff); + assemble_columns_to_reduce(simplices, columns_to_reduce, pivot_column_index, sparse_dist, comp, dim, n, + threshold, modulus, binomial_coeff); } } } -- cgit v1.2.3 From 7f2d16e1054529bed4d04c00a6fd7a7c33fdd458 Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Fri, 30 Sep 2016 22:03:08 +0200 Subject: fixed build problems --- ripser.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ripser.cpp b/ripser.cpp index b183b3d..36a477a 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -180,6 +180,7 @@ class diameter_index_t : public std::pair { public: diameter_index_t() : std::pair() {} diameter_index_t(std::pair p) : std::pair(p) {} + diameter_index_t(index_t i) : std::pair(0, i) {} }; value_t get_diameter(diameter_index_t i) { return i.first; } index_t get_index(diameter_index_t i) { return i.second; } @@ -187,8 +188,6 @@ index_t get_index(diameter_index_t i) { return i.second; } class diameter_entry_t : public std::pair { public: diameter_entry_t(std::pair p) : std::pair(p) {} - diameter_entry_t(entry_t e) : std::pair(0, e) {} - diameter_entry_t() : diameter_entry_t(0) {} diameter_entry_t(value_t _diameter, index_t _index, coefficient_t _coefficient) : std::pair(_diameter, make_entry(_index, _coefficient)) {} diameter_entry_t(diameter_index_t _diameter_index, coefficient_t _coefficient) @@ -968,7 +967,7 @@ int main(int argc, char** argv) { std::vector simplices, &edges = simplices; for (index_t i = 0; i < n; ++i) { - simplex_coboundary_enumerator cofaces(i, 0, n, modulus, sparse_dist, binomial_coeff); + simplex_coboundary_enumerator cofaces(diameter_index_t(i), 0, n, modulus, sparse_dist, binomial_coeff); while (cofaces.has_next(false)) { auto coface = cofaces.next(); -- cgit v1.2.3 From 0e3bd6152519cce4a55c104aa00478aeaf23dfb9 Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Wed, 9 Nov 2016 23:58:52 +0100 Subject: initialize edges from lower distance matrix --- ripser.cpp | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/ripser.cpp b/ripser.cpp index 36a477a..3ebf2e3 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -965,19 +965,19 @@ int main(int argc, char** argv) { std::vector columns_to_reduce; std::vector simplices, &edges = simplices; - - for (index_t i = 0; i < n; ++i) { - simplex_coboundary_enumerator cofaces(diameter_index_t(i), 0, n, modulus, sparse_dist, binomial_coeff); - - while (cofaces.has_next(false)) { - auto coface = cofaces.next(); - value_t diameter = get_diameter(coface); - if (diameter <= threshold) edges.push_back(std::make_pair(diameter, get_index(coface))); - } - - std::sort(edges.rbegin(), edges.rend(), greater_diameter_or_smaller_index()); + + std::chrono::time_point start, end; + long elapsed_time; + + start = std::chrono::system_clock::now(); + + for (index_t e = 0; e < dist.distances.size(); ++e) { + value_t diameter = dist.distances[e]; + if (diameter <= threshold) edges.push_back(std::make_pair(diameter, e)); } - + + std::sort(edges.rbegin(), edges.rend(), greater_diameter_or_smaller_index()); + { union_find dset(n); @@ -1019,4 +1019,9 @@ int main(int argc, char** argv) { threshold, modulus, binomial_coeff); } } + + end = std::chrono::system_clock::now(); + elapsed_time = std::chrono::duration_cast(end - start).count(); + std::cout << "Computed Rips persistence in " << elapsed_time << " ms.\n"; + } -- cgit v1.2.3 From 9213750960682a4bd3d4291467818395f124355c Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Thu, 10 Nov 2016 00:25:10 +0100 Subject: more timing --- ripser.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/ripser.cpp b/ripser.cpp index 3ebf2e3..d984904 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -946,8 +946,14 @@ int main(int argc, char** argv) { exit(-1); } + std::chrono::time_point start; + + start = std::chrono::system_clock::now(); + compressed_lower_distance_matrix dist = read_file(filename ? file_stream : std::cin, format); + std::cout << "Reading file in " << std::chrono::duration_cast(std::chrono::system_clock::now() - start).count() / 1000. << " s.\n"; + index_t n = dist.size(); std::cout << "distance matrix with " << n << " points" << std::endl; @@ -955,7 +961,12 @@ int main(int argc, char** argv) { auto value_range = std::minmax_element(dist.distances.begin(), dist.distances.end()); std::cout << "value range: [" << *value_range.first << "," << *value_range.second << "]" << std::endl; + start = std::chrono::system_clock::now(); + sparse_distance_matrix sparse_dist(dist, threshold); + + std::cout << "Building sparse distance matrix in " << std::chrono::duration_cast(std::chrono::system_clock::now() - start).count() / 1000. << " s.\n"; + dim_max = std::min(dim_max, n - 2); @@ -966,8 +977,6 @@ int main(int argc, char** argv) { std::vector simplices, &edges = simplices; - std::chrono::time_point start, end; - long elapsed_time; start = std::chrono::system_clock::now(); @@ -1020,8 +1029,7 @@ int main(int argc, char** argv) { } } - end = std::chrono::system_clock::now(); - elapsed_time = std::chrono::duration_cast(end - start).count(); - std::cout << "Computed Rips persistence in " << elapsed_time << " ms.\n"; + std::cout << "Computing Rips persistence in " << std::chrono::duration_cast(std::chrono::system_clock::now() - start).count() / 1000. << " s.\n"; + } -- cgit v1.2.3 From c86c7fc1620363b4a78699c88644d5d8c6051379 Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Wed, 30 Nov 2016 17:46:00 -0500 Subject: cleanup --- ripser.cpp | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/ripser.cpp b/ripser.cpp index 270f8b9..a66e8e6 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -137,6 +137,8 @@ index_t get_index(diameter_index_t i) { return i.second; } class diameter_entry_t : public std::pair { public: diameter_entry_t(std::pair p) : std::pair(p) {} + diameter_entry_t(entry_t e) : std::pair(0, e) {} + diameter_entry_t() : diameter_entry_t(0) {} diameter_entry_t(value_t _diameter, index_t _index, coefficient_t _coefficient) : std::pair(_diameter, make_entry(_index, _coefficient)) {} diameter_entry_t(diameter_index_t _diameter_index, coefficient_t _coefficient) @@ -203,14 +205,6 @@ public: size_t size() const { return neighbors.size(); } }; -template struct second_argument_greater { - bool operator()(const T& lhs, const T& rhs) const { return lhs.second > rhs.second; } -}; - -template struct second_argument_equal_to { - bool operator()(const T& lhs, const T& rhs) const { return lhs.second == rhs.second; } -}; - template <> void compressed_distance_matrix::init_rows() { value_t* pointer = &distances[0]; for (index_t i = 1; i < size(); ++i) { @@ -494,16 +488,16 @@ public: return out; } -// value_t compute_diameter(const index_t index, index_t dim) const { -// value_t diam = -std::numeric_limits::infinity(); -// -// vertices.clear(); -// get_simplex_vertices(index, dim, sparse_dist.size(), std::back_inserter(vertices)); -// -// for (index_t i = 0; i <= dim; ++i) -// for (index_t j = 0; j < i; ++j) { diam = std::max(diam, sparse_dist(vertices[i], vertices[j])); } -// return diam; -// } + value_t compute_diameter(const index_t index, index_t dim) const { + value_t diam = -std::numeric_limits::infinity(); + + vertices.clear(); + get_simplex_vertices(index, dim, sparse_dist.size(), std::back_inserter(vertices)); + + for (index_t i = 0; i <= dim; ++i) + for (index_t j = 0; j < i; ++j) { diam = std::max(diam, dist(vertices[i], vertices[j])); } + return diam; + } void assemble_columns_to_reduce(std::vector& simplices, std::vector& columns_to_reduce, -- cgit v1.2.3 From 117088b16d9abe1ca18a909568bd71e377782ff4 Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Wed, 30 Nov 2016 18:22:01 -0500 Subject: speedup coboundary enumeration --- ripser.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/ripser.cpp b/ripser.cpp index a66e8e6..aa2d438 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -381,7 +381,10 @@ class ripser { coefficient_t modulus; compressed_lower_distance_matrix dist; sparse_distance_matrix sparse_dist; + mutable std::vector vertices; + mutable std::vector::const_reverse_iterator> ii; + mutable std::vector::const_reverse_iterator> ee; public: ripser(compressed_lower_distance_matrix&& _dist,sparse_distance_matrix&& _sparse_dist, index_t _dim_max, value_t _threshold, coefficient_t _modulus) @@ -400,9 +403,11 @@ public: const sparse_distance_matrix& sparse_dist; const binomial_coeff_table& binomial_coeff; - std::vector vertices; + std::vector& vertices; - std::vector::const_reverse_iterator> ii, ee; + std::vector::const_reverse_iterator>& ii; + std::vector::const_reverse_iterator>& ee; + diameter_index_t x; @@ -410,7 +415,12 @@ public: public: simplex_coboundary_enumerator(const diameter_entry_t _simplex, index_t _dim, const ripser& _parent) : parent(_parent), simplex(_simplex), idx_below(get_index(_simplex)), idx_above(0), v(parent.n - 1), k(_dim + 1), - max_vertex_below(parent.n - 1), modulus(parent.modulus), sparse_dist(parent.sparse_dist), binomial_coeff(parent.binomial_coeff) { + max_vertex_below(parent.n - 1), modulus(parent.modulus), sparse_dist(parent.sparse_dist), binomial_coeff(parent.binomial_coeff), vertices(parent.vertices), ii(parent.ii), ee(parent.ee) { + + ii.clear(); + ee.clear(); + vertices.clear(); + parent.get_simplex_vertices(idx_below, _dim, parent.n, std::back_inserter(vertices)); for (auto v : vertices) { -- cgit v1.2.3 From 63c3ae66f90bbf4ef295433b02d8dd10072bcf6d Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Wed, 30 Nov 2016 19:23:17 -0500 Subject: use only sparse distance matrix --- ripser.cpp | 156 +++++++++++++++++++++++++++---------------------------------- 1 file changed, 68 insertions(+), 88 deletions(-) diff --git a/ripser.cpp b/ripser.cpp index aa2d438..01e587b 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -52,6 +52,7 @@ typedef int16_t coefficient_t; class binomial_coeff_table { std::vector> B; + public: binomial_coeff_table(index_t n, index_t k) : B(n + 1) { for (index_t i = 0; i <= n; i++) { @@ -87,7 +88,6 @@ std::vector multiplicative_inverse_vector(const coefficient_t m) return inverse; } - #ifdef USE_COEFFICIENTS struct __attribute__((packed)) entry_t { index_t index : 8 * (sizeof(index_t) - sizeof(coefficient_t)); @@ -379,22 +379,20 @@ class ripser { const binomial_coeff_table binomial_coeff; std::vector multiplicative_inverse; coefficient_t modulus; - compressed_lower_distance_matrix dist; sparse_distance_matrix sparse_dist; - + mutable std::vector vertices; mutable std::vector::const_reverse_iterator> ii; mutable std::vector::const_reverse_iterator> ee; public: - ripser(compressed_lower_distance_matrix&& _dist,sparse_distance_matrix&& _sparse_dist, index_t _dim_max, value_t _threshold, coefficient_t _modulus) - : dist(_dist), sparse_dist(_sparse_dist), n(_sparse_dist.size()), dim_max(std::min(_dim_max, index_t(_sparse_dist.size() - 2))), threshold(_threshold), - modulus(_modulus), binomial_coeff(n, dim_max + 2), - multiplicative_inverse(multiplicative_inverse_vector(_modulus)) {} - + ripser(sparse_distance_matrix&& _sparse_dist, index_t _dim_max, value_t _threshold, coefficient_t _modulus) + : sparse_dist(_sparse_dist), n(_sparse_dist.size()), + dim_max(std::min(_dim_max, index_t(_sparse_dist.size() - 2))), threshold(_threshold), modulus(_modulus), + binomial_coeff(n, dim_max + 2), multiplicative_inverse(multiplicative_inverse_vector(_modulus)) {} + class simplex_coboundary_enumerator { private: - const ripser& parent; index_t idx_below, idx_above, v, k, max_vertex_below; @@ -404,31 +402,28 @@ public: const binomial_coeff_table& binomial_coeff; std::vector& vertices; - std::vector::const_reverse_iterator>& ii; std::vector::const_reverse_iterator>& ee; - - diameter_index_t x; - - + public: simplex_coboundary_enumerator(const diameter_entry_t _simplex, index_t _dim, const ripser& _parent) - : parent(_parent), simplex(_simplex), idx_below(get_index(_simplex)), idx_above(0), v(parent.n - 1), k(_dim + 1), - max_vertex_below(parent.n - 1), modulus(parent.modulus), sparse_dist(parent.sparse_dist), binomial_coeff(parent.binomial_coeff), vertices(parent.vertices), ii(parent.ii), ee(parent.ee) { - + : parent(_parent), simplex(_simplex), idx_below(get_index(_simplex)), idx_above(0), v(parent.n - 1), + k(_dim + 1), max_vertex_below(parent.n - 1), modulus(parent.modulus), sparse_dist(parent.sparse_dist), + binomial_coeff(parent.binomial_coeff), vertices(parent.vertices), ii(parent.ii), ee(parent.ee) { + ii.clear(); ee.clear(); vertices.clear(); - + parent.get_simplex_vertices(idx_below, _dim, parent.n, std::back_inserter(vertices)); - + for (auto v : vertices) { ii.push_back(sparse_dist.neighbors[v].rbegin()); ee.push_back(sparse_dist.neighbors[v].rend()); } } - + bool has_next(bool all_cofaces = true) { for (auto &it0 = ii[0], &end0 = ee[0]; it0 != end0; ++it0) { x = *it0; @@ -440,34 +435,32 @@ public: if (get_index(y) != get_index(x)) goto continue_outer; else - x = std::min(x, y, greater_diameter_or_smaller_index()); + x = std::max(x, y); } - return all_cofaces || - !(k > 0 && parent.get_next_vertex(max_vertex_below, idx_below, k) > get_index(x)); + return all_cofaces || !(k > 0 && parent.get_next_vertex(max_vertex_below, idx_below, k) > get_index(x)); continue_outer:; } return false; } - + diameter_entry_t next() { ++ii[0]; - + while (k > 0 && parent.get_next_vertex(max_vertex_below, idx_below, k) > get_index(x)) { idx_below -= binomial_coeff(max_vertex_below, k); idx_above += binomial_coeff(max_vertex_below, k + 1); --k; } - + value_t coface_diameter = std::max(get_diameter(simplex), get_diameter(x)); - + coefficient_t coface_coefficient = (k & 1 ? -1 + modulus : 1) * get_coefficient(simplex) % modulus; - + return diameter_entry_t(coface_diameter, idx_above + binomial_coeff(get_index(x), k + 1) + idx_below, - coface_coefficient); + coface_coefficient); } }; - index_t get_next_vertex(index_t& v, const index_t idx, const index_t k) const { if (binomial_coeff(v, k) > idx) { index_t count = v; @@ -485,10 +478,11 @@ public: assert(binomial_coeff(v, k) <= idx && binomial_coeff(v + 1, k) > idx); return v; } - + + index_t get_edge_index(const index_t i, const index_t j) const { return binomial_coeff(i, 2) + j; } + template - OutputIterator get_simplex_vertices(index_t idx, const index_t dim, index_t v, - OutputIterator out) const { + OutputIterator get_simplex_vertices(index_t idx, const index_t dim, index_t v, OutputIterator out) const { --v; for (index_t k = dim + 1; k > 0; --k) { get_next_vertex(v, idx, k); @@ -497,57 +491,46 @@ public: } return out; } - - value_t compute_diameter(const index_t index, index_t dim) const { - value_t diam = -std::numeric_limits::infinity(); - vertices.clear(); - get_simplex_vertices(index, dim, sparse_dist.size(), std::back_inserter(vertices)); - - for (index_t i = 0; i <= dim; ++i) - for (index_t j = 0; j < i; ++j) { diam = std::max(diam, dist(vertices[i], vertices[j])); } - return diam; - } - -void assemble_columns_to_reduce(std::vector& simplices, - std::vector& columns_to_reduce, - hash_map& pivot_column_index, index_t dim) { + void assemble_columns_to_reduce(std::vector& simplices, + std::vector& columns_to_reduce, + hash_map& pivot_column_index, index_t dim) { #ifdef INDICATE_PROGRESS - std::cout << "\033[K" - << "assembling columns" << std::flush << "\r"; + std::cout << "\033[K" + << "assembling columns" << std::flush << "\r"; #endif - columns_to_reduce.clear(); + columns_to_reduce.clear(); - std::vector next_simplices; + std::vector next_simplices; - for (diameter_index_t simplex : simplices) { - simplex_coboundary_enumerator cofaces(simplex, dim, *this); + for (diameter_index_t simplex : simplices) { + simplex_coboundary_enumerator cofaces(simplex, dim, *this); - while (cofaces.has_next(false)) { - auto coface = cofaces.next(); + while (cofaces.has_next(false)) { + auto coface = cofaces.next(); - next_simplices.push_back(std::make_pair(get_diameter(coface), get_index(coface))); + next_simplices.push_back(std::make_pair(get_diameter(coface), get_index(coface))); - if (pivot_column_index.find(get_index(coface)) == pivot_column_index.end()) - columns_to_reduce.push_back(std::make_pair(get_diameter(coface), get_index(coface))); + if (pivot_column_index.find(get_index(coface)) == pivot_column_index.end()) + columns_to_reduce.push_back(std::make_pair(get_diameter(coface), get_index(coface))); + } } - } - simplices.swap(next_simplices); + simplices.swap(next_simplices); #ifdef INDICATE_PROGRESS - std::cout << "\033[K" - << "sorting " << columns_to_reduce.size() << " columns" << std::flush << "\r"; + std::cout << "\033[K" + << "sorting " << columns_to_reduce.size() << " columns" << std::flush << "\r"; #endif - std::sort(columns_to_reduce.begin(), columns_to_reduce.end(), - greater_diameter_or_smaller_index()); + std::sort(columns_to_reduce.begin(), columns_to_reduce.end(), + greater_diameter_or_smaller_index()); #ifdef INDICATE_PROGRESS - std::cout << "\033[K"; + std::cout << "\033[K"; #endif -} + } void compute_pairs(std::vector& columns_to_reduce, hash_map& pivot_column_index, index_t dim) { @@ -723,29 +706,30 @@ void assemble_columns_to_reduce(std::vector& simplices, void compute_barcodes() { std::vector columns_to_reduce; - + std::vector simplices, &edges = simplices; - - for (index_t e = 0; e < dist.distances.size(); ++e) { - value_t diameter = dist.distances[e]; - if (diameter <= threshold) edges.push_back(std::make_pair(diameter, e)); - } - + + for (index_t i = 0; i < n; ++i) + for (auto n : sparse_dist.neighbors[i]) { + index_t j = get_index(n); + if (i > j) edges.push_back(std::make_pair(get_diameter(n), get_edge_index(i, j))); + } + std::sort(edges.rbegin(), edges.rend(), greater_diameter_or_smaller_index()); - + { union_find dset(n); - + #ifdef PRINT_PERSISTENCE_PAIRS std::cout << "persistence intervals in dim 0:" << std::endl; #endif - + std::vector vertices_of_edge(2); for (auto e : edges) { vertices_of_edge.clear(); get_simplex_vertices(get_index(e), 1, n, std::back_inserter(vertices_of_edge)); index_t u = dset.find(vertices_of_edge[0]), v = dset.find(vertices_of_edge[1]); - + if (u != v) { #ifdef PRINT_PERSISTENCE_PAIRS if (get_diameter(e) > 0) std::cout << " [0," << get_diameter(e) << ")" << std::endl; @@ -755,24 +739,21 @@ void assemble_columns_to_reduce(std::vector& simplices, columns_to_reduce.push_back(e); } std::reverse(columns_to_reduce.begin(), columns_to_reduce.end()); - + #ifdef PRINT_PERSISTENCE_PAIRS for (index_t i = 0; i < n; ++i) if (dset.find(i) == i) std::cout << " [0, )" << std::endl << std::flush; #endif } - + for (index_t dim = 1; dim <= dim_max; ++dim) { hash_map pivot_column_index; pivot_column_index.reserve(columns_to_reduce.size()); - + compute_pairs(columns_to_reduce, pivot_column_index, dim); - - if (dim < dim_max) { - assemble_columns_to_reduce(simplices, columns_to_reduce, pivot_column_index, dim); - } + + if (dim < dim_max) { assemble_columns_to_reduce(simplices, columns_to_reduce, pivot_column_index, dim); } } - } }; @@ -995,9 +976,8 @@ int main(int argc, char** argv) { auto value_range = std::minmax_element(dist.distances.begin(), dist.distances.end()); std::cout << "value range: [" << *value_range.first << "," << *value_range.second << "]" << std::endl; - + sparse_distance_matrix sparse_dist(dist, threshold); - - ripser(std::move(dist), std::move(sparse_dist), dim_max, threshold, modulus).compute_barcodes(); + ripser(std::move(sparse_dist), dim_max, threshold, modulus).compute_barcodes(); } -- cgit v1.2.3 From f1af637b5d3552472e63a6715ea073540871bf65 Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Wed, 28 Dec 2016 14:32:21 +0100 Subject: code cleanup --- ripser.cpp | 126 ++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 66 insertions(+), 60 deletions(-) diff --git a/ripser.cpp b/ripser.cpp index 01e587b..ec06d05 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -24,6 +24,8 @@ with this program. If not, see . //#define INDICATE_PROGRESS #define PRINT_PERSISTENCE_PAIRS +#define SPARSE_DISTANCE_MATRIX + //#define USE_GOOGLE_HASHMAP #include @@ -52,7 +54,6 @@ typedef int16_t coefficient_t; class binomial_coeff_table { std::vector> B; - public: binomial_coeff_table(index_t n, index_t k) : B(n + 1) { for (index_t i = 0; i <= n; i++) { @@ -129,7 +130,6 @@ class diameter_index_t : public std::pair { public: diameter_index_t() : std::pair() {} diameter_index_t(std::pair p) : std::pair(p) {} - diameter_index_t(index_t i) : std::pair(0, i) {} }; value_t get_diameter(diameter_index_t i) { return i.first; } index_t get_index(diameter_index_t i) { return i.second; } @@ -379,51 +379,88 @@ class ripser { const binomial_coeff_table binomial_coeff; std::vector multiplicative_inverse; coefficient_t modulus; +#ifdef SPARSE_DISTANCE_MATRIX sparse_distance_matrix sparse_dist; - +#else + compressed_lower_distance_matrix dist; +#endif mutable std::vector vertices; +#ifdef SPARSE_DISTANCE_MATRIX mutable std::vector::const_reverse_iterator> ii; mutable std::vector::const_reverse_iterator> ee; - +#endif + public: ripser(sparse_distance_matrix&& _sparse_dist, index_t _dim_max, value_t _threshold, coefficient_t _modulus) : sparse_dist(_sparse_dist), n(_sparse_dist.size()), dim_max(std::min(_dim_max, index_t(_sparse_dist.size() - 2))), threshold(_threshold), modulus(_modulus), binomial_coeff(n, dim_max + 2), multiplicative_inverse(multiplicative_inverse_vector(_modulus)) {} + index_t get_next_vertex(index_t& v, const index_t idx, const index_t k) const { + if (binomial_coeff(v, k) > idx) { + index_t count = v; + while (count > 0) { + index_t i = v; + index_t step = count >> 1; + i -= step; + if (binomial_coeff(i, k) > idx) { + v = --i; + count -= step + 1; + } else + count = step; + } + } + assert(binomial_coeff(v, k) <= idx && binomial_coeff(v + 1, k) > idx); + return v; + } + + index_t get_edge_index(const index_t i, const index_t j) const { return binomial_coeff(i, 2) + j; } + + template + OutputIterator get_simplex_vertices(index_t idx, const index_t dim, index_t v, + OutputIterator out) const { + --v; + for (index_t k = dim + 1; k > 0; --k) { + get_next_vertex(v, idx, k); + *out++ = v; + idx -= binomial_coeff(v, k); + } + return out; + } + class simplex_coboundary_enumerator { private: const ripser& parent; - + index_t idx_below, idx_above, v, k, max_vertex_below; const diameter_entry_t simplex; const coefficient_t modulus; const sparse_distance_matrix& sparse_dist; const binomial_coeff_table& binomial_coeff; - + std::vector& vertices; std::vector::const_reverse_iterator>& ii; std::vector::const_reverse_iterator>& ee; diameter_index_t x; - + public: simplex_coboundary_enumerator(const diameter_entry_t _simplex, index_t _dim, const ripser& _parent) - : parent(_parent), simplex(_simplex), idx_below(get_index(_simplex)), idx_above(0), v(parent.n - 1), - k(_dim + 1), max_vertex_below(parent.n - 1), modulus(parent.modulus), sparse_dist(parent.sparse_dist), - binomial_coeff(parent.binomial_coeff), vertices(parent.vertices), ii(parent.ii), ee(parent.ee) { - + : parent(_parent), simplex(_simplex), idx_below(get_index(_simplex)), idx_above(0), v(parent.n - 1), + k(_dim + 1), max_vertex_below(parent.n - 1), modulus(parent.modulus), sparse_dist(parent.sparse_dist), + binomial_coeff(parent.binomial_coeff), vertices(parent.vertices), ii(parent.ii), ee(parent.ee) { + ii.clear(); ee.clear(); vertices.clear(); - + parent.get_simplex_vertices(idx_below, _dim, parent.n, std::back_inserter(vertices)); - + for (auto v : vertices) { ii.push_back(sparse_dist.neighbors[v].rbegin()); ee.push_back(sparse_dist.neighbors[v].rend()); } } - + bool has_next(bool all_cofaces = true) { for (auto &it0 = ii[0], &end0 = ee[0]; it0 != end0; ++it0) { x = *it0; @@ -442,55 +479,25 @@ public: } return false; } - + diameter_entry_t next() { ++ii[0]; - + while (k > 0 && parent.get_next_vertex(max_vertex_below, idx_below, k) > get_index(x)) { idx_below -= binomial_coeff(max_vertex_below, k); idx_above += binomial_coeff(max_vertex_below, k + 1); --k; } - + value_t coface_diameter = std::max(get_diameter(simplex), get_diameter(x)); - + coefficient_t coface_coefficient = (k & 1 ? -1 + modulus : 1) * get_coefficient(simplex) % modulus; - + return diameter_entry_t(coface_diameter, idx_above + binomial_coeff(get_index(x), k + 1) + idx_below, - coface_coefficient); + coface_coefficient); } }; - index_t get_next_vertex(index_t& v, const index_t idx, const index_t k) const { - if (binomial_coeff(v, k) > idx) { - index_t count = v; - while (count > 0) { - index_t i = v; - index_t step = count >> 1; - i -= step; - if (binomial_coeff(i, k) > idx) { - v = --i; - count -= step + 1; - } else - count = step; - } - } - assert(binomial_coeff(v, k) <= idx && binomial_coeff(v + 1, k) > idx); - return v; - } - - index_t get_edge_index(const index_t i, const index_t j) const { return binomial_coeff(i, 2) + j; } - - template - OutputIterator get_simplex_vertices(index_t idx, const index_t dim, index_t v, OutputIterator out) const { - --v; - for (index_t k = dim + 1; k > 0; --k) { - get_next_vertex(v, idx, k); - *out++ = v; - idx -= binomial_coeff(v, k); - } - return out; - } void assemble_columns_to_reduce(std::vector& simplices, std::vector& columns_to_reduce, @@ -707,18 +714,17 @@ public: std::vector columns_to_reduce; - std::vector simplices, &edges = simplices; - - for (index_t i = 0; i < n; ++i) - for (auto n : sparse_dist.neighbors[i]) { - index_t j = get_index(n); - if (i > j) edges.push_back(std::make_pair(get_diameter(n), get_edge_index(i, j))); - } - - std::sort(edges.rbegin(), edges.rend(), greater_diameter_or_smaller_index()); - + std::vector simplices; + { union_find dset(n); + std::vector &edges = simplices; + for (index_t i = 0; i < n; ++i) + for (auto n : sparse_dist.neighbors[i]) { + index_t j = get_index(n); + if (i > j) edges.push_back(std::make_pair(get_diameter(n), get_edge_index(i, j))); + } + std::sort(edges.rbegin(), edges.rend(), greater_diameter_or_smaller_index()); #ifdef PRINT_PERSISTENCE_PAIRS std::cout << "persistence intervals in dim 0:" << std::endl; -- cgit v1.2.3 From 31d0819c553fabbb25192797b250967216d699d3 Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Thu, 29 Dec 2016 16:12:38 +0100 Subject: more code cleanup --- ripser.cpp | 317 +++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 224 insertions(+), 93 deletions(-) diff --git a/ripser.cpp b/ripser.cpp index ec06d05..d0674f9 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -221,14 +221,12 @@ template <> void compressed_distance_matrix::init_rows() { } } -template <> value_t compressed_distance_matrix::operator()(index_t i, index_t j) const { - if (i > j) std::swap(i, j); - return i == j ? 0 : rows[i][j]; +template <> value_t compressed_distance_matrix::operator()(const index_t i, const index_t j) const { + return i == j ? 0 : i > j ? rows[j][i] : rows[i][j]; } -template <> value_t compressed_distance_matrix::operator()(index_t i, index_t j) const { - if (i > j) std::swap(i, j); - return i == j ? 0 : rows[j][i]; +template <> value_t compressed_distance_matrix::operator()(const index_t i, const index_t j) const { + return i == j ? 0 : i > j ? rows[i][j] : rows[j][i]; } typedef compressed_distance_matrix compressed_lower_distance_matrix; @@ -373,28 +371,22 @@ template void push_entry(Heap& column, index_t i, coefficient_t column.push(std::make_pair(diameter, e)); } -class ripser { - index_t dim_max, n; +template class ripser { + DistanceMatrix dist; + index_t n, dim_max; value_t threshold; const binomial_coeff_table binomial_coeff; std::vector multiplicative_inverse; coefficient_t modulus; -#ifdef SPARSE_DISTANCE_MATRIX - sparse_distance_matrix sparse_dist; -#else - compressed_lower_distance_matrix dist; -#endif mutable std::vector vertices; -#ifdef SPARSE_DISTANCE_MATRIX - mutable std::vector::const_reverse_iterator> ii; - mutable std::vector::const_reverse_iterator> ee; -#endif - + mutable std::vector::const_reverse_iterator> neighbor_it; + mutable std::vector::const_reverse_iterator> neighbor_end; + public: - ripser(sparse_distance_matrix&& _sparse_dist, index_t _dim_max, value_t _threshold, coefficient_t _modulus) - : sparse_dist(_sparse_dist), n(_sparse_dist.size()), - dim_max(std::min(_dim_max, index_t(_sparse_dist.size() - 2))), threshold(_threshold), modulus(_modulus), - binomial_coeff(n, dim_max + 2), multiplicative_inverse(multiplicative_inverse_vector(_modulus)) {} + ripser(DistanceMatrix&& _dist, index_t _dim_max, value_t _threshold, coefficient_t _modulus) + : dist(std::move(_dist)), n(dist.size()), dim_max(std::min(_dim_max, index_t(dist.size() - 2))), + threshold(_threshold), modulus(_modulus), binomial_coeff(n, dim_max + 2), + multiplicative_inverse(multiplicative_inverse_vector(_modulus)) {} index_t get_next_vertex(index_t& v, const index_t idx, const index_t k) const { if (binomial_coeff(v, k) > idx) { @@ -417,8 +409,7 @@ public: index_t get_edge_index(const index_t i, const index_t j) const { return binomial_coeff(i, 2) + j; } template - OutputIterator get_simplex_vertices(index_t idx, const index_t dim, index_t v, - OutputIterator out) const { + OutputIterator get_simplex_vertices(index_t idx, const index_t dim, index_t v, OutputIterator out) const { --v; for (index_t k = dim + 1; k > 0; --k) { get_next_vertex(v, idx, k); @@ -427,45 +418,92 @@ public: } return out; } - + + value_t compute_diameter(const index_t index, index_t dim) const { + value_t diam = -std::numeric_limits::infinity(); + + vertices.clear(); + get_simplex_vertices(index, dim, dist.size(), std::back_inserter(vertices)); + + for (index_t i = 0; i <= dim; ++i) + for (index_t j = 0; j < i; ++j) { diam = std::max(diam, dist(vertices[i], vertices[j])); } + return diam; + } + class simplex_coboundary_enumerator { + private: + index_t idx_below, idx_above, v, k; + std::vector vertices; + const diameter_entry_t simplex; + const coefficient_t modulus; + const compressed_lower_distance_matrix& dist; + const binomial_coeff_table& binomial_coeff; + + public: + simplex_coboundary_enumerator(const diameter_entry_t _simplex, index_t _dim, const ripser& parent) + : simplex(_simplex), idx_below(get_index(_simplex)), idx_above(0), v(parent.n - 1), k(_dim + 1), + modulus(parent.modulus), binomial_coeff(parent.binomial_coeff), dist(parent.dist), vertices(_dim + 1) { + parent.get_simplex_vertices(get_index(_simplex), _dim, parent.n, vertices.begin()); + } + + bool has_next() { + while ((v != -1) && (binomial_coeff(v, k) <= idx_below)) { + idx_below -= binomial_coeff(v, k); + idx_above += binomial_coeff(v, k + 1); + --v; + --k; + assert(k != -1); + } + return v != -1; + } + + diameter_entry_t next() { + value_t coface_diameter = get_diameter(simplex); + for (index_t w : vertices) coface_diameter = std::max(coface_diameter, dist(v, w)); + index_t coface_index = idx_above + binomial_coeff(v--, k + 1) + idx_below; + coefficient_t coface_coefficient = (k & 1 ? -1 + modulus : 1) * get_coefficient(simplex) % modulus; + return diameter_entry_t(coface_diameter, coface_index, coface_coefficient); + } + }; + + class simplex_sparse_coboundary_enumerator { private: const ripser& parent; - + index_t idx_below, idx_above, v, k, max_vertex_below; const diameter_entry_t simplex; const coefficient_t modulus; - const sparse_distance_matrix& sparse_dist; + const DistanceMatrix& dist; const binomial_coeff_table& binomial_coeff; - + std::vector& vertices; - std::vector::const_reverse_iterator>& ii; - std::vector::const_reverse_iterator>& ee; + std::vector::const_reverse_iterator>& neighbor_it; + std::vector::const_reverse_iterator>& neighbor_end; diameter_index_t x; - + public: - simplex_coboundary_enumerator(const diameter_entry_t _simplex, index_t _dim, const ripser& _parent) - : parent(_parent), simplex(_simplex), idx_below(get_index(_simplex)), idx_above(0), v(parent.n - 1), - k(_dim + 1), max_vertex_below(parent.n - 1), modulus(parent.modulus), sparse_dist(parent.sparse_dist), - binomial_coeff(parent.binomial_coeff), vertices(parent.vertices), ii(parent.ii), ee(parent.ee) { - - ii.clear(); - ee.clear(); + simplex_sparse_coboundary_enumerator(const diameter_entry_t _simplex, index_t _dim, const ripser& _parent) + : parent(_parent), simplex(_simplex), idx_below(get_index(_simplex)), idx_above(0), v(parent.n - 1), + k(_dim + 1), max_vertex_below(parent.n - 1), modulus(parent.modulus), dist(parent.dist), + binomial_coeff(parent.binomial_coeff), vertices(parent.vertices), neighbor_it(parent.neighbor_it), neighbor_end(parent.neighbor_end) { + + neighbor_it.clear(); + neighbor_end.clear(); vertices.clear(); - + parent.get_simplex_vertices(idx_below, _dim, parent.n, std::back_inserter(vertices)); - + for (auto v : vertices) { - ii.push_back(sparse_dist.neighbors[v].rbegin()); - ee.push_back(sparse_dist.neighbors[v].rend()); + neighbor_it.push_back(dist.neighbors[v].rbegin()); + neighbor_end.push_back(dist.neighbors[v].rend()); } } - + bool has_next(bool all_cofaces = true) { - for (auto &it0 = ii[0], &end0 = ee[0]; it0 != end0; ++it0) { + for (auto &it0 = neighbor_it[0], &end0 = neighbor_end[0]; it0 != end0; ++it0) { x = *it0; - for (size_t idx = 1; idx < ii.size(); ++idx) { - auto &it = ii[idx], end = ee[idx]; + for (size_t idx = 1; idx < neighbor_it.size(); ++idx) { + auto &it = neighbor_it[idx], end = neighbor_end[idx]; while (get_index(*it) > get_index(x)) if (++it == end) return false; auto y = *it; @@ -479,41 +517,77 @@ public: } return false; } - + diameter_entry_t next() { - ++ii[0]; - + ++neighbor_it[0]; + while (k > 0 && parent.get_next_vertex(max_vertex_below, idx_below, k) > get_index(x)) { idx_below -= binomial_coeff(max_vertex_below, k); idx_above += binomial_coeff(max_vertex_below, k + 1); --k; } - + value_t coface_diameter = std::max(get_diameter(simplex), get_diameter(x)); - + coefficient_t coface_coefficient = (k & 1 ? -1 + modulus : 1) * get_coefficient(simplex) % modulus; - + return diameter_entry_t(coface_diameter, idx_above + binomial_coeff(get_index(x), k + 1) + idx_below, - coface_coefficient); + coface_coefficient); } }; - - void assemble_columns_to_reduce(std::vector& simplices, - std::vector& columns_to_reduce, + void assemble_columns_to_reduce(std::vector& columns_to_reduce, hash_map& pivot_column_index, index_t dim) { + index_t num_simplices = binomial_coeff(n, dim + 1); + + columns_to_reduce.clear(); + +#ifdef INDICATE_PROGRESS + std::cout << "\033[K" + << "assembling " << num_simplices << " columns" << std::flush << "\r"; +#endif + + for (index_t index = 0; index < num_simplices; ++index) { + if (pivot_column_index.find(index) == pivot_column_index.end()) { + value_t diameter = compute_diameter(index, dim); + if (diameter <= threshold) columns_to_reduce.push_back(std::make_pair(diameter, index)); +#ifdef INDICATE_PROGRESS + if ((index + 1) % 1000 == 0) + std::cout << "\033[K" + << "assembled " << columns_to_reduce.size() << " out of " << (index + 1) << "/" + << num_simplices << " columns" << std::flush << "\r"; +#endif + } + } + +#ifdef INDICATE_PROGRESS + std::cout << "\033[K" + << "sorting " << num_simplices << " columns" << std::flush << "\r"; +#endif + + std::sort(columns_to_reduce.begin(), columns_to_reduce.end(), + greater_diameter_or_smaller_index()); +#ifdef INDICATE_PROGRESS + std::cout << "\033[K"; +#endif + } + + void assemble_sparse_columns_to_reduce(std::vector& simplices, + std::vector& columns_to_reduce, + hash_map& pivot_column_index, index_t dim) { #ifdef INDICATE_PROGRESS std::cout << "\033[K" << "assembling columns" << std::flush << "\r"; #endif + --dim; columns_to_reduce.clear(); std::vector next_simplices; for (diameter_index_t simplex : simplices) { - simplex_coboundary_enumerator cofaces(simplex, dim, *this); + simplex_sparse_coboundary_enumerator cofaces(simplex, dim, *this); while (cofaces.has_next(false)) { auto coface = cofaces.next(); @@ -539,6 +613,7 @@ public: #endif } + template void compute_pairs(std::vector& columns_to_reduce, hash_map& pivot_column_index, index_t dim) { @@ -624,7 +699,7 @@ public: #endif coface_entries.clear(); - simplex_coboundary_enumerator cofaces(simplex, dim, *this); + BoundaryEnumerator cofaces(simplex, dim, *this); while (cofaces.has_next()) { diameter_entry_t coface = cofaces.next(); if (get_diameter(coface) <= threshold) { @@ -710,58 +785,111 @@ public: #endif } - void compute_barcodes() { + void compute_barcodes(); +}; - std::vector columns_to_reduce; +template <> void ripser::compute_barcodes() { - std::vector simplices; - - { - union_find dset(n); - std::vector &edges = simplices; - for (index_t i = 0; i < n; ++i) - for (auto n : sparse_dist.neighbors[i]) { - index_t j = get_index(n); - if (i > j) edges.push_back(std::make_pair(get_diameter(n), get_edge_index(i, j))); - } - std::sort(edges.rbegin(), edges.rend(), greater_diameter_or_smaller_index()); + std::vector columns_to_reduce; + + { + union_find dset(n); + std::vector edges; + for (index_t index = binomial_coeff(n, 2); index-- > 0;) { + value_t diameter = compute_diameter(index, 1); + if (diameter <= threshold) edges.push_back(std::make_pair(diameter, index)); + } + std::sort(edges.rbegin(), edges.rend(), greater_diameter_or_smaller_index()); #ifdef PRINT_PERSISTENCE_PAIRS - std::cout << "persistence intervals in dim 0:" << std::endl; + std::cout << "persistence intervals in dim 0:" << std::endl; #endif - std::vector vertices_of_edge(2); - for (auto e : edges) { - vertices_of_edge.clear(); - get_simplex_vertices(get_index(e), 1, n, std::back_inserter(vertices_of_edge)); - index_t u = dset.find(vertices_of_edge[0]), v = dset.find(vertices_of_edge[1]); + std::vector vertices_of_edge(2); + for (auto e : edges) { + vertices_of_edge.clear(); + get_simplex_vertices(get_index(e), 1, n, std::back_inserter(vertices_of_edge)); + index_t u = dset.find(vertices_of_edge[0]), v = dset.find(vertices_of_edge[1]); - if (u != v) { + if (u != v) { #ifdef PRINT_PERSISTENCE_PAIRS - if (get_diameter(e) > 0) std::cout << " [0," << get_diameter(e) << ")" << std::endl; + if (get_diameter(e) != 0) std::cout << " [0," << get_diameter(e) << ")" << std::endl; #endif - dset.link(u, v); - } else - columns_to_reduce.push_back(e); + dset.link(u, v); + } else + columns_to_reduce.push_back(e); + } + std::reverse(columns_to_reduce.begin(), columns_to_reduce.end()); + +#ifdef PRINT_PERSISTENCE_PAIRS + for (index_t i = 0; i < n; ++i) + if (dset.find(i) == i) std::cout << " [0, )" << std::endl << std::flush; +#endif + } + + for (index_t dim = 1; dim <= dim_max; ++dim) { + hash_map pivot_column_index; + pivot_column_index.reserve(columns_to_reduce.size()); + + compute_pairs(columns_to_reduce, pivot_column_index, dim); + + if (dim < dim_max) { assemble_columns_to_reduce(columns_to_reduce, pivot_column_index, dim + 1); } + } +} + +template <> void ripser::compute_barcodes() { + + std::vector columns_to_reduce; + + std::vector simplices; + + { + union_find dset(n); + std::vector& edges = simplices; + for (index_t i = 0; i < n; ++i) + for (auto n : dist.neighbors[i]) { + index_t j = get_index(n); + if (i > j) edges.push_back(std::make_pair(get_diameter(n), get_edge_index(i, j))); } - std::reverse(columns_to_reduce.begin(), columns_to_reduce.end()); + std::sort(edges.rbegin(), edges.rend(), greater_diameter_or_smaller_index()); + +#ifdef PRINT_PERSISTENCE_PAIRS + std::cout << "persistence intervals in dim 0:" << std::endl; +#endif + + std::vector vertices_of_edge(2); + for (auto e : edges) { + vertices_of_edge.clear(); + get_simplex_vertices(get_index(e), 1, n, std::back_inserter(vertices_of_edge)); + index_t u = dset.find(vertices_of_edge[0]), v = dset.find(vertices_of_edge[1]); + if (u != v) { #ifdef PRINT_PERSISTENCE_PAIRS - for (index_t i = 0; i < n; ++i) - if (dset.find(i) == i) std::cout << " [0, )" << std::endl << std::flush; + if (get_diameter(e) != 0) std::cout << " [0," << get_diameter(e) << ")" << std::endl; #endif + dset.link(u, v); + } else + columns_to_reduce.push_back(e); } + std::reverse(columns_to_reduce.begin(), columns_to_reduce.end()); + +#ifdef PRINT_PERSISTENCE_PAIRS + for (index_t i = 0; i < n; ++i) + if (dset.find(i) == i) std::cout << " [0, )" << std::endl << std::flush; +#endif + } - for (index_t dim = 1; dim <= dim_max; ++dim) { - hash_map pivot_column_index; - pivot_column_index.reserve(columns_to_reduce.size()); + for (index_t dim = 1; dim <= dim_max; ++dim) { + hash_map pivot_column_index; + pivot_column_index.reserve(columns_to_reduce.size()); - compute_pairs(columns_to_reduce, pivot_column_index, dim); + compute_pairs(columns_to_reduce, pivot_column_index, dim); - if (dim < dim_max) { assemble_columns_to_reduce(simplices, columns_to_reduce, pivot_column_index, dim); } + if (dim < dim_max) { + assemble_sparse_columns_to_reduce(simplices, columns_to_reduce, pivot_column_index, dim + 1); } } -}; +} enum file_format { LOWER_DISTANCE_MATRIX, UPPER_DISTANCE_MATRIX, DISTANCE_MATRIX, POINT_CLOUD, DIPHA, RIPSER }; @@ -983,7 +1111,10 @@ int main(int argc, char** argv) { auto value_range = std::minmax_element(dist.distances.begin(), dist.distances.end()); std::cout << "value range: [" << *value_range.first << "," << *value_range.second << "]" << std::endl; - sparse_distance_matrix sparse_dist(dist, threshold); - ripser(std::move(sparse_dist), dim_max, threshold, modulus).compute_barcodes(); +#ifdef SPARSE_DISTANCE_MATRIX + ripser(std::move(dist), dim_max, threshold, modulus).compute_barcodes(); +#else + ripser(sparse_distance_matrix(dist, threshold), dim_max, threshold, modulus).compute_barcodes(); +#endif } -- cgit v1.2.3 From b945df6609d9198c34a982e70dee0773ee630897 Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Thu, 29 Dec 2016 19:26:55 +0100 Subject: reordered initializers --- ripser.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ripser.cpp b/ripser.cpp index 49ff6a8..3054441 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -508,8 +508,8 @@ public: public: simplex_sparse_coboundary_enumerator(const diameter_entry_t _simplex, index_t _dim, const ripser& _parent) - : parent(_parent), simplex(_simplex), idx_below(get_index(_simplex)), idx_above(0), - v(parent.n - 1), k(_dim + 1), max_vertex_below(parent.n - 1), modulus(parent.modulus), + : parent(_parent), idx_below(get_index(_simplex)), idx_above(0), + v(parent.n - 1), k(_dim + 1), max_vertex_below(parent.n - 1), simplex(_simplex), modulus(parent.modulus), dist(parent.dist), binomial_coeff(parent.binomial_coeff), vertices(parent.vertices), neighbor_it(parent.neighbor_it), neighbor_end(parent.neighbor_end) { -- cgit v1.2.3 From 2989ecd1047fcae2b8fead4b8fca1a4608342576 Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Thu, 29 Dec 2016 23:07:00 +0100 Subject: use sparse distance matrix when threshold is given --- ripser.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/ripser.cpp b/ripser.cpp index 3054441..4ac5033 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -24,8 +24,6 @@ with this program. If not, see . //#define INDICATE_PROGRESS #define PRINT_PERSISTENCE_PAIRS -#define SPARSE_DISTANCE_MATRIX - //#define USE_GOOGLE_HASHMAP #include @@ -1063,14 +1061,14 @@ int main(int argc, char** argv) { std::cout << "value range: [" << *value_range.first << "," << *value_range.second << "]" << std::endl; -#ifdef SPARSE_DISTANCE_MATRIX - ripser(std::move(dist), dim_max, threshold, modulus) - .compute_barcodes(); -#else - ripser(sparse_distance_matrix(dist, threshold), dim_max, threshold, - modulus) - .compute_barcodes(); -#endif + if (threshold == std::numeric_limits::max()) + ripser(std::move(dist), dim_max, threshold, modulus) + .compute_barcodes(); + else + ripser(sparse_distance_matrix(dist, threshold), dim_max, threshold, + modulus) + .compute_barcodes(); + } template <> void ripser::compute_barcodes() { -- cgit v1.2.3 From 31a18897fb52e4e98faed5562e6b97da1e024b4c Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Sat, 7 Jan 2017 00:31:25 +0100 Subject: move --- ripser.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ripser.cpp b/ripser.cpp index 701ba35..fbbd345 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -1071,8 +1071,8 @@ int main(int argc, char** argv) { ripser(std::move(dist), dim_max, threshold, modulus) .compute_barcodes(); else - ripser(sparse_distance_matrix(dist, threshold), dim_max, threshold, - modulus) + ripser(sparse_distance_matrix(std::move(dist), threshold), dim_max, + threshold, modulus) .compute_barcodes(); } -- cgit v1.2.3 From 02e1d32f8c19a92b91dab3fc2520a6f4a98640f1 Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Thu, 24 Aug 2017 12:36:23 +0200 Subject: threshold for sparse distance matrix --- ripser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ripser.cpp b/ripser.cpp index 2f5a01a..74f9224 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -1079,7 +1079,7 @@ int main(int argc, char** argv) { std::cout << "value range: [" << min << "," << max << "]" << std::endl; - if (threshold == std::numeric_limits::max()) + if (threshold == std::numeric_limits::infinity()) ripser(std::move(dist), dim_max, threshold, modulus) .compute_barcodes(); else -- cgit v1.2.3 From b6b8b14a129107fc5bd70c999d551a6c9632881d Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Sat, 26 Aug 2017 08:19:09 +0200 Subject: filter by persistence ratio --- ripser.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/ripser.cpp b/ripser.cpp index 74f9224..2f41b05 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -394,6 +394,7 @@ template class ripser { DistanceMatrix dist; index_t n, dim_max; value_t threshold; + float ratio; coefficient_t modulus; const binomial_coeff_table binomial_coeff; std::vector multiplicative_inverse; @@ -402,10 +403,10 @@ template class ripser { mutable std::vector::const_reverse_iterator> neighbor_end; public: - ripser(DistanceMatrix&& _dist, index_t _dim_max, value_t _threshold, coefficient_t _modulus) + ripser(DistanceMatrix&& _dist, index_t _dim_max, value_t _threshold, float _ratio, coefficient_t _modulus) : dist(std::move(_dist)), n(dist.size()), dim_max(std::min(_dim_max, index_t(dist.size() - 2))), threshold(_threshold), - modulus(_modulus), binomial_coeff(n, dim_max + 2), + ratio(_ratio), modulus(_modulus), binomial_coeff(n, dim_max + 2), multiplicative_inverse(multiplicative_inverse_vector(_modulus)) {} index_t get_next_vertex(index_t& v, const index_t idx, const index_t k) const { @@ -781,7 +782,7 @@ public: found_persistence_pair: #ifdef PRINT_PERSISTENCE_PAIRS value_t death = get_diameter(pivot); - if (diameter != death) { + if ((float)death/diameter > ratio) { #ifdef INDICATE_PROGRESS std::cout << "\033[K"; #endif @@ -1003,6 +1004,9 @@ int main(int argc, char** argv) { index_t dim_max = 1; value_t threshold = std::numeric_limits::infinity(); + + float ratio = 1; + #ifdef USE_COEFFICIENTS coefficient_t modulus = 2; @@ -1024,6 +1028,11 @@ int main(int argc, char** argv) { size_t next_pos; threshold = std::stof(parameter, &next_pos); if (next_pos != parameter.size()) print_usage_and_exit(-1); + } else if (arg == "--ratio") { + std::string parameter = std::string(argv[++i]); + size_t next_pos; + ratio = std::stof(parameter, &next_pos); + if (next_pos != parameter.size()) print_usage_and_exit(-1); } else if (arg == "--format") { std::string parameter = std::string(argv[++i]); if (parameter == "lower-distance") @@ -1080,11 +1089,11 @@ int main(int argc, char** argv) { << std::endl; if (threshold == std::numeric_limits::infinity()) - ripser(std::move(dist), dim_max, threshold, modulus) + ripser(std::move(dist), dim_max, threshold, ratio, modulus) .compute_barcodes(); else ripser(sparse_distance_matrix(std::move(dist), threshold), dim_max, - threshold, modulus) + threshold, ratio, modulus) .compute_barcodes(); } -- cgit v1.2.3 From 922acb40aec110347ac17da391ce5ae2b5da57db Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Sun, 24 Sep 2017 18:19:44 +0200 Subject: consolidated code for sparse and dense distance matrices --- ripser.cpp | 593 +++++++++++++++++++++++++++++-------------------------------- 1 file changed, 283 insertions(+), 310 deletions(-) diff --git a/ripser.cpp b/ripser.cpp index 2f41b05..1cb1d79 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -456,201 +456,12 @@ public: return diam; } - class simplex_coboundary_enumerator { - private: - index_t idx_below, idx_above, v, k; - std::vector vertices; - const diameter_entry_t simplex; - const coefficient_t modulus; - const compressed_lower_distance_matrix& dist; - const binomial_coeff_table& binomial_coeff; - - public: - simplex_coboundary_enumerator(const diameter_entry_t _simplex, index_t _dim, - const ripser& parent) - : idx_below(get_index(_simplex)), idx_above(0), v(parent.n - 1), k(_dim + 1), - vertices(_dim + 1), simplex(_simplex), modulus(parent.modulus), dist(parent.dist), - binomial_coeff(parent.binomial_coeff) { - parent.get_simplex_vertices(get_index(_simplex), _dim, parent.n, vertices.begin()); - } - - bool has_next() { - while ((v != -1) && (binomial_coeff(v, k) <= idx_below)) { - idx_below -= binomial_coeff(v, k); - idx_above += binomial_coeff(v, k + 1); - --v; - --k; - assert(k != -1); - } - return v != -1; - } - - diameter_entry_t next() { - value_t coface_diameter = get_diameter(simplex); - for (index_t w : vertices) coface_diameter = std::max(coface_diameter, dist(v, w)); - index_t coface_index = idx_above + binomial_coeff(v--, k + 1) + idx_below; - coefficient_t coface_coefficient = - (k & 1 ? -1 + modulus : 1) * get_coefficient(simplex) % modulus; - return diameter_entry_t(coface_diameter, coface_index, coface_coefficient); - } - }; - - class simplex_sparse_coboundary_enumerator { - private: - const ripser& parent; - - index_t idx_below, idx_above, v, k, max_vertex_below; - const diameter_entry_t simplex; - const coefficient_t modulus; - const DistanceMatrix& dist; - const binomial_coeff_table& binomial_coeff; - - std::vector& vertices; - std::vector::const_reverse_iterator>& neighbor_it; - std::vector::const_reverse_iterator>& neighbor_end; - diameter_index_t x; - - public: - simplex_sparse_coboundary_enumerator(const diameter_entry_t _simplex, index_t _dim, - const ripser& _parent) - : parent(_parent), idx_below(get_index(_simplex)), idx_above(0), - v(parent.n - 1), k(_dim + 1), max_vertex_below(parent.n - 1), simplex(_simplex), modulus(parent.modulus), - dist(parent.dist), binomial_coeff(parent.binomial_coeff), vertices(parent.vertices), - neighbor_it(parent.neighbor_it), neighbor_end(parent.neighbor_end) { - - neighbor_it.clear(); - neighbor_end.clear(); - vertices.clear(); - - parent.get_simplex_vertices(idx_below, _dim, parent.n, std::back_inserter(vertices)); - - for (auto v : vertices) { - neighbor_it.push_back(dist.neighbors[v].rbegin()); - neighbor_end.push_back(dist.neighbors[v].rend()); - } - } - - bool has_next(bool all_cofaces = true) { - for (auto &it0 = neighbor_it[0], &end0 = neighbor_end[0]; it0 != end0; ++it0) { - x = *it0; - for (size_t idx = 1; idx < neighbor_it.size(); ++idx) { - auto &it = neighbor_it[idx], end = neighbor_end[idx]; - while (get_index(*it) > get_index(x)) - if (++it == end) return false; - auto y = *it; - if (get_index(y) != get_index(x)) - goto continue_outer; - else - x = std::max(x, y); - } - return all_cofaces || - !(k > 0 && - parent.get_next_vertex(max_vertex_below, idx_below, k) > get_index(x)); - continue_outer:; - } - return false; - } - - diameter_entry_t next() { - ++neighbor_it[0]; - - while (k > 0 && parent.get_next_vertex(max_vertex_below, idx_below, k) > get_index(x)) { - idx_below -= binomial_coeff(max_vertex_below, k); - idx_above += binomial_coeff(max_vertex_below, k + 1); - --k; - } - - value_t coface_diameter = std::max(get_diameter(simplex), get_diameter(x)); - - coefficient_t coface_coefficient = - (k & 1 ? -1 + modulus : 1) * get_coefficient(simplex) % modulus; - - return diameter_entry_t(coface_diameter, - idx_above + binomial_coeff(get_index(x), k + 1) + idx_below, - coface_coefficient); - } - }; - - void assemble_columns_to_reduce(std::vector& columns_to_reduce, - hash_map& pivot_column_index, index_t dim) { - index_t num_simplices = binomial_coeff(n, dim + 1); - - columns_to_reduce.clear(); - -#ifdef INDICATE_PROGRESS - std::cout << "\033[K" - << "assembling " << num_simplices << " columns" << std::flush << "\r"; -#endif - - for (index_t index = 0; index < num_simplices; ++index) { - if (pivot_column_index.find(index) == pivot_column_index.end()) { - value_t diameter = compute_diameter(index, dim); - if (diameter <= threshold) - columns_to_reduce.push_back(std::make_pair(diameter, index)); -#ifdef INDICATE_PROGRESS - if ((index + 1) % 1000000 == 0) - std::cout << "\033[K" - << "assembled " << columns_to_reduce.size() << " out of " - << (index + 1) << "/" << num_simplices << " columns" << std::flush - << "\r"; -#endif - } - } - -#ifdef INDICATE_PROGRESS - std::cout << "\033[K" - << "sorting " << num_simplices << " columns" << std::flush << "\r"; -#endif - - std::sort(columns_to_reduce.begin(), columns_to_reduce.end(), - greater_diameter_or_smaller_index()); -#ifdef INDICATE_PROGRESS - std::cout << "\033[K"; -#endif - } - - void assemble_sparse_columns_to_reduce(std::vector& simplices, - std::vector& columns_to_reduce, - hash_map& pivot_column_index, - index_t dim) { - -#ifdef INDICATE_PROGRESS - std::cout << "\033[K" - << "assembling columns" << std::flush << "\r"; -#endif - - --dim; - columns_to_reduce.clear(); - - std::vector next_simplices; - - for (diameter_index_t simplex : simplices) { - simplex_sparse_coboundary_enumerator cofaces(simplex, dim, *this); - - while (cofaces.has_next(false)) { - auto coface = cofaces.next(); - - next_simplices.push_back(std::make_pair(get_diameter(coface), get_index(coface))); - - if (pivot_column_index.find(get_index(coface)) == pivot_column_index.end()) - columns_to_reduce.push_back( - std::make_pair(get_diameter(coface), get_index(coface))); - } - } - - simplices.swap(next_simplices); - -#ifdef INDICATE_PROGRESS - std::cout << "\033[K" - << "sorting " << columns_to_reduce.size() << " columns" << std::flush << "\r"; -#endif + class simplex_coboundary_enumerator; - std::sort(columns_to_reduce.begin(), columns_to_reduce.end(), - greater_diameter_or_smaller_index()); -#ifdef INDICATE_PROGRESS - std::cout << "\033[K"; -#endif - } + void assemble_columns_to_reduce(std::vector& simplices, + std::vector& columns_to_reduce, + hash_map& pivot_column_index, + index_t dim); template void compute_pairs(std::vector& columns_to_reduce, @@ -829,11 +640,286 @@ public: #endif } - void compute_barcodes(); + std::vector get_edges(); + + void compute_barcodes() { + + std::vector columns_to_reduce; + + std::vector simplices; + + { + union_find dset(n); + std::vector& edges = simplices; + + edges = get_edges(); + + std::sort(edges.rbegin(), edges.rend(), + greater_diameter_or_smaller_index()); + +#ifdef PRINT_PERSISTENCE_PAIRS + std::cout << "persistence intervals in dim 0:" << std::endl; +#endif + + std::vector vertices_of_edge(2); + for (auto e : edges) { + vertices_of_edge.clear(); + get_simplex_vertices(get_index(e), 1, n, std::back_inserter(vertices_of_edge)); + index_t u = dset.find(vertices_of_edge[0]), v = dset.find(vertices_of_edge[1]); + + if (u != v) { +#ifdef PRINT_PERSISTENCE_PAIRS + if (get_diameter(e) != 0) + std::cout << " [0," << get_diameter(e) << ")" << std::endl; +#endif + dset.link(u, v); + } else + columns_to_reduce.push_back(e); + } + std::reverse(columns_to_reduce.begin(), columns_to_reduce.end()); + +#ifdef PRINT_PERSISTENCE_PAIRS + for (index_t i = 0; i < n; ++i) + if (dset.find(i) == i) std::cout << " [0, )" << std::endl << std::flush; +#endif + } + + for (index_t dim = 1; dim <= dim_max; ++dim) { + hash_map pivot_column_index; + pivot_column_index.reserve(columns_to_reduce.size()); + + compute_pairs(columns_to_reduce, pivot_column_index, + dim); + + if (dim < dim_max) { + assemble_columns_to_reduce(simplices, columns_to_reduce, pivot_column_index, + dim + 1); + } + } + } }; -template <> void ripser::compute_barcodes(); -template <> void ripser::compute_barcodes(); + +template <> +class ripser::simplex_coboundary_enumerator { +private: + index_t idx_below, idx_above, v, k; + std::vector vertices; + const diameter_entry_t simplex; + const coefficient_t modulus; + const compressed_lower_distance_matrix& dist; + const binomial_coeff_table& binomial_coeff; + +public: + simplex_coboundary_enumerator(const diameter_entry_t _simplex, index_t _dim, + const ripser& parent) + : idx_below(get_index(_simplex)), idx_above(0), v(parent.n - 1), k(_dim + 1), + vertices(_dim + 1), simplex(_simplex), modulus(parent.modulus), dist(parent.dist), + binomial_coeff(parent.binomial_coeff) { + parent.get_simplex_vertices(get_index(_simplex), _dim, parent.n, vertices.begin()); + } + + bool has_next() { + while ((v != -1) && (binomial_coeff(v, k) <= idx_below)) { + idx_below -= binomial_coeff(v, k); + idx_above += binomial_coeff(v, k + 1); + --v; + --k; + assert(k != -1); + } + return v != -1; + } + + diameter_entry_t next() { + value_t coface_diameter = get_diameter(simplex); + for (index_t w : vertices) coface_diameter = std::max(coface_diameter, dist(v, w)); + index_t coface_index = idx_above + binomial_coeff(v--, k + 1) + idx_below; + coefficient_t coface_coefficient = + (k & 1 ? -1 + modulus : 1) * get_coefficient(simplex) % modulus; + return diameter_entry_t(coface_diameter, coface_index, coface_coefficient); + } +}; + +template <> +class ripser::simplex_coboundary_enumerator { +private: + const ripser& parent; + + index_t idx_below, idx_above, v, k, max_vertex_below; + const diameter_entry_t simplex; + const coefficient_t modulus; + const sparse_distance_matrix& dist; + const binomial_coeff_table& binomial_coeff; + + std::vector& vertices; + std::vector::const_reverse_iterator>& neighbor_it; + std::vector::const_reverse_iterator>& neighbor_end; + diameter_index_t x; + +public: + simplex_coboundary_enumerator(const diameter_entry_t _simplex, index_t _dim, + const ripser& _parent) + : parent(_parent), idx_below(get_index(_simplex)), idx_above(0), + v(parent.n - 1), k(_dim + 1), max_vertex_below(parent.n - 1), simplex(_simplex), modulus(parent.modulus), + dist(parent.dist), binomial_coeff(parent.binomial_coeff), vertices(parent.vertices), + neighbor_it(parent.neighbor_it), neighbor_end(parent.neighbor_end) { + + neighbor_it.clear(); + neighbor_end.clear(); + vertices.clear(); + + parent.get_simplex_vertices(idx_below, _dim, parent.n, std::back_inserter(vertices)); + + for (auto v : vertices) { + neighbor_it.push_back(dist.neighbors[v].rbegin()); + neighbor_end.push_back(dist.neighbors[v].rend()); + } + } + + bool has_next(bool all_cofaces = true) { + for (auto &it0 = neighbor_it[0], &end0 = neighbor_end[0]; it0 != end0; ++it0) { + x = *it0; + for (size_t idx = 1; idx < neighbor_it.size(); ++idx) { + auto &it = neighbor_it[idx], end = neighbor_end[idx]; + while (get_index(*it) > get_index(x)) + if (++it == end) return false; + auto y = *it; + if (get_index(y) != get_index(x)) + goto continue_outer; + else + x = std::max(x, y); + } + return all_cofaces || + !(k > 0 && + parent.get_next_vertex(max_vertex_below, idx_below, k) > get_index(x)); + continue_outer:; + } + return false; + } + + diameter_entry_t next() { + ++neighbor_it[0]; + + while (k > 0 && parent.get_next_vertex(max_vertex_below, idx_below, k) > get_index(x)) { + idx_below -= binomial_coeff(max_vertex_below, k); + idx_above += binomial_coeff(max_vertex_below, k + 1); + --k; + } + + value_t coface_diameter = std::max(get_diameter(simplex), get_diameter(x)); + + coefficient_t coface_coefficient = + (k & 1 ? -1 + modulus : 1) * get_coefficient(simplex) % modulus; + + return diameter_entry_t(coface_diameter, + idx_above + binomial_coeff(get_index(x), k + 1) + idx_below, + coface_coefficient); + } +}; + + +template <> std::vector ripser::get_edges() { + std::vector edges; + for (index_t index = binomial_coeff(n, 2); index-- > 0;) { + value_t diameter = compute_diameter(index, 1); + if (diameter <= threshold) edges.push_back(std::make_pair(diameter, index)); + } + return edges; +} + +template <> std::vector ripser::get_edges() { + std::vector edges; + for (index_t i = 0; i < n; ++i) + for (auto n : dist.neighbors[i]) { + index_t j = get_index(n); + if (i > j) edges.push_back(std::make_pair(get_diameter(n), get_edge_index(i, j))); + } + return edges; +} + +template <> void ripser:: +assemble_columns_to_reduce(std::vector& simplices, + std::vector& columns_to_reduce, + hash_map& pivot_column_index, index_t dim) { + index_t num_simplices = binomial_coeff(n, dim + 1); + + columns_to_reduce.clear(); + +#ifdef INDICATE_PROGRESS + std::cout << "\033[K" + << "assembling " << num_simplices << " columns" << std::flush << "\r"; +#endif + + for (index_t index = 0; index < num_simplices; ++index) { + if (pivot_column_index.find(index) == pivot_column_index.end()) { + value_t diameter = compute_diameter(index, dim); + if (diameter <= threshold) + columns_to_reduce.push_back(std::make_pair(diameter, index)); +#ifdef INDICATE_PROGRESS + if ((index + 1) % 1000000 == 0) + std::cout << "\033[K" + << "assembled " << columns_to_reduce.size() << " out of " + << (index + 1) << "/" << num_simplices << " columns" << std::flush + << "\r"; +#endif + } + } + +#ifdef INDICATE_PROGRESS + std::cout << "\033[K" + << "sorting " << num_simplices << " columns" << std::flush << "\r"; +#endif + + std::sort(columns_to_reduce.begin(), columns_to_reduce.end(), + greater_diameter_or_smaller_index()); +#ifdef INDICATE_PROGRESS + std::cout << "\033[K"; +#endif +} + +template <> void ripser:: +assemble_columns_to_reduce(std::vector& simplices, + std::vector& columns_to_reduce, + hash_map& pivot_column_index, + index_t dim) { + +#ifdef INDICATE_PROGRESS + std::cout << "\033[K" + << "assembling columns" << std::flush << "\r"; +#endif + + --dim; + columns_to_reduce.clear(); + + std::vector next_simplices; + + for (diameter_index_t simplex : simplices) { + simplex_coboundary_enumerator cofaces(simplex, dim, *this); + + while (cofaces.has_next(false)) { + auto coface = cofaces.next(); + + next_simplices.push_back(std::make_pair(get_diameter(coface), get_index(coface))); + + if (pivot_column_index.find(get_index(coface)) == pivot_column_index.end()) + columns_to_reduce.push_back( + std::make_pair(get_diameter(coface), get_index(coface))); + } + } + + simplices.swap(next_simplices); + +#ifdef INDICATE_PROGRESS + std::cout << "\033[K" + << "sorting " << columns_to_reduce.size() << " columns" << std::flush << "\r"; +#endif + + std::sort(columns_to_reduce.begin(), columns_to_reduce.end(), + greater_diameter_or_smaller_index()); +#ifdef INDICATE_PROGRESS + std::cout << "\033[K"; +#endif +} enum file_format { LOWER_DISTANCE_MATRIX, @@ -1072,8 +1158,6 @@ int main(int argc, char** argv) { std::cout << "distance matrix with " << dist.size() << " points" << std::endl; - auto value_range = std::minmax_element(dist.distances.begin(), dist.distances.end()); - value_t min = std::numeric_limits::infinity(), max = -std::numeric_limits::infinity(); for (auto d: dist.distances) { @@ -1097,114 +1181,3 @@ int main(int argc, char** argv) { .compute_barcodes(); } - -template <> void ripser::compute_barcodes() { - - std::vector columns_to_reduce; - - { - union_find dset(n); - std::vector edges; - for (index_t index = binomial_coeff(n, 2); index-- > 0;) { - value_t diameter = compute_diameter(index, 1); - if (diameter <= threshold) edges.push_back(std::make_pair(diameter, index)); - } - std::sort(edges.rbegin(), edges.rend(), - greater_diameter_or_smaller_index()); - -#ifdef PRINT_PERSISTENCE_PAIRS - std::cout << "persistence intervals in dim 0:" << std::endl; -#endif - - std::vector vertices_of_edge(2); - for (auto e : edges) { - vertices_of_edge.clear(); - get_simplex_vertices(get_index(e), 1, n, std::back_inserter(vertices_of_edge)); - index_t u = dset.find(vertices_of_edge[0]), v = dset.find(vertices_of_edge[1]); - - if (u != v) { -#ifdef PRINT_PERSISTENCE_PAIRS - if (get_diameter(e) != 0) - std::cout << " [0," << get_diameter(e) << ")" << std::endl; -#endif - dset.link(u, v); - } else - columns_to_reduce.push_back(e); - } - std::reverse(columns_to_reduce.begin(), columns_to_reduce.end()); - -#ifdef PRINT_PERSISTENCE_PAIRS - for (index_t i = 0; i < n; ++i) - if (dset.find(i) == i) std::cout << " [0, )" << std::endl << std::flush; -#endif - } - - for (index_t dim = 1; dim <= dim_max; ++dim) { - hash_map pivot_column_index; - pivot_column_index.reserve(columns_to_reduce.size()); - - compute_pairs(columns_to_reduce, pivot_column_index, dim); - - if (dim < dim_max) { - assemble_columns_to_reduce(columns_to_reduce, pivot_column_index, dim + 1); - } - } -} - -template <> void ripser::compute_barcodes() { - - std::vector columns_to_reduce; - - std::vector simplices; - - { - union_find dset(n); - std::vector& edges = simplices; - for (index_t i = 0; i < n; ++i) - for (auto n : dist.neighbors[i]) { - index_t j = get_index(n); - if (i > j) edges.push_back(std::make_pair(get_diameter(n), get_edge_index(i, j))); - } - std::sort(edges.rbegin(), edges.rend(), - greater_diameter_or_smaller_index()); - -#ifdef PRINT_PERSISTENCE_PAIRS - std::cout << "persistence intervals in dim 0:" << std::endl; -#endif - - std::vector vertices_of_edge(2); - for (auto e : edges) { - vertices_of_edge.clear(); - get_simplex_vertices(get_index(e), 1, n, std::back_inserter(vertices_of_edge)); - index_t u = dset.find(vertices_of_edge[0]), v = dset.find(vertices_of_edge[1]); - - if (u != v) { -#ifdef PRINT_PERSISTENCE_PAIRS - if (get_diameter(e) != 0) - std::cout << " [0," << get_diameter(e) << ")" << std::endl; -#endif - dset.link(u, v); - } else - columns_to_reduce.push_back(e); - } - std::reverse(columns_to_reduce.begin(), columns_to_reduce.end()); - -#ifdef PRINT_PERSISTENCE_PAIRS - for (index_t i = 0; i < n; ++i) - if (dset.find(i) == i) std::cout << " [0, )" << std::endl << std::flush; -#endif - } - - for (index_t dim = 1; dim <= dim_max; ++dim) { - hash_map pivot_column_index; - pivot_column_index.reserve(columns_to_reduce.size()); - - compute_pairs(columns_to_reduce, pivot_column_index, - dim); - - if (dim < dim_max) { - assemble_sparse_columns_to_reduce(simplices, columns_to_reduce, pivot_column_index, - dim + 1); - } - } -} -- cgit v1.2.3 From 12bda394bdf6d2c610600b246b500908f88e4d10 Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Sun, 24 Sep 2017 18:59:04 +0200 Subject: extracted dim 0 computation --- ripser.cpp | 80 +++++++++++++++++++++++++++++++------------------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/ripser.cpp b/ripser.cpp index 1cb1d79..688df6a 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -462,6 +462,42 @@ public: std::vector& columns_to_reduce, hash_map& pivot_column_index, index_t dim); + + void compute_dim_0_pairs(std::vector& edges, + std::vector& columns_to_reduce) { + union_find dset(n); + + edges = get_edges(); + + std::sort(edges.rbegin(), edges.rend(), + greater_diameter_or_smaller_index()); + +#ifdef PRINT_PERSISTENCE_PAIRS + std::cout << "persistence intervals in dim 0:" << std::endl; +#endif + + std::vector vertices_of_edge(2); + for (auto e : edges) { + vertices_of_edge.clear(); + get_simplex_vertices(get_index(e), 1, n, std::back_inserter(vertices_of_edge)); + index_t u = dset.find(vertices_of_edge[0]), v = dset.find(vertices_of_edge[1]); + + if (u != v) { +#ifdef PRINT_PERSISTENCE_PAIRS + if (get_diameter(e) != 0) + std::cout << " [0," << get_diameter(e) << ")" << std::endl; +#endif + dset.link(u, v); + } else + columns_to_reduce.push_back(e); + } + std::reverse(columns_to_reduce.begin(), columns_to_reduce.end()); + +#ifdef PRINT_PERSISTENCE_PAIRS + for (index_t i = 0; i < n; ++i) + if (dset.find(i) == i) std::cout << " [0, )" << std::endl << std::flush; +#endif + } template void compute_pairs(std::vector& columns_to_reduce, @@ -644,56 +680,20 @@ public: void compute_barcodes() { - std::vector columns_to_reduce; + std::vector simplices, columns_to_reduce; - std::vector simplices; - - { - union_find dset(n); - std::vector& edges = simplices; - - edges = get_edges(); - - std::sort(edges.rbegin(), edges.rend(), - greater_diameter_or_smaller_index()); - -#ifdef PRINT_PERSISTENCE_PAIRS - std::cout << "persistence intervals in dim 0:" << std::endl; -#endif - - std::vector vertices_of_edge(2); - for (auto e : edges) { - vertices_of_edge.clear(); - get_simplex_vertices(get_index(e), 1, n, std::back_inserter(vertices_of_edge)); - index_t u = dset.find(vertices_of_edge[0]), v = dset.find(vertices_of_edge[1]); - - if (u != v) { -#ifdef PRINT_PERSISTENCE_PAIRS - if (get_diameter(e) != 0) - std::cout << " [0," << get_diameter(e) << ")" << std::endl; -#endif - dset.link(u, v); - } else - columns_to_reduce.push_back(e); - } - std::reverse(columns_to_reduce.begin(), columns_to_reduce.end()); - -#ifdef PRINT_PERSISTENCE_PAIRS - for (index_t i = 0; i < n; ++i) - if (dset.find(i) == i) std::cout << " [0, )" << std::endl << std::flush; -#endif - } + compute_dim_0_pairs(simplices, columns_to_reduce); for (index_t dim = 1; dim <= dim_max; ++dim) { hash_map pivot_column_index; pivot_column_index.reserve(columns_to_reduce.size()); compute_pairs(columns_to_reduce, pivot_column_index, - dim); + dim); if (dim < dim_max) { assemble_columns_to_reduce(simplices, columns_to_reduce, pivot_column_index, - dim + 1); + dim + 1); } } } -- cgit v1.2.3 From 740992e73b581c646f0f381789264f2504e76e8b Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Sun, 24 Sep 2017 19:16:08 +0200 Subject: use sparse distance matrix only when threshold is below maximum value --- ripser.cpp | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/ripser.cpp b/ripser.cpp index 688df6a..5acc32e 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -1089,10 +1089,9 @@ int main(int argc, char** argv) { file_format format = DISTANCE_MATRIX; index_t dim_max = 1; - value_t threshold = std::numeric_limits::infinity(); - - float ratio = 1; + value_t threshold = std::numeric_limits::max(); + float ratio = 1; #ifdef USE_COEFFICIENTS coefficient_t modulus = 2; @@ -1156,28 +1155,30 @@ int main(int argc, char** argv) { compressed_lower_distance_matrix dist = read_file(filename ? file_stream : std::cin, format); - std::cout << "distance matrix with " << dist.size() << " points" << std::endl; + value_t min = std::numeric_limits::infinity(), + max = -std::numeric_limits::infinity(), max_finite = max; + int num_edges = 0; - value_t min = std::numeric_limits::infinity(), max = -std::numeric_limits::infinity(); - - for (auto d: dist.distances) { - if (d != std::numeric_limits::infinity() ) { - min = std::min(min, d); - max = std::max(max, d); - } else { - threshold = std::min(threshold, std::numeric_limits::max()); - } + for (auto d : dist.distances) { + min = std::min(min, d); + max = std::max(max, d); + max_finite = d != std::numeric_limits::infinity() ? std::max(max, d) : max_finite; + if (d <= threshold) ++num_edges; } - - std::cout << "value range: [" << min << "," << max << "]" - << std::endl; - if (threshold == std::numeric_limits::infinity()) - ripser(std::move(dist), dim_max, threshold, ratio, modulus) - .compute_barcodes(); - else + std::cout << "value range: [" << min << "," << max_finite << "]" << std::endl; + + if (threshold >= max) { + std::cout << "distance matrix with " << dist.size() << " points" << std::endl; + ripser(std::move(dist), dim_max, threshold, ratio, + modulus) + .compute_barcodes(); + } else { + std::cout << "sparse distance matrix with " << dist.size() << " points and " << num_edges + << " entries" << std::endl; + ripser(sparse_distance_matrix(std::move(dist), threshold), dim_max, threshold, ratio, modulus) - .compute_barcodes(); - + .compute_barcodes(); + } } -- cgit v1.2.3 From a962f06a93df50941c813d187730b849b8fd84d6 Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Sun, 24 Sep 2017 19:16:35 +0200 Subject: pretty-print --- ripser.cpp | 190 +++++++++++++++++++++++++++++-------------------------------- 1 file changed, 91 insertions(+), 99 deletions(-) diff --git a/ripser.cpp b/ripser.cpp index 5acc32e..70a092a 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -146,7 +146,8 @@ public: diameter_entry_t(const diameter_index_t& _diameter_index, coefficient_t _coefficient) : std::pair(get_diameter(_diameter_index), make_entry(get_index(_diameter_index), _coefficient)) {} - diameter_entry_t(const diameter_index_t& _diameter_index) : diameter_entry_t(_diameter_index, 1) {} + diameter_entry_t(const diameter_index_t& _diameter_index) + : diameter_entry_t(_diameter_index, 1) {} }; const entry_t& get_entry(const diameter_entry_t& p) { return p.second; } @@ -249,10 +250,8 @@ public: euclidean_distance_matrix(std::vector>&& _points) : points(std::move(_points)) { - for (auto p: points) { - assert(p.size() == points.front().size()); - } - } + for (auto p : points) { assert(p.size() == points.front().size()); } + } value_t operator()(const index_t i, const index_t j) const { assert(i < points.size()); @@ -403,7 +402,8 @@ template class ripser { mutable std::vector::const_reverse_iterator> neighbor_end; public: - ripser(DistanceMatrix&& _dist, index_t _dim_max, value_t _threshold, float _ratio, coefficient_t _modulus) + ripser(DistanceMatrix&& _dist, index_t _dim_max, value_t _threshold, float _ratio, + coefficient_t _modulus) : dist(std::move(_dist)), n(dist.size()), dim_max(std::min(_dim_max, index_t(dist.size() - 2))), threshold(_threshold), ratio(_ratio), modulus(_modulus), binomial_coeff(n, dim_max + 2), @@ -459,29 +459,28 @@ public: class simplex_coboundary_enumerator; void assemble_columns_to_reduce(std::vector& simplices, - std::vector& columns_to_reduce, - hash_map& pivot_column_index, - index_t dim); - + std::vector& columns_to_reduce, + hash_map& pivot_column_index, index_t dim); + void compute_dim_0_pairs(std::vector& edges, - std::vector& columns_to_reduce) { + std::vector& columns_to_reduce) { union_find dset(n); - + edges = get_edges(); - + std::sort(edges.rbegin(), edges.rend(), - greater_diameter_or_smaller_index()); - + greater_diameter_or_smaller_index()); + #ifdef PRINT_PERSISTENCE_PAIRS std::cout << "persistence intervals in dim 0:" << std::endl; #endif - + std::vector vertices_of_edge(2); for (auto e : edges) { vertices_of_edge.clear(); get_simplex_vertices(get_index(e), 1, n, std::back_inserter(vertices_of_edge)); index_t u = dset.find(vertices_of_edge[0]), v = dset.find(vertices_of_edge[1]); - + if (u != v) { #ifdef PRINT_PERSISTENCE_PAIRS if (get_diameter(e) != 0) @@ -492,7 +491,7 @@ public: columns_to_reduce.push_back(e); } std::reverse(columns_to_reduce.begin(), columns_to_reduce.end()); - + #ifdef PRINT_PERSISTENCE_PAIRS for (index_t i = 0; i < n; ++i) if (dset.find(i) == i) std::cout << " [0, )" << std::endl << std::flush; @@ -629,7 +628,7 @@ public: found_persistence_pair: #ifdef PRINT_PERSISTENCE_PAIRS value_t death = get_diameter(pivot); - if ((float)death/diameter > ratio) { + if ((float)death / diameter > ratio) { #ifdef INDICATE_PROGRESS std::cout << "\033[K"; #endif @@ -677,31 +676,29 @@ public: } std::vector get_edges(); - + void compute_barcodes() { - + std::vector simplices, columns_to_reduce; - + compute_dim_0_pairs(simplices, columns_to_reduce); - + for (index_t dim = 1; dim <= dim_max; ++dim) { hash_map pivot_column_index; pivot_column_index.reserve(columns_to_reduce.size()); - + compute_pairs(columns_to_reduce, pivot_column_index, - dim); - + dim); + if (dim < dim_max) { assemble_columns_to_reduce(simplices, columns_to_reduce, pivot_column_index, - dim + 1); + dim + 1); } } } }; - -template <> -class ripser::simplex_coboundary_enumerator { +template <> class ripser::simplex_coboundary_enumerator { private: index_t idx_below, idx_above, v, k; std::vector vertices; @@ -709,16 +706,16 @@ private: const coefficient_t modulus; const compressed_lower_distance_matrix& dist; const binomial_coeff_table& binomial_coeff; - + public: simplex_coboundary_enumerator(const diameter_entry_t _simplex, index_t _dim, - const ripser& parent) - : idx_below(get_index(_simplex)), idx_above(0), v(parent.n - 1), k(_dim + 1), - vertices(_dim + 1), simplex(_simplex), modulus(parent.modulus), dist(parent.dist), - binomial_coeff(parent.binomial_coeff) { + const ripser& parent) + : idx_below(get_index(_simplex)), idx_above(0), v(parent.n - 1), k(_dim + 1), + vertices(_dim + 1), simplex(_simplex), modulus(parent.modulus), dist(parent.dist), + binomial_coeff(parent.binomial_coeff) { parent.get_simplex_vertices(get_index(_simplex), _dim, parent.n, vertices.begin()); } - + bool has_next() { while ((v != -1) && (binomial_coeff(v, k) <= idx_below)) { idx_below -= binomial_coeff(v, k); @@ -729,53 +726,52 @@ public: } return v != -1; } - + diameter_entry_t next() { value_t coface_diameter = get_diameter(simplex); for (index_t w : vertices) coface_diameter = std::max(coface_diameter, dist(v, w)); index_t coface_index = idx_above + binomial_coeff(v--, k + 1) + idx_below; coefficient_t coface_coefficient = - (k & 1 ? -1 + modulus : 1) * get_coefficient(simplex) % modulus; + (k & 1 ? -1 + modulus : 1) * get_coefficient(simplex) % modulus; return diameter_entry_t(coface_diameter, coface_index, coface_coefficient); } }; -template <> -class ripser::simplex_coboundary_enumerator { +template <> class ripser::simplex_coboundary_enumerator { private: const ripser& parent; - + index_t idx_below, idx_above, v, k, max_vertex_below; const diameter_entry_t simplex; const coefficient_t modulus; const sparse_distance_matrix& dist; const binomial_coeff_table& binomial_coeff; - + std::vector& vertices; std::vector::const_reverse_iterator>& neighbor_it; std::vector::const_reverse_iterator>& neighbor_end; diameter_index_t x; - + public: simplex_coboundary_enumerator(const diameter_entry_t _simplex, index_t _dim, - const ripser& _parent) - : parent(_parent), idx_below(get_index(_simplex)), idx_above(0), - v(parent.n - 1), k(_dim + 1), max_vertex_below(parent.n - 1), simplex(_simplex), modulus(parent.modulus), - dist(parent.dist), binomial_coeff(parent.binomial_coeff), vertices(parent.vertices), - neighbor_it(parent.neighbor_it), neighbor_end(parent.neighbor_end) { - + const ripser& _parent) + : parent(_parent), idx_below(get_index(_simplex)), idx_above(0), v(parent.n - 1), + k(_dim + 1), max_vertex_below(parent.n - 1), simplex(_simplex), modulus(parent.modulus), + dist(parent.dist), binomial_coeff(parent.binomial_coeff), vertices(parent.vertices), + neighbor_it(parent.neighbor_it), neighbor_end(parent.neighbor_end) { + neighbor_it.clear(); neighbor_end.clear(); vertices.clear(); - + parent.get_simplex_vertices(idx_below, _dim, parent.n, std::back_inserter(vertices)); - + for (auto v : vertices) { neighbor_it.push_back(dist.neighbors[v].rbegin()); neighbor_end.push_back(dist.neighbors[v].rend()); } } - + bool has_next(bool all_cofaces = true) { for (auto &it0 = neighbor_it[0], &end0 = neighbor_end[0]; it0 != end0; ++it0) { x = *it0; @@ -790,34 +786,33 @@ public: x = std::max(x, y); } return all_cofaces || - !(k > 0 && - parent.get_next_vertex(max_vertex_below, idx_below, k) > get_index(x)); + !(k > 0 && + parent.get_next_vertex(max_vertex_below, idx_below, k) > get_index(x)); continue_outer:; } return false; } - + diameter_entry_t next() { ++neighbor_it[0]; - + while (k > 0 && parent.get_next_vertex(max_vertex_below, idx_below, k) > get_index(x)) { idx_below -= binomial_coeff(max_vertex_below, k); idx_above += binomial_coeff(max_vertex_below, k + 1); --k; } - + value_t coface_diameter = std::max(get_diameter(simplex), get_diameter(x)); - + coefficient_t coface_coefficient = - (k & 1 ? -1 + modulus : 1) * get_coefficient(simplex) % modulus; - + (k & 1 ? -1 + modulus : 1) * get_coefficient(simplex) % modulus; + return diameter_entry_t(coface_diameter, - idx_above + binomial_coeff(get_index(x), k + 1) + idx_below, - coface_coefficient); + idx_above + binomial_coeff(get_index(x), k + 1) + idx_below, + coface_coefficient); } }; - template <> std::vector ripser::get_edges() { std::vector edges; for (index_t index = binomial_coeff(n, 2); index-- > 0;) { @@ -837,85 +832,82 @@ template <> std::vector ripser::get_ed return edges; } -template <> void ripser:: -assemble_columns_to_reduce(std::vector& simplices, - std::vector& columns_to_reduce, - hash_map& pivot_column_index, index_t dim) { +template <> +void ripser::assemble_columns_to_reduce( + std::vector& simplices, std::vector& columns_to_reduce, + hash_map& pivot_column_index, index_t dim) { index_t num_simplices = binomial_coeff(n, dim + 1); - + columns_to_reduce.clear(); - + #ifdef INDICATE_PROGRESS std::cout << "\033[K" - << "assembling " << num_simplices << " columns" << std::flush << "\r"; + << "assembling " << num_simplices << " columns" << std::flush << "\r"; #endif - + for (index_t index = 0; index < num_simplices; ++index) { if (pivot_column_index.find(index) == pivot_column_index.end()) { value_t diameter = compute_diameter(index, dim); - if (diameter <= threshold) - columns_to_reduce.push_back(std::make_pair(diameter, index)); + if (diameter <= threshold) columns_to_reduce.push_back(std::make_pair(diameter, index)); #ifdef INDICATE_PROGRESS if ((index + 1) % 1000000 == 0) std::cout << "\033[K" - << "assembled " << columns_to_reduce.size() << " out of " - << (index + 1) << "/" << num_simplices << " columns" << std::flush - << "\r"; + << "assembled " << columns_to_reduce.size() << " out of " << (index + 1) + << "/" << num_simplices << " columns" << std::flush << "\r"; #endif } } - + #ifdef INDICATE_PROGRESS std::cout << "\033[K" - << "sorting " << num_simplices << " columns" << std::flush << "\r"; + << "sorting " << num_simplices << " columns" << std::flush << "\r"; #endif - + std::sort(columns_to_reduce.begin(), columns_to_reduce.end(), - greater_diameter_or_smaller_index()); + greater_diameter_or_smaller_index()); #ifdef INDICATE_PROGRESS std::cout << "\033[K"; #endif } -template <> void ripser:: -assemble_columns_to_reduce(std::vector& simplices, - std::vector& columns_to_reduce, - hash_map& pivot_column_index, - index_t dim) { - +template <> +void ripser::assemble_columns_to_reduce( + std::vector& simplices, std::vector& columns_to_reduce, + hash_map& pivot_column_index, index_t dim) { + #ifdef INDICATE_PROGRESS std::cout << "\033[K" - << "assembling columns" << std::flush << "\r"; + << "assembling columns" << std::flush << "\r"; #endif - + --dim; columns_to_reduce.clear(); - + std::vector next_simplices; - + for (diameter_index_t simplex : simplices) { simplex_coboundary_enumerator cofaces(simplex, dim, *this); - + while (cofaces.has_next(false)) { auto coface = cofaces.next(); - + next_simplices.push_back(std::make_pair(get_diameter(coface), get_index(coface))); - + if (pivot_column_index.find(get_index(coface)) == pivot_column_index.end()) columns_to_reduce.push_back( - std::make_pair(get_diameter(coface), get_index(coface))); + std::make_pair(get_diameter(coface), get_index(coface))); } } - + simplices.swap(next_simplices); - + #ifdef INDICATE_PROGRESS std::cout << "\033[K" - << "sorting " << columns_to_reduce.size() << " columns" << std::flush << "\r"; + << "sorting " << columns_to_reduce.size() << " columns" << std::flush << "\r"; #endif - + std::sort(columns_to_reduce.begin(), columns_to_reduce.end(), - greater_diameter_or_smaller_index()); + greater_diameter_or_smaller_index()); #ifdef INDICATE_PROGRESS std::cout << "\033[K"; #endif -- cgit v1.2.3 From 23a262f1b59eacd7a3ef01589101e64290cd7128 Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Thu, 15 Feb 2018 11:00:13 +0100 Subject: threshold at enclosing radius --- ripser.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/ripser.cpp b/ripser.cpp index 70a092a..7858c55 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -785,9 +785,8 @@ public: else x = std::max(x, y); } - return all_cofaces || - !(k > 0 && - parent.get_next_vertex(max_vertex_below, idx_below, k) > get_index(x)); + return all_cofaces || !(k > 0 && parent.get_next_vertex(max_vertex_below, idx_below, + k) > get_index(x)); continue_outer:; } return false; @@ -1151,6 +1150,15 @@ int main(int argc, char** argv) { max = -std::numeric_limits::infinity(), max_finite = max; int num_edges = 0; + value_t enclosing_radius = std::numeric_limits::infinity(); + for (index_t i = 0; i < dist.size(); ++i) { + value_t r_i = -std::numeric_limits::infinity(); + for (index_t j = 0; j < dist.size(); ++j) r_i = std::max(r_i, dist(i, j)); + enclosing_radius = std::min(enclosing_radius, r_i); + } + + if (threshold == std::numeric_limits::max()) threshold = enclosing_radius; + for (auto d : dist.distances) { min = std::min(min, d); max = std::max(max, d); -- cgit v1.2.3 From 5a3afe81d365917ec64d2af7bf43d28df4b3b55c Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Thu, 12 Jul 2018 22:04:34 +0200 Subject: only compute enclosing radius when thresholding --- ripser.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/ripser.cpp b/ripser.cpp index d534f49..f012591 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -1157,14 +1157,16 @@ int main(int argc, char** argv) { max = -std::numeric_limits::infinity(), max_finite = max; int num_edges = 0; - value_t enclosing_radius = std::numeric_limits::infinity(); - for (index_t i = 0; i < dist.size(); ++i) { - value_t r_i = -std::numeric_limits::infinity(); - for (index_t j = 0; j < dist.size(); ++j) r_i = std::max(r_i, dist(i, j)); - enclosing_radius = std::min(enclosing_radius, r_i); - } + if (threshold == std::numeric_limits::max()) { + value_t enclosing_radius = std::numeric_limits::infinity(); + for (index_t i = 0; i < dist.size(); ++i) { + value_t r_i = -std::numeric_limits::infinity(); + for (index_t j = 0; j < dist.size(); ++j) r_i = std::max(r_i, dist(i, j)); + enclosing_radius = std::min(enclosing_radius, r_i); + } - if (threshold == std::numeric_limits::max()) threshold = enclosing_radius; + threshold = enclosing_radius; + } for (auto d : dist.distances) { min = std::min(min, d); @@ -1182,7 +1184,7 @@ int main(int argc, char** argv) { .compute_barcodes(); } else { std::cout << "sparse distance matrix with " << dist.size() << " points and " << num_edges - << " entries" << std::endl; + << "/" << (dist.size()*dist.size()-1)/2 << " entries" << std::endl; ripser(sparse_distance_matrix(std::move(dist), threshold), dim_max, threshold, ratio, modulus) -- cgit v1.2.3 From f0f5cad546e7d396c2402cd709cd9e68587aafcb Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Thu, 12 Jul 2018 22:04:44 +0200 Subject: updated readme --- README.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 4aae03d..73bbe59 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ # Ripser -Copyright © 2015–2016 [Ulrich Bauer]. +Copyright © 2015–2018 [Ulrich Bauer]. ### Description Ripser is a lean C++ code for the computation of Vietoris–Rips persistence barcodes. It can do just this one thing, but does it extremely well. -To see a live demo of Ripser's capabilities, go to [live.ripser.org]. The computation happens inside the browser (using [PNaCl] on Chrome and JavaScript via [Emscripten] on other browsers). +To see a live demo of Ripser's capabilities, go to [live.ripser.org]. The computation happens inside the browser (using [PNaCl] on Chrome and JavaScript via [Emscripten] on other browsers). The main features of Ripser: @@ -26,13 +26,14 @@ Input formats currently supported by Ripser: - [DIPHA] distance matrix data - point cloud data -Ripser's efficiency is based on a few important concepts and principles: +Ripser's efficiency is based on a few important concepts and principles, building on key previous and concurrent developments by other researchers in computational topology: - - Compute persistent *co*homology + - Compute persistent *co*homology (as suggested by [Vin de Silva, Dmitriy Morozov, and Mikael Vejdemo-Johansson](https://doi.org/10.1088/0266-5611/27/12/124003)) - Don't compute information that is never needed - (for the experts: employ the *clearing* optimization, aka *persistence with a twist*) - - Don't store information that can be readily recomputed - - Take obvious shortcuts (*apparent persistence pairs*) + (for the experts: employ the *clearing* optimization, aka *persistence with a twist*, as suggested by [Chao Chen and Michael Kerber](http://www.geometrie.tugraz.at/kerber/kerber_papers/ck-phcwat-11.pdf)) + - Don't store information that can be readily recomputed (in particular, the boundary matrix and the reduced boundary matrix) + - Take computational shortcuts (*apparent* and *emergent persistence pairs*) + - If no threshold is specified, choose the *enclosing radius* as the threshold, from which on homology is guaranteed to be trivial (as suggested by [Greg Henselman-Petrusek](https://github.com/Eetion/Eirene.jl)) ### Version -- cgit v1.2.3 From 22017ba657b7068fed2f1ff4f2d76413aa8fa1e7 Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Thu, 12 Jul 2018 22:13:54 +0200 Subject: xcode project update --- ripser.xcodeproj/project.pbxproj | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ripser.xcodeproj/project.pbxproj b/ripser.xcodeproj/project.pbxproj index b5f6881..60bb47a 100644 --- a/ripser.xcodeproj/project.pbxproj +++ b/ripser.xcodeproj/project.pbxproj @@ -88,7 +88,7 @@ 551018401BD63CB300990BFF /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0910; + LastUpgradeCheck = 0940; ORGANIZATIONNAME = "ulrich-bauer.org"; TargetAttributes = { 551018471BD63CB300990BFF = { @@ -129,7 +129,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; + CLANG_CXX_LANGUAGE_STANDARD = "c++14"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; @@ -137,12 +137,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -180,7 +182,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; + CLANG_CXX_LANGUAGE_STANDARD = "c++14"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; @@ -188,12 +190,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; -- cgit v1.2.3 From 2b64127e9d0e7d9739ce554591bc07eb3b73aa1a Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Sat, 11 Aug 2018 00:21:30 -0500 Subject: changed license to MIT --- COPYING.LESSER.txt | 165 ------------- COPYING.txt | 695 ++--------------------------------------------------- ripser.cpp | 49 ++-- 3 files changed, 55 insertions(+), 854 deletions(-) delete mode 100644 COPYING.LESSER.txt diff --git a/COPYING.LESSER.txt b/COPYING.LESSER.txt deleted file mode 100644 index 65c5ca8..0000000 --- a/COPYING.LESSER.txt +++ /dev/null @@ -1,165 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - - This version of the GNU Lesser General Public License incorporates -the terms and conditions of version 3 of the GNU General Public -License, supplemented by the additional permissions listed below. - - 0. Additional Definitions. - - As used herein, "this License" refers to version 3 of the GNU Lesser -General Public License, and the "GNU GPL" refers to version 3 of the GNU -General Public License. - - "The Library" refers to a covered work governed by this License, -other than an Application or a Combined Work as defined below. - - An "Application" is any work that makes use of an interface provided -by the Library, but which is not otherwise based on the Library. -Defining a subclass of a class defined by the Library is deemed a mode -of using an interface provided by the Library. - - A "Combined Work" is a work produced by combining or linking an -Application with the Library. The particular version of the Library -with which the Combined Work was made is also called the "Linked -Version". - - The "Minimal Corresponding Source" for a Combined Work means the -Corresponding Source for the Combined Work, excluding any source code -for portions of the Combined Work that, considered in isolation, are -based on the Application, and not on the Linked Version. - - The "Corresponding Application Code" for a Combined Work means the -object code and/or source code for the Application, including any data -and utility programs needed for reproducing the Combined Work from the -Application, but excluding the System Libraries of the Combined Work. - - 1. Exception to Section 3 of the GNU GPL. - - You may convey a covered work under sections 3 and 4 of this License -without being bound by section 3 of the GNU GPL. - - 2. Conveying Modified Versions. - - If you modify a copy of the Library, and, in your modifications, a -facility refers to a function or data to be supplied by an Application -that uses the facility (other than as an argument passed when the -facility is invoked), then you may convey a copy of the modified -version: - - a) under this License, provided that you make a good faith effort to - ensure that, in the event an Application does not supply the - function or data, the facility still operates, and performs - whatever part of its purpose remains meaningful, or - - b) under the GNU GPL, with none of the additional permissions of - this License applicable to that copy. - - 3. Object Code Incorporating Material from Library Header Files. - - The object code form of an Application may incorporate material from -a header file that is part of the Library. You may convey such object -code under terms of your choice, provided that, if the incorporated -material is not limited to numerical parameters, data structure -layouts and accessors, or small macros, inline functions and templates -(ten or fewer lines in length), you do both of the following: - - a) Give prominent notice with each copy of the object code that the - Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the object code with a copy of the GNU GPL and this license - document. - - 4. Combined Works. - - You may convey a Combined Work under terms of your choice that, -taken together, effectively do not restrict modification of the -portions of the Library contained in the Combined Work and reverse -engineering for debugging such modifications, if you also do each of -the following: - - a) Give prominent notice with each copy of the Combined Work that - the Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the Combined Work with a copy of the GNU GPL and this license - document. - - c) For a Combined Work that displays copyright notices during - execution, include the copyright notice for the Library among - these notices, as well as a reference directing the user to the - copies of the GNU GPL and this license document. - - d) Do one of the following: - - 0) Convey the Minimal Corresponding Source under the terms of this - License, and the Corresponding Application Code in a form - suitable for, and under terms that permit, the user to - recombine or relink the Application with a modified version of - the Linked Version to produce a modified Combined Work, in the - manner specified by section 6 of the GNU GPL for conveying - Corresponding Source. - - 1) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (a) uses at run time - a copy of the Library already present on the user's computer - system, and (b) will operate properly with a modified version - of the Library that is interface-compatible with the Linked - Version. - - e) Provide Installation Information, but only if you would otherwise - be required to provide such information under section 6 of the - GNU GPL, and only to the extent that such information is - necessary to install and execute a modified version of the - Combined Work produced by recombining or relinking the - Application with a modified version of the Linked Version. (If - you use option 4d0, the Installation Information must accompany - the Minimal Corresponding Source and Corresponding Application - Code. If you use option 4d1, you must provide the Installation - Information in the manner specified by section 6 of the GNU GPL - for conveying Corresponding Source.) - - 5. Combined Libraries. - - You may place library facilities that are a work based on the -Library side by side in a single library together with other library -facilities that are not Applications and are not covered by this -License, and convey such a combined library under terms of your -choice, if you do both of the following: - - a) Accompany the combined library with a copy of the same work based - on the Library, uncombined with any other library facilities, - conveyed under the terms of this License. - - b) Give prominent notice with the combined library that part of it - is a work based on the Library, and explaining where to find the - accompanying uncombined form of the same work. - - 6. Revised Versions of the GNU Lesser General Public License. - - The Free Software Foundation may publish revised and/or new versions -of the GNU Lesser General Public License from time to time. Such new -versions will be similar in spirit to the present version, but may -differ in detail to address new problems or concerns. - - Each version is given a distinguishing version number. If the -Library as you received it specifies that a certain numbered version -of the GNU Lesser General Public License "or any later version" -applies to it, you have the option of following the terms and -conditions either of that published version or of any later version -published by the Free Software Foundation. If the Library as you -received it does not specify a version number of the GNU Lesser -General Public License, you may choose any version of the GNU Lesser -General Public License ever published by the Free Software Foundation. - - If the Library as you received it specifies that a proxy can decide -whether future versions of the GNU Lesser General Public License shall -apply, that proxy's public statement of acceptance of any version is -permanent authorization for you to choose that version for the -Library. diff --git a/COPYING.txt b/COPYING.txt index 94a9ed0..e097aef 100644 --- a/COPYING.txt +++ b/COPYING.txt @@ -1,674 +1,21 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - 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 . - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - Copyright (C) - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. +MIT License + +Copyright (c) 2015–2018 Ulrich Bauer + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/ripser.cpp b/ripser.cpp index f012591..938cd7d 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -1,23 +1,42 @@ /* -Ripser: a lean C++ code for computation of Vietoris-Rips persistence barcodes - -Copyright 2015-2016 Ulrich Bauer. - -This program is free software: you can redistribute it and/or modify it under -the terms of the GNU Lesser General Public License as published by the -Free Software Foundation, either version 3 of the License, or (at your option) -any later version. - -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 Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License along -with this program. If not, see . + Ripser: a lean C++ code for computation of Vietoris-Rips persistence barcodes + + MIT License + + Copyright (c) 2015–2018 Ulrich Bauer + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + + You are under no obligation whatsoever to provide any bug fixes, patches, or + upgrades to the features, functionality or performance of the source code + ("Enhancements") to anyone; however, if you choose to make your Enhancements + available either publicly, or directly to the author of this software, without + imposing a separate written license agreement for such Enhancements, then you + hereby grant the following license: a non-exclusive, royalty-free perpetual + license to install, use, modify, prepare derivative works, incorporate into + other computer software, distribute, and sublicense such enhancements or + derivative works thereof, in binary and source code form. */ + //#define ASSEMBLE_REDUCTION_MATRIX //#define USE_COEFFICIENTS -- cgit v1.2.3 From 0103269b97b948ac95703e6645653ea45c3751fd Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Sat, 11 Aug 2018 00:24:31 -0500 Subject: changed license to MIT --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 73bbe59..6a7acf1 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ Prototype implementations are already avaliable; please contact the author if on ### License -Ripser is licensed under the [LGPL] 3.0. Please contact the author if you want to use Ripser in your software under a different license. +Ripser is licensed under the [MIT] license. Please contact the author if you want to use Ripser in your software under a different license. [Ulrich Bauer]: [live.ripser.org]: @@ -110,4 +110,4 @@ Ripser is licensed under the [LGPL] 3.0. Please contact the author if you want t [Perseus]: [GUDHI]: [sparsehash]: -[LGPL]: \ No newline at end of file +[MIT]: \ No newline at end of file -- cgit v1.2.3 From 5b13a77ba3c89a304ac9f3411c7121d38554a6c5 Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Tue, 28 Aug 2018 14:49:11 +0200 Subject: added and explained CONTRIBUTING.txt --- CONTRIBUTING.txt | 9 +++++++++ README.md | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 CONTRIBUTING.txt diff --git a/CONTRIBUTING.txt b/CONTRIBUTING.txt new file mode 100644 index 0000000..d17de40 --- /dev/null +++ b/CONTRIBUTING.txt @@ -0,0 +1,9 @@ +You are under no obligation whatsoever to provide any bug fixes, patches, or +upgrades to the features, functionality or performance of the source code +("Enhancements") to anyone; however, if you choose to make your Enhancements +available either publicly, or directly to the author of this software, without +imposing a separate written license agreement for such Enhancements, then you +hereby grant the following license: a non-exclusive, royalty-free perpetual +license to install, use, modify, prepare derivative works, incorporate into +other computer software, distribute, and sublicense such enhancements or +derivative works thereof, in binary and source code form. diff --git a/README.md b/README.md index 6a7acf1..cdf6db1 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ Prototype implementations are already avaliable; please contact the author if on ### License -Ripser is licensed under the [MIT] license. Please contact the author if you want to use Ripser in your software under a different license. +Ripser is licensed under the [MIT] license (`COPYING.txt`), with an extra clause (`CONTRIBUTING.txt`) clarifying the license for modifications released without an explicit written license agreement. Please contact the author if you want to use Ripser in your software under a different license. [Ulrich Bauer]: [live.ripser.org]: -- cgit v1.2.3 From 5b5ca047fd009d32a83ed7060ccb4772497c2566 Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Fri, 5 Oct 2018 14:54:17 +0200 Subject: sparse distance matrix file format --- ripser.cpp | 132 ++++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 92 insertions(+), 40 deletions(-) diff --git a/ripser.cpp b/ripser.cpp index 938cd7d..5158f23 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -214,14 +214,20 @@ public: class sparse_distance_matrix { public: std::vector> neighbors; + + index_t num_edges; + + sparse_distance_matrix(std::vector>&& _neighbors, index_t _num_edges) : neighbors(std::move(_neighbors)), num_edges(_num_edges) {} template - sparse_distance_matrix(const DistanceMatrix& mat, value_t threshold) : neighbors(mat.size()) { + sparse_distance_matrix(const DistanceMatrix& mat, value_t threshold) : neighbors(mat.size()), num_edges(0) { for (index_t i = 0; i < size(); ++i) for (index_t j = 0; j < size(); ++j) - if (i != j && mat(i, j) <= threshold) + if (i != j && mat(i, j) <= threshold) { + ++num_edges; neighbors[i].push_back(std::make_pair(mat(i, j), j)); + } } size_t size() const { return neighbors.size(); } @@ -944,6 +950,7 @@ enum file_format { DISTANCE_MATRIX, POINT_CLOUD, DIPHA, + SPARSE, RIPSER }; @@ -984,6 +991,38 @@ compressed_lower_distance_matrix read_point_cloud(std::istream& input_stream) { return compressed_lower_distance_matrix(std::move(distances)); } +sparse_distance_matrix read_sparse_distance_matrix(std::istream& input_stream) { + + std::vector> neighbors; + + index_t num_edges = 0; + + + std::string line; + while (std::getline(input_stream, line)) { + std::istringstream s(line); + size_t i, j; + value_t value; + s >> i; + s >> j; + s >> value; + if (i != j) { + neighbors.resize(std::max({neighbors.size(), i + 1, j + 1})); + neighbors[i].push_back(std::make_pair(value, j)); + neighbors[j].push_back(std::make_pair(value, i)); + ++num_edges; + } + } + + for (index_t i = 0; i < neighbors.size(); ++i) { + std::sort(neighbors[i].begin(), neighbors[i].end()); + auto last = std::unique(neighbors[i].begin(), neighbors[i].end()); + neighbors[i].erase(last, neighbors[i].end()); + } + + return sparse_distance_matrix(std::move(neighbors), num_edges); +} + compressed_lower_distance_matrix read_lower_distance_matrix(std::istream& input_stream) { std::vector distances; value_t value; @@ -1065,7 +1104,7 @@ compressed_lower_distance_matrix read_file(std::istream& input_stream, file_form return read_point_cloud(input_stream); case DIPHA: return read_dipha(input_stream); - case RIPSER: + default: return read_ripser(input_stream); } } @@ -1087,6 +1126,7 @@ void print_usage_and_exit(int exit_code) { << " distance (full distance matrix)" << std::endl << " point-cloud (point cloud in Euclidean space)" << std::endl << " dipha (distance matrix in DIPHA file format)" << std::endl + << " sparse (sparse distance matrix in Sparse Triplet Matrix file format)" << " ripser (distance matrix in Ripser binary file format)" << std::endl << " --dim compute persistent homology up to dimension " << std::endl @@ -1147,6 +1187,8 @@ int main(int argc, char** argv) { format = POINT_CLOUD; else if (parameter == "dipha") format = DIPHA; + else if (parameter == "sparse") + format = SPARSE; else if (parameter == "ripser") format = RIPSER; else @@ -1170,43 +1212,53 @@ int main(int argc, char** argv) { exit(-1); } - compressed_lower_distance_matrix dist = read_file(filename ? file_stream : std::cin, format); - - value_t min = std::numeric_limits::infinity(), - max = -std::numeric_limits::infinity(), max_finite = max; - int num_edges = 0; - - if (threshold == std::numeric_limits::max()) { - value_t enclosing_radius = std::numeric_limits::infinity(); - for (index_t i = 0; i < dist.size(); ++i) { - value_t r_i = -std::numeric_limits::infinity(); - for (index_t j = 0; j < dist.size(); ++j) r_i = std::max(r_i, dist(i, j)); - enclosing_radius = std::min(enclosing_radius, r_i); - } - - threshold = enclosing_radius; - } - - for (auto d : dist.distances) { - min = std::min(min, d); - max = std::max(max, d); - max_finite = d != std::numeric_limits::infinity() ? std::max(max, d) : max_finite; - if (d <= threshold) ++num_edges; - } - - std::cout << "value range: [" << min << "," << max_finite << "]" << std::endl; - - if (threshold >= max) { - std::cout << "distance matrix with " << dist.size() << " points" << std::endl; - ripser(std::move(dist), dim_max, threshold, ratio, - modulus) - .compute_barcodes(); + if (format == SPARSE) { + sparse_distance_matrix dist = read_sparse_distance_matrix(filename ? file_stream : std::cin); + std::cout << "sparse distance matrix with " << dist.size() << " points and " << dist.num_edges + << "/" << (dist.size()*(dist.size()-1))/2 << " entries" << std::endl; + + ripser(std::move(dist), dim_max, threshold, ratio, modulus) + .compute_barcodes(); } else { - std::cout << "sparse distance matrix with " << dist.size() << " points and " << num_edges - << "/" << (dist.size()*dist.size()-1)/2 << " entries" << std::endl; - - ripser(sparse_distance_matrix(std::move(dist), threshold), dim_max, - threshold, ratio, modulus) - .compute_barcodes(); + + compressed_lower_distance_matrix dist = read_file(filename ? file_stream : std::cin, format); + + value_t min = std::numeric_limits::infinity(), + max = -std::numeric_limits::infinity(), max_finite = max; + int num_edges = 0; + + if (threshold == std::numeric_limits::max()) { + value_t enclosing_radius = std::numeric_limits::infinity(); + for (index_t i = 0; i < dist.size(); ++i) { + value_t r_i = -std::numeric_limits::infinity(); + for (index_t j = 0; j < dist.size(); ++j) r_i = std::max(r_i, dist(i, j)); + enclosing_radius = std::min(enclosing_radius, r_i); + } + + threshold = enclosing_radius; + } + + for (auto d : dist.distances) { + min = std::min(min, d); + max = std::max(max, d); + max_finite = d != std::numeric_limits::infinity() ? std::max(max, d) : max_finite; + if (d <= threshold) ++num_edges; + } + + std::cout << "value range: [" << min << "," << max_finite << "]" << std::endl; + + if (threshold >= max) { + std::cout << "distance matrix with " << dist.size() << " points" << std::endl; + ripser(std::move(dist), dim_max, threshold, ratio, + modulus) + .compute_barcodes(); + } else { + std::cout << "sparse distance matrix with " << dist.size() << " points and " << num_edges + << "/" << (dist.size()*dist.size()-1)/2 << " entries" << std::endl; + + ripser(sparse_distance_matrix(std::move(dist), threshold), dim_max, + threshold, ratio, modulus) + .compute_barcodes(); + } } } -- cgit v1.2.3 From 00e252107d333ba963522867b58686128b5a22f0 Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Sat, 6 Oct 2018 12:29:50 +0200 Subject: fixed sparse distance matrix input --- ripser.cpp | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/ripser.cpp b/ripser.cpp index 5158f23..899062a 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -151,6 +151,10 @@ typedef std::pair diameter_index_t; value_t get_diameter(const diameter_index_t& i) { return i.first; } index_t get_index(const diameter_index_t& i) { return i.second; } +typedef std::pair index_diameter_t; +index_t get_index(const index_diameter_t& i) { return i.first; } +value_t get_diameter(const index_diameter_t& i) { return i.second; } + class diameter_entry_t : public std::pair { public: diameter_entry_t() {} @@ -213,11 +217,11 @@ public: class sparse_distance_matrix { public: - std::vector> neighbors; + std::vector> neighbors; index_t num_edges; - sparse_distance_matrix(std::vector>&& _neighbors, index_t _num_edges) : neighbors(std::move(_neighbors)), num_edges(_num_edges) {} + sparse_distance_matrix(std::vector>&& _neighbors, index_t _num_edges) : neighbors(std::move(_neighbors)), num_edges(_num_edges) {} template sparse_distance_matrix(const DistanceMatrix& mat, value_t threshold) : neighbors(mat.size()), num_edges(0) { @@ -226,7 +230,7 @@ public: for (index_t j = 0; j < size(); ++j) if (i != j && mat(i, j) <= threshold) { ++num_edges; - neighbors[i].push_back(std::make_pair(mat(i, j), j)); + neighbors[i].push_back(std::make_pair(j, mat(i, j))); } } @@ -405,8 +409,8 @@ template class ripser { const binomial_coeff_table binomial_coeff; std::vector multiplicative_inverse; mutable std::vector vertices; - mutable std::vector::const_reverse_iterator> neighbor_it; - mutable std::vector::const_reverse_iterator> neighbor_end; + mutable std::vector::const_reverse_iterator> neighbor_it; + mutable std::vector::const_reverse_iterator> neighbor_end; mutable std::vector coface_entries; public: @@ -780,9 +784,9 @@ private: const binomial_coeff_table& binomial_coeff; std::vector& vertices; - std::vector::const_reverse_iterator>& neighbor_it; - std::vector::const_reverse_iterator>& neighbor_end; - diameter_index_t x; + std::vector::const_reverse_iterator>& neighbor_it; + std::vector::const_reverse_iterator>& neighbor_end; + index_diameter_t x; public: simplex_coboundary_enumerator(const diameter_entry_t _simplex, index_t _dim, @@ -993,7 +997,7 @@ compressed_lower_distance_matrix read_point_cloud(std::istream& input_stream) { sparse_distance_matrix read_sparse_distance_matrix(std::istream& input_stream) { - std::vector> neighbors; + std::vector> neighbors; index_t num_edges = 0; @@ -1008,15 +1012,16 @@ sparse_distance_matrix read_sparse_distance_matrix(std::istream& input_stream) { s >> value; if (i != j) { neighbors.resize(std::max({neighbors.size(), i + 1, j + 1})); - neighbors[i].push_back(std::make_pair(value, j)); - neighbors[j].push_back(std::make_pair(value, i)); + neighbors[i].push_back(std::make_pair(j, value)); + neighbors[j].push_back(std::make_pair(i, value)); ++num_edges; } } for (index_t i = 0; i < neighbors.size(); ++i) { std::sort(neighbors[i].begin(), neighbors[i].end()); - auto last = std::unique(neighbors[i].begin(), neighbors[i].end()); + + auto last = std::unique(neighbors[i].begin(), neighbors[i].end(), [](const index_diameter_t& x, const index_diameter_t& y) { return get_index(x) == get_index(y); }); neighbors[i].erase(last, neighbors[i].end()); } -- cgit v1.2.3 From 2273fc17b34ad3efec7733febeb910ede6280b8e Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Sat, 6 Oct 2018 13:16:35 +0200 Subject: pretty print, clean up --- ripser.cpp | 86 +++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 48 insertions(+), 38 deletions(-) diff --git a/ripser.cpp b/ripser.cpp index 899062a..7fe1a4b 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -3,19 +3,19 @@ Ripser: a lean C++ code for computation of Vietoris-Rips persistence barcodes MIT License - + Copyright (c) 2015–2018 Ulrich Bauer - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -36,7 +36,6 @@ */ - //#define ASSEMBLE_REDUCTION_MATRIX //#define USE_COEFFICIENTS @@ -218,13 +217,16 @@ public: class sparse_distance_matrix { public: std::vector> neighbors; - + index_t num_edges; - sparse_distance_matrix(std::vector>&& _neighbors, index_t _num_edges) : neighbors(std::move(_neighbors)), num_edges(_num_edges) {} + sparse_distance_matrix(std::vector>&& _neighbors, + index_t _num_edges) + : neighbors(std::move(_neighbors)), num_edges(_num_edges) {} template - sparse_distance_matrix(const DistanceMatrix& mat, value_t threshold) : neighbors(mat.size()), num_edges(0) { + sparse_distance_matrix(const DistanceMatrix& mat, value_t threshold) + : neighbors(mat.size()), num_edges(0) { for (index_t i = 0; i < size(); ++i) for (index_t j = 0; j < size(); ++j) @@ -998,9 +1000,8 @@ compressed_lower_distance_matrix read_point_cloud(std::istream& input_stream) { sparse_distance_matrix read_sparse_distance_matrix(std::istream& input_stream) { std::vector> neighbors; - - index_t num_edges = 0; + index_t num_edges = 0; std::string line; while (std::getline(input_stream, line)) { @@ -1017,14 +1018,17 @@ sparse_distance_matrix read_sparse_distance_matrix(std::istream& input_stream) { ++num_edges; } } - + for (index_t i = 0; i < neighbors.size(); ++i) { std::sort(neighbors[i].begin(), neighbors[i].end()); - - auto last = std::unique(neighbors[i].begin(), neighbors[i].end(), [](const index_diameter_t& x, const index_diameter_t& y) { return get_index(x) == get_index(y); }); + + auto last = std::unique(neighbors[i].begin(), neighbors[i].end(), + [](const index_diameter_t& x, const index_diameter_t& y) { + return get_index(x) == get_index(y); + }); neighbors[i].erase(last, neighbors[i].end()); } - + return sparse_distance_matrix(std::move(neighbors), num_edges); } @@ -1131,7 +1135,8 @@ void print_usage_and_exit(int exit_code) { << " distance (full distance matrix)" << std::endl << " point-cloud (point cloud in Euclidean space)" << std::endl << " dipha (distance matrix in DIPHA file format)" << std::endl - << " sparse (sparse distance matrix in Sparse Triplet Matrix file format)" + << " sparse (sparse distance matrix in Sparse Triplet format)" + << std::endl << " ripser (distance matrix in Ripser binary file format)" << std::endl << " --dim compute persistent homology up to dimension " << std::endl @@ -1218,20 +1223,23 @@ int main(int argc, char** argv) { } if (format == SPARSE) { - sparse_distance_matrix dist = read_sparse_distance_matrix(filename ? file_stream : std::cin); - std::cout << "sparse distance matrix with " << dist.size() << " points and " << dist.num_edges - << "/" << (dist.size()*(dist.size()-1))/2 << " entries" << std::endl; - + sparse_distance_matrix dist = + read_sparse_distance_matrix(filename ? file_stream : std::cin); + std::cout << "sparse distance matrix with " << dist.size() << " points and " + << dist.num_edges << "/" << (dist.size() * (dist.size() - 1)) / 2 << " entries" + << std::endl; + ripser(std::move(dist), dim_max, threshold, ratio, modulus) - .compute_barcodes(); + .compute_barcodes(); } else { - - compressed_lower_distance_matrix dist = read_file(filename ? file_stream : std::cin, format); - + + compressed_lower_distance_matrix dist = + read_file(filename ? file_stream : std::cin, format); + value_t min = std::numeric_limits::infinity(), - max = -std::numeric_limits::infinity(), max_finite = max; + max = -std::numeric_limits::infinity(), max_finite = max; int num_edges = 0; - + if (threshold == std::numeric_limits::max()) { value_t enclosing_radius = std::numeric_limits::infinity(); for (index_t i = 0; i < dist.size(); ++i) { @@ -1239,31 +1247,33 @@ int main(int argc, char** argv) { for (index_t j = 0; j < dist.size(); ++j) r_i = std::max(r_i, dist(i, j)); enclosing_radius = std::min(enclosing_radius, r_i); } - + threshold = enclosing_radius; } - + for (auto d : dist.distances) { min = std::min(min, d); max = std::max(max, d); - max_finite = d != std::numeric_limits::infinity() ? std::max(max, d) : max_finite; + max_finite = + d != std::numeric_limits::infinity() ? std::max(max, d) : max_finite; if (d <= threshold) ++num_edges; } - + std::cout << "value range: [" << min << "," << max_finite << "]" << std::endl; - + if (threshold >= max) { std::cout << "distance matrix with " << dist.size() << " points" << std::endl; ripser(std::move(dist), dim_max, threshold, ratio, - modulus) - .compute_barcodes(); + modulus) + .compute_barcodes(); } else { - std::cout << "sparse distance matrix with " << dist.size() << " points and " << num_edges - << "/" << (dist.size()*dist.size()-1)/2 << " entries" << std::endl; - - ripser(sparse_distance_matrix(std::move(dist), threshold), dim_max, - threshold, ratio, modulus) - .compute_barcodes(); + std::cout << "sparse distance matrix with " << dist.size() << " points and " + << num_edges << "/" << (dist.size() * dist.size() - 1) / 2 << " entries" + << std::endl; + + ripser(sparse_distance_matrix(std::move(dist), threshold), + dim_max, threshold, ratio, modulus) + .compute_barcodes(); } } } -- cgit v1.2.3 From d3e1bae3779cfb500422b3018e098ebea089baa8 Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Sat, 6 Oct 2018 17:41:01 +0200 Subject: removed use of std::unique --- ripser.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/ripser.cpp b/ripser.cpp index 7fe1a4b..85c65e1 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -1019,16 +1019,9 @@ sparse_distance_matrix read_sparse_distance_matrix(std::istream& input_stream) { } } - for (index_t i = 0; i < neighbors.size(); ++i) { + for (index_t i = 0; i < neighbors.size(); ++i) std::sort(neighbors[i].begin(), neighbors[i].end()); - auto last = std::unique(neighbors[i].begin(), neighbors[i].end(), - [](const index_diameter_t& x, const index_diameter_t& y) { - return get_index(x) == get_index(y); - }); - neighbors[i].erase(last, neighbors[i].end()); - } - return sparse_distance_matrix(std::move(neighbors), num_edges); } -- cgit v1.2.3 From 4879faf147e96923952b248ed2552c10eb1e809c Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Wed, 22 May 2019 20:13:04 +0200 Subject: assemble reduction matrix per default --- Makefile | 10 ++-------- ripser.cpp | 4 ++-- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 893d776..4967c0d 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ build: ripser -all: ripser ripser-coeff ripser-reduction ripser-coeff-reduction ripser-debug +all: ripser ripser-coeff ripser-debug ripser: ripser.cpp @@ -10,15 +10,9 @@ ripser: ripser.cpp ripser-coeff: ripser.cpp c++ -std=c++11 ripser.cpp -o ripser-coeff -Ofast -D NDEBUG -D USE_COEFFICIENTS -ripser-reduction: ripser.cpp - c++ -std=c++11 ripser.cpp -o ripser-reduction -Ofast -D NDEBUG -D ASSEMBLE_REDUCTION_MATRIX - -ripser-coeff-reduction: ripser.cpp - c++ -std=c++11 ripser.cpp -o ripser-coeff-reduction -Ofast -D NDEBUG -D USE_COEFFICIENTS -D ASSEMBLE_REDUCTION_MATRIX - ripser-debug: ripser.cpp c++ -std=c++11 ripser.cpp -o ripser-debug -g clean: - rm -f ripser ripser-coeff ripser-reduction ripser-coeff-reduction ripser-debug + rm -f ripser ripser-coeff ripser-debug diff --git a/ripser.cpp b/ripser.cpp index 85c65e1..0308d46 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -4,7 +4,7 @@ MIT License - Copyright (c) 2015–2018 Ulrich Bauer + Copyright (c) 2015–2019 Ulrich Bauer Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -36,7 +36,7 @@ */ -//#define ASSEMBLE_REDUCTION_MATRIX +#define ASSEMBLE_REDUCTION_MATRIX //#define USE_COEFFICIENTS //#define INDICATE_PROGRESS -- cgit v1.2.3 From 2623d262762fed4c8db15b034f5881fc9fa9813d Mon Sep 17 00:00:00 2001 From: Ulrich Bauer Date: Wed, 22 May 2019 20:13:17 +0200 Subject: updated readme --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index cdf6db1..c8f82cc 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Currently, Ripser outperforms other codes ([Dionysus], [DIPHA], [GUDHI], [Perseu Input formats currently supported by Ripser: - - comma-separated values lower triangular distance matrix (preferred) + - comma-separated values lower triangular distance matrix - comma-separated values upper triangular distance matrix (MATLAB output from the function `pdist`) - comma-separated values full distance matrix - [DIPHA] distance matrix data @@ -73,14 +73,14 @@ A Makefile is provided with some variants of the above options. Use `make all` t The input is given either in a file whose name is passed as an argument, or through stdin. The following options are supported at the command line: - `--format`: use the specified file format for the input. The following formats are supported: - - `lower-distance` (default if no format is specified): lower triangular distance matrix; a comma (or whitespace, or other non-numerical character) separated list of the distance matrix entries below the diagonal, sorted lexicographically by row index, then column index - - `upper-distance`: upper triangular distance matrix; similar to the previous, but for the entries above the diagonal; suitable for output from the MATLAB functions `pdist` or `seqpdist`, exported to a CSV file - - `distance`: full distance matrix; similar to the above, but for all entries of the distance matrix - - `dipha`: DIPHA distance matrix as described on the [DIPHA] website - - `point-cloud`: point cloud; a comma (or whitespace, or other non-numerical character) separated list of coordinates of the points in some Euclidean space, one point per line - - `--dim k`: compute persistent homology up to dimension *k* - - `--threshold t`: compute Rips complexes up to diameter *t* - - `--modulus p`: compute homology with coefficients in the prime field Z/*p*Z (only available when built with the option `USE_COEFFICIENTS`) + - `lower-distance` (default if no format is specified): lower triangular distance matrix; a comma (or whitespace, or other non-numerical character) separated list of the distance matrix entries below the diagonal, sorted lexicographically by row index, then column index. + - `upper-distance`: upper triangular distance matrix; similar to the previous, but for the entries above the diagonal; suitable for output from the MATLAB functions `pdist` or `seqpdist`, exported to a CSV file. + - `distance`: full distance matrix; similar to the above, but for all entries of the distance matrix. One line per row of the matrix; only the part below the diagonal is actually read. + - `dipha`: DIPHA distance matrix as described on the [DIPHA] website. + - `point-cloud`: point cloud; a comma (or whitespace, or other non-numerical character) separated list of coordinates of the points in some Euclidean space, one point per line. + - `--dim k`: compute persistent homology up to dimension *k*. + - `--threshold t`: compute Rips complexes up to diameter *t*. + - `--modulus p`: compute homology with coefficients in the prime field Z/*p*Z (only available when built with the option `USE_COEFFICIENTS`). -- cgit v1.2.3