TTK
Loading...
Searching...
No Matches
MergeTreeTemporalReductionDecoding.h
Go to the documentation of this file.
1
19#pragma once
20
21// ttk common includes
22#include <Debug.h>
23
24#include <FTMTreeUtils.h>
25#include <MergeTreeBarycenter.h>
26#include <MergeTreeBase.h>
27#include <MergeTreeDistance.h>
28
29namespace ttk {
30
36 public MergeTreeBase {
37 protected:
39
40 public:
42
43 template <class dataType>
47 std::vector<std::tuple<ftm::idNode, ftm::idNode, double>> &matching) {
48 MergeTreeDistance mergeTreeDistance;
50 mergeTreeDistance.setEpsilonTree1(epsilonTree1_);
51 mergeTreeDistance.setEpsilonTree2(epsilonTree2_);
52 mergeTreeDistance.setEpsilon2Tree1(epsilon2Tree1_);
53 mergeTreeDistance.setEpsilon2Tree2(epsilon2Tree2_);
54 mergeTreeDistance.setEpsilon3Tree1(epsilon3Tree1_);
55 mergeTreeDistance.setEpsilon3Tree2(epsilon3Tree2_);
57 mergeTreeDistance.setParallelize(parallelize_);
60 mergeTreeDistance.setKeepSubtree(keepSubtree_);
61 mergeTreeDistance.setUseMinMaxPair(useMinMaxPair_);
62 mergeTreeDistance.setThreadNumber(this->threadNumber_);
63 mergeTreeDistance.setDistanceSquaredRoot(true); // squared root
64 mergeTreeDistance.setDebugLevel(2);
65 mergeTreeDistance.setPreprocess(false);
66 mergeTreeDistance.setPostprocess(false);
67 // mergeTreeDistance.setIsCalled(true);
68
69 dataType distance
70 = mergeTreeDistance.execute<dataType>(mTree1, mTree2, matching);
71
72 return distance;
73 }
74
75 template <class dataType>
78 std::vector<std::tuple<ftm::idNode, ftm::idNode, double>> matching;
79 return computeDistance<dataType>(mTree1, mTree2, matching);
80 }
81
82 template <class dataType>
85 double alpha) {
86 MergeTreeBarycenter mergeTreeBarycenter;
87 mergeTreeBarycenter.setAssignmentSolver(assignmentSolverID_);
88 mergeTreeBarycenter.setEpsilonTree1(epsilonTree1_);
89 mergeTreeBarycenter.setEpsilonTree2(epsilonTree2_);
90 mergeTreeBarycenter.setEpsilon2Tree1(epsilon2Tree1_);
91 mergeTreeBarycenter.setEpsilon2Tree2(epsilon2Tree2_);
92 mergeTreeBarycenter.setEpsilon3Tree1(epsilon3Tree1_);
93 mergeTreeBarycenter.setEpsilon3Tree2(epsilon3Tree2_);
95 mergeTreeBarycenter.setParallelize(parallelize_);
98 mergeTreeBarycenter.setKeepSubtree(keepSubtree_);
99 mergeTreeBarycenter.setUseMinMaxPair(useMinMaxPair_);
100 mergeTreeBarycenter.setThreadNumber(this->threadNumber_);
101 mergeTreeBarycenter.setAlpha(alpha);
102 mergeTreeBarycenter.setDebugLevel(2);
103 mergeTreeBarycenter.setPreprocess(false);
104 mergeTreeBarycenter.setPostprocess(false);
105 // mergeTreeBarycenter.setIsCalled(true);
106
107 std::vector<ftm::MergeTree<dataType>> intermediateTrees;
108 intermediateTrees.push_back(mTree1);
109 intermediateTrees.push_back(mTree2);
110 std::vector<std::vector<std::tuple<ftm::idNode, ftm::idNode, double>>>
111 outputMatchingBarycenter(2);
112 ftm::MergeTree<dataType> barycenter;
113 mergeTreeBarycenter.execute<dataType>(
114 intermediateTrees, outputMatchingBarycenter, barycenter);
115 return barycenter;
116 }
117
118 template <class dataType>
120 std::vector<ftm::MergeTree<dataType>> &mTrees,
121 std::vector<std::tuple<double, int, int, int, int>> &coefs,
122 std::vector<ftm::MergeTree<dataType>> &allMT,
123 std::vector<std::vector<std::tuple<ftm::idNode, ftm::idNode, double>>>
124 &allMatching) {
125 Timer t_tempSub;
126
127 // --- Preprocessing
128 treesNodeCorr_ = std::vector<std::vector<int>>(mTrees.size());
129 for(unsigned int i = 0; i < mTrees.size(); ++i) {
130 preprocessingPipeline<dataType>(
133 }
134 printTreesStats<dataType>(mTrees);
135
136 // --- Execute
137 distancesToKeyFrames_ = std::vector<double>(coefs.size() * 2);
138 int index = 0;
139 size_t cpt = 0;
140 while(cpt < coefs.size()) {
141 while(cpt < coefs.size() and std::get<2>(coefs[cpt]) <= index) {
142 double const alpha = std::get<0>(coefs[cpt]);
143 int const index1 = std::get<1>(coefs[cpt]);
144 int const index2 = std::get<2>(coefs[cpt]);
145 ftm::MergeTree<dataType> tree = computeBarycenter<dataType>(
146 mTrees[index1], mTrees[index2], alpha);
147 allMT.push_back(tree);
148 distancesToKeyFrames_[cpt * 2]
149 = computeDistance<dataType>(mTrees[index1], tree);
150 distancesToKeyFrames_[cpt * 2 + 1]
151 = computeDistance<dataType>(tree, mTrees[index2]);
152 ++cpt;
153 }
154 allMT.push_back(mTrees[index]);
155 ++index;
156 }
157
158 allMatching = std::vector<
159 std::vector<std::tuple<ftm::idNode, ftm::idNode, double>>>(allMT.size()
160 - 1);
161 finalDistances_ = std::vector<double>(allMT.size() - 1);
162 for(unsigned int i = 0; i < allMT.size() - 1; ++i)
164 = computeDistance<dataType>(allMT[i], allMT[i + 1], allMatching[i]);
165
166 // --- Postprocessing
167 for(unsigned int i = 0; i < allMT.size(); ++i)
168 postprocessingPipeline<dataType>(&(allMT[i].tree));
169 for(unsigned int i = 0; i < mTrees.size(); ++i)
170 postprocessingPipeline<dataType>(&(mTrees[i].tree));
171
172 // --- Print results
173 std::stringstream ss, ss2, ss3;
174 ss << "input size = " << mTrees.size();
175 printMsg(ss.str());
176 ss2 << "output size = " << allMT.size();
177 printMsg(ss2.str());
178 ss3 << "reconstructed : " << allMT.size() - mTrees.size();
179 printMsg(ss3.str());
180 printMsg("Decoding", 1, t_tempSub.getElapsedTime(), this->threadNumber_);
181 }
182
183 }; // MergeTreeTemporalReductionDecoding class
184
185} // namespace ttk
virtual int setThreadNumber(const int threadNumber)
Definition BaseClass.h:80
Minimalist debugging class.
Definition Debug.h:88
virtual int setDebugLevel(const int &debugLevel)
Definition Debug.cpp:147
void setPreprocess(bool preproc)
void setPostprocess(bool postproc)
void execute(std::vector< ftm::MergeTree< dataType > > &trees, std::vector< double > &alphas, std::vector< std::vector< std::tuple< ftm::idNode, ftm::idNode, double > > > &finalMatchings, ftm::MergeTree< dataType > &baryMergeTree, bool finalAsgnDoubleInput=false, bool finalAsgnFirstInput=true)
void setBranchDecomposition(bool useBD)
void setNormalizedWasserstein(bool normalizedWasserstein)
void setDistanceSquaredRoot(bool distanceSquaredRoot)
void setEpsilon3Tree1(double epsilon)
void setEpsilonTree1(double epsilon)
void setAssignmentSolver(int assignmentSolver)
void setEpsilon2Tree1(double epsilon)
void setEpsilonTree2(double epsilon)
void setPersistenceThreshold(double pt)
std::vector< std::vector< int > > treesNodeCorr_
void setEpsilon2Tree2(double epsilon)
void setKeepSubtree(bool keepSubtree)
void setUseMinMaxPair(bool useMinMaxPair)
void setEpsilon3Tree2(double epsilon)
void setParallelize(bool para)
void setPreprocess(bool preproc)
void setPostprocess(bool postproc)
dataType execute(ftm::MergeTree< dataType > &mTree1, ftm::MergeTree< dataType > &mTree2, std::vector< std::tuple< ftm::idNode, ftm::idNode, double > > &outputMatching)
dataType computeDistance(ftm::MergeTree< dataType > &mTree1, ftm::MergeTree< dataType > &mTree2)
dataType computeDistance(ftm::MergeTree< dataType > &mTree1, ftm::MergeTree< dataType > &mTree2, std::vector< std::tuple< ftm::idNode, ftm::idNode, double > > &matching)
void execute(std::vector< ftm::MergeTree< dataType > > &mTrees, std::vector< std::tuple< double, int, int, int, int > > &coefs, std::vector< ftm::MergeTree< dataType > > &allMT, std::vector< std::vector< std::tuple< ftm::idNode, ftm::idNode, double > > > &allMatching)
ftm::MergeTree< dataType > computeBarycenter(ftm::MergeTree< dataType > &mTree1, ftm::MergeTree< dataType > &mTree2, double alpha)
double getElapsedTime()
Definition Timer.h:15
The Topology ToolKit.
printMsg(debug::output::BOLD+" | | | | | . \\ | | (__| | / __/| |_| / __/|__ _|"+debug::output::ENDCOLOR, debug::Priority::PERFORMANCE, debug::LineMode::NEW, stream)