class persistence_TestSuite: public Test::Suite {
private:
- typedef simplicial_complex<3, uint32_t, double> scomplex;
- typedef persistence<3, uint32_t, double> pers;
+ typedef simplicial_function<3, uint32_t, uint32_t> sfunction;
+ typedef sfunction::scomplex scomplex;
+ typedef persistence<3, uint32_t> pers;
typedef pers::boundary_matrix bm;
typedef pers::lowestones_matrix lom;
typedef pers::transformation_matrix tm;
TEST_ADD(persistence_TestSuite::test_betti_numbers);
TEST_ADD(persistence_TestSuite::test_lowestones);
TEST_ADD(persistence_TestSuite::test_diagram);
+ TEST_ADD(persistence_TestSuite::test_diagrampoint_value);
}
protected:
// 9
scomplex::simplex ssring[] = {
- // dimension, faces, value...
- /* 1 */ {0, {}, 1},
- /* 2 */ {0, {}, 2},
- /* 3 */ {0, {}, 3},
- /* 4 */ {0, {}, 4},
- /* 5 */ {0, {}, 5},
- /* 6 */ {0, {}, 6},
- /* 7 */ {1, {2, 3}, 6.01},
- /* 8 */ {1, {3, 1}, 6.02},
- /* 9 */ {1, {1, 2}, 6.03},
- /* 10 */ {1, {4, 5}, 6.04},
- /* 11 */ {1, {5, 6}, 6.05},
- /* 12 */ {1, {6, 4}, 6.06},
- /* 13 */ {1, {1, 4}, 6.07},
- /* 14 */ {1, {1, 5}, 6.08},
- /* 15 */ {2, {13, 14, 10}, 6.0801},
- /* 16 */ {1, {3, 6}, 6.09},
- /* 17 */ {1, {2, 5}, 6.10},
- /* 18 */ {1, {2, 6}, 6.11},
- /* 19 */ {2, {9, 14, 17}, 6.1101},
- /* 20 */ {2, {7, 16, 18}, 6.1102},
- /* 21 */ {2, {11, 17, 18}, 6.1103},
- /* 22 */ {1, {3, 4}, 6.12},
- /* 23 */ {2, {12, 16, 22}, 6.1201},
- /* 24 */ {2, {8, 13, 22}, 6.1202}
+ // dimension, faces
+ /* 1 */ {0, {}},
+ /* 2 */ {0, {}},
+ /* 3 */ {0, {}},
+ /* 4 */ {0, {}},
+ /* 5 */ {0, {}},
+ /* 6 */ {0, {}},
+ /* 7 */ {1, {2, 3}},
+ /* 8 */ {1, {3, 1}},
+ /* 9 */ {1, {1, 2}},
+ /* 10 */ {1, {4, 5}},
+ /* 11 */ {1, {5, 6}},
+ /* 12 */ {1, {6, 4}},
+ /* 13 */ {1, {1, 4}},
+ /* 14 */ {1, {1, 5}},
+ /* 15 */ {2, {13, 14, 10}},
+ /* 16 */ {1, {3, 6}},
+ /* 17 */ {1, {2, 5}},
+ /* 18 */ {1, {2, 6}},
+ /* 19 */ {2, {9, 14, 17}},
+ /* 20 */ {2, {7, 16, 18}},
+ /* 21 */ {2, {11, 17, 18}},
+ /* 22 */ {1, {3, 4}},
+ /* 23 */ {2, {12, 16, 22}},
+ /* 24 */ {2, {8, 13, 22}},
};
const size_t cntssring = sizeof(ssring)/sizeof(scomplex::simplex);
ring.add_simplices(ssring, cntssring);
oring.reset();
scomplex::simplex sstorus[] = {
- // dimension, faces, value...
- /* 25 */ {0, {}, 7},
- /* 26 */ {0, {}, 8},
- /* 27 */ {0, {}, 9},
- /* 28 */ {1, {25, 26}, 9.01},
- /* 29 */ {1, {26, 27}, 9.02},
- /* 30 */ {1, {25, 27}, 9.03},
- /* 31 */ {1, {25, 1}, 9.04},
- /* 32 */ {1, {26, 1}, 9.05},
- /* 33 */ {2, {28, 31, 32}, 9.0501},
- /* 34 */ {1, {27, 1}, 9.06},
- /* 35 */ {2, {30, 31, 34}, 9.0601},
- /* 36 */ {1, {27, 3}, 9.07},
- /* 37 */ {2, {36, 34, 8}, 9.0701},
- /* 38 */ {1, {27, 2}, 9.08},
- /* 39 */ {1, {26, 2}, 9.09},
- /* 40 */ {2, {9, 32, 39}, 9.0901},
- /* 41 */ {2, {29, 38, 39}, 9.0902},
- /* 42 */ {2, {7, 38, 36}, 9.0903},
- /* 43 */ {1, {4, 25}, 9.10},
- /* 44 */ {1, {5, 26}, 9.11},
- /* 45 */ {1, {6, 27}, 9.12},
- /* 46 */ {1, {4, 26}, 9.13},
- /* 47 */ {1, {4, 27}, 9.14},
- /* 48 */ {1, {5, 27}, 9.15},
- /* 49 */ {2, {43, 47, 30}, 9.1501},
- /* 50 */ {2, {12, 45, 47}, 9.1502},
- /* 51 */ {2, {29, 44, 48}, 9.1503},
- /* 52 */ {2, {48, 11, 45}, 9.1504},
- /* 53 */ {2, {10, 46, 44}, 9.1505},
- /* 54 */ {2, {43, 46, 28}, 9.1506},
+ // dimension, faces
+ /* 25 */ {0, {}},
+ /* 26 */ {0, {}},
+ /* 27 */ {0, {}},
+ /* 28 */ {1, {25, 26}},
+ /* 29 */ {1, {26, 27}},
+ /* 30 */ {1, {25, 27}},
+ /* 31 */ {1, {25, 1}},
+ /* 32 */ {1, {26, 1}},
+ /* 33 */ {2, {28, 31, 32}},
+ /* 34 */ {1, {27, 1}},
+ /* 35 */ {2, {30, 31, 34}},
+ /* 36 */ {1, {27, 3}},
+ /* 37 */ {2, {36, 34, 8}},
+ /* 38 */ {1, {27, 2}},
+ /* 39 */ {1, {26, 2}},
+ /* 40 */ {2, {9, 32, 39}},
+ /* 41 */ {2, {29, 38, 39}},
+ /* 42 */ {2, {7, 38, 36}},
+ /* 43 */ {1, {4, 25}},
+ /* 44 */ {1, {5, 26}},
+ /* 45 */ {1, {6, 27}},
+ /* 46 */ {1, {4, 26}},
+ /* 47 */ {1, {4, 27}},
+ /* 48 */ {1, {5, 27}},
+ /* 49 */ {2, {43, 47, 30}},
+ /* 50 */ {2, {12, 45, 47}},
+ /* 51 */ {2, {29, 44, 48}},
+ /* 52 */ {2, {48, 11, 45}},
+ /* 53 */ {2, {10, 46, 44}},
+ /* 54 */ {2, {43, 46, 28}},
};
const size_t cntsstorus = sizeof(sstorus)/sizeof(scomplex::simplex);
torus = ring;
otorus.reset();
scomplex::simplex ssball[] = {
- // dimension, faces, value...
- {0, {}, 1},
- {0, {}, 2},
- {0, {}, 3},
- {0, {}, 4},
- {0, {}, 5},
- {1, {1, 2}, 6},
- {1, {2, 3}, 7},
- {1, {3, 4}, 8},
- {1, {4, 1}, 9},
- {1, {1, 5}, 10},
- {1, {2, 5}, 11},
- {1, {3, 5}, 12},
- {1, {4, 5}, 13},
- {2, {6, 10, 11}, 14},
- {2, {7, 11, 12}, 15},
- {2, {8, 12, 13}, 16},
- {2, {9, 13, 10}, 17},
- {1, {1, 3}, 18},
- {2, {18, 6, 7}, 19},
- {2, {18, 8, 9}, 20},
- {2, {18, 10, 12}, 21},
- {3, {21, 14, 15, 19}, 22},
- {3, {21, 16, 17, 20}, 23},
+ // dimension, faces
+ {0, {}},
+ {0, {}},
+ {0, {}},
+ {0, {}},
+ {0, {}},
+ {1, {1, 2}},
+ {1, {2, 3}},
+ {1, {3, 4}},
+ {1, {4, 1}},
+ {1, {1, 5}},
+ {1, {2, 5}},
+ {1, {3, 5}},
+ {1, {4, 5}},
+ {2, {6, 10, 11}},
+ {2, {7, 11, 12}},
+ {2, {8, 12, 13}},
+ {2, {9, 13, 10}},
+ {1, {1, 3}},
+ {2, {18, 6, 7}},
+ {2, {18, 8, 9}},
+ {2, {18, 10, 12}},
+ {3, {21, 14, 15, 19}},
+ {3, {21, 16, 17, 20}},
};
const size_t cntssball = sizeof(ssball)/sizeof(scomplex::simplex);
ball.add_simplices(ssball, cntssball);
lom ballloe(ballloe_coords, ballloe_coords + sizeof(ballloe_coords)/sizeof(uint32_t));
TEST_ASSERT(ballloe == balllo);
- //std::cout << std::endl;
- //ballp.interpret_reduction(std::cout);
- //torusp.compute_diagrams();
- //torusp.interpret_reduction(std::cout);
- //torusp.interpret_persistence(std::cout);
- //std::cout << std::endl;
- //std::cout << std::endl;
+#if 0
+ sfunction ftorus(torus);
+ ftorus.make_complete();
+ for (unsigned i=1; i < torus.size(); ++i)
+ ftorus.set_value(i, i);
+
+ std::cout << std::endl;
+ ballp.interpret_reduction(std::cout);
+ torusp.compute_diagrams();
+ torusp.interpret_reduction(std::cout, &ftorus);
+ torusp.interpret_persistence(std::cout, &ftorus);
+ std::cout << std::endl;
+ std::cout << std::endl;
+#endif
+ }
+
+ void test_diagrampoint_value() {
+ pers torusp(otorus);
+ torusp.compute_diagrams();
+
+ // We make a simplicial function that assigns to each simplex twice
+ // the index as value.
+ sfunction ftorus(torus);
+ ftorus.make_complete();
+ for (unsigned i=1; i < torus.size(); ++i)
+ ftorus.set_value(i, 2*i);
+
+ for (unsigned d=0; d <= 3; ++d) {
+ const pers::diagram &dia = torusp.get_persistence_diagram(d);
+ for (unsigned i=0; i < dia.births.size(); ++i) {
+ TEST_ASSERT(2 * dia.births[i].birth == dia.births[i].get_birth_value(otorus, ftorus));
+ TEST_ASSERT(2 * dia.births[i].death == dia.births[i].get_death_value(otorus, ftorus));
+ TEST_ASSERT(2 * (dia.births[i].death - dia.births[i].birth) ==
+ dia.births[i].get_persistence(otorus, ftorus));
+ }
+ }
}
void test_betti_numbers() {