1 #include <utilities/log.h>
3 #include "topology/simplex.h"
4 #include "topology/filtration.h"
5 #include "topology/static-persistence.h"
6 #include "topology/dynamic-persistence.h"
7 #include "topology/persistence-diagram.h"
8 #include <utilities/indirect.h>
17 #include <boost/archive/text_oarchive.hpp>
18 #include <boost/archive/text_iarchive.hpp>
19 #include <boost/serialization/vector.hpp>
22 typedef unsigned Vertex;
23 typedef Simplex<Vertex, double> Smplx;
24 typedef Filtration<Smplx> Fltr;
25 // typedef StaticPersistence<> Persistence;
26 typedef DynamicPersistenceTrails<> Persistence;
27 typedef PersistenceDiagram<> PDgm;
28 typedef OffsetBeginMap<Persistence, Fltr,
29 Persistence::iterator,
30 Fltr::Index> PersistenceFiltrationMap;
31 typedef OffsetBeginMap<Fltr, Persistence,
33 Persistence::iterator> FiltrationPersistenceMap;
35 // Transposes elements of the filtration together with the
36 struct FiltrationTranspositionVisitor: public Persistence::TranspositionVisitor
38 typedef Persistence::iterator iterator;
40 FiltrationTranspositionVisitor(const Persistence& p,
43 void transpose(iterator i) { f_.transpose(f_.begin() + (i - p_.begin())); } 45 const Persistence& p_;
49 void fillTriangleSimplices(Fltr& c)
51 typedef std::vector<Vertex> VertexVector;
52 VertexVector vertices(4);
53 vertices[0] = 0; vertices[1] = 1; vertices[2] = 2;
56 VertexVector::const_iterator bg = vertices.begin();
57 VertexVector::const_iterator end = vertices.end();
58 c.push_back(Smplx(bg, bg + 1, 0)); // 0 = A
59 c.push_back(Smplx(bg + 1, bg + 2, 1)); // 1 = B
60 c.push_back(Smplx(bg + 2, bg + 3, 2)); // 2 = C
61 c.push_back(Smplx(bg, bg + 2, 2.5)); // AB
62 c.push_back(Smplx(bg + 1, bg + 3, 2.9)); // BC
63 c.push_back(Smplx(bg + 2, end, 3.5)); // CA
64 c.push_back(Smplx(bg, bg + 3, 5)); // ABC
67 int main(int argc, char** argv)
70 rlog::RLogInit(argc, argv);
72 stdoutLog.subscribeTo(RLOG_CHANNEL("topology/persistence")); 73 //stdoutLog.subscribeTo(RLOG_CHANNEL("topology/chain")); 74 //stdoutLog.subscribeTo(RLOG_CHANNEL("topology/vineyard")); 78 fillTriangleSimplices(f);
79 std::cout << "Simplices filled" << std::endl;
80 for (Fltr::Index cur = f.begin(); cur != f.end(); ++cur)
81 std::cout << " " << *cur << std::endl;
83 #if 1 // testing serialization of the Filtration (really Simplex)
85 std::ofstream ofs("complex"); 86 boost::archive::text_oarchive oa(ofs);
92 std::ifstream ifs("complex"); 93 boost::archive::text_iarchive ia(ifs);
98 f.sort(Smplx::DataComparison());
99 std::cout << "Filtration initialized" << std::endl;
100 std::cout << f << std::endl;
103 std::cout << "Persistence initialized" << std::endl;
106 std::cout << "Simplices paired" << std::endl;
108 Persistence::SimplexMap<Fltr> m = p.make_simplex_map(f);
109 std::map<Dimension, PDgm> dgms;
110 init_diagrams(dgms, p.begin(), p.end(),
111 evaluate_through_map(m, Smplx::DataEvaluator()),
112 evaluate_through_map(m, Smplx::DimensionExtractor()));
114 std::cout << 0 << std::endl << dgms[0] << std::endl;
115 std::cout << 1 << std::endl << dgms[1] << std::endl;
117 PersistenceFiltrationMap pfmap(p, f);
118 DimensionFunctor<PersistenceFiltrationMap, Fltr> dim(pfmap, f);
121 FiltrationPersistenceMap fpmap(f, p);
122 FiltrationTranspositionVisitor visitor(p, f);
124 std::cout << A << std::endl;
125 std::cout << "Transposing A: " << p.transpose(fpmap[f.find(A)], dim, visitor) << std::endl; // 1.2 unpaired
127 Smplx BC; BC.add(1); BC.add(2);
128 Smplx AB; AB.add(0); AB.add(1);
129 std::cout << BC << std::endl;
130 std::cout << p.transpose(fpmap[f.find(BC)], dim, visitor) << std::endl; // 3.1
131 // p.transpose(fpmap[f.find(BC)], dim, visitor);
132 std::cout << AB << std::endl;
133 std::cout << p.transpose(fpmap[f.find(AB)], dim, visitor) << std::endl; // 2.1
134 // p.transpose(fpmap[f.find(AB)], dim, visitor);
136 std::cout << p.transpose(p.begin(), dim, visitor) << std::endl; // transposition case 1.2 special
137 std::cout << p.transpose(boost::next(p.begin()), dim, visitor) << std::endl;
138 std::cout << p.transpose(boost::next(p.begin(),3), dim, visitor) << std::endl;