TTK
Loading...
Searching...
No Matches
MergeTreePrincipalGeodesicsBase.h
Go to the documentation of this file.
1
10
11#pragma once
12
14#include <cmath>
15
16#define POINTS_BELOW_DIAG_TOLERANCE 1e-4
17
18namespace ttk {
19
20 class MergeTreePrincipalGeodesicsBase : virtual public Debug,
22 protected:
23 // Filled by the algorithm
24 std::vector<std::vector<std::vector<double>>> vS_, v2s_, trees2Vs_,
26 std::vector<std::vector<double>> allTs_, allScaledTs_, allTreesTs_;
27 std::vector<std::vector<double>> branchesCorrelationMatrix_,
29 std::vector<std::vector<std::tuple<ftm::idNode, ftm::idNode, double>>>
31
32 public:
35 "MergeTreePrincipalGeodesicsBase"); // inherited from Debug: prefix will
36 // be printed at the beginning of
37 // every msg
38 }
39
40 //----------------------------------------------------------------------------
41 // Matching / Distance
42 //----------------------------------------------------------------------------
43 template <class dataType>
45 ftm::MergeTree<dataType> &barycenter,
46 std::vector<ftm::MergeTree<dataType>> &inputTrees,
47 std::vector<std::vector<double *>> &vS,
48 std::vector<std::vector<double *>> &v2s,
49 size_t vSize,
50 std::vector<std::vector<double>> &allTreesTs,
51 std::vector<double> &reconstructionErrors,
52 std::vector<std::vector<std::tuple<ftm::idNode, ftm::idNode, double>>>
53 &matchings,
54 bool transposeVector = true) {
55 reconstructionErrors.resize(inputTrees.size());
56 matchings.resize(inputTrees.size());
57 dataType reconstructionError = 0.0;
58#ifdef TTK_ENABLE_OPENMP
59#pragma omp parallel for schedule(dynamic) num_threads(this->threadNumber_) reduction(+:reconstructionError)
60#endif
61 for(unsigned int i = 0; i < inputTrees.size(); ++i) {
62 ftm::MergeTree<dataType> reconstructedTree;
63 getMultiInterpolation<dataType>(barycenter, vS, v2s, vSize,
64 allTreesTs[i], reconstructedTree,
65 transposeVector);
66 dataType error;
67 computeOneDistance<dataType>(
68 reconstructedTree, inputTrees[i], matchings[i], error, true);
69 reconstructionError += error / inputTrees.size();
70 reconstructionErrors[i] = error;
71 }
72 return reconstructionError;
73 }
74
75 template <class dataType>
77 ftm::MergeTree<dataType> &barycenter,
78 std::vector<ftm::MergeTree<dataType>> &inputTrees,
79 std::vector<std::vector<std::vector<double>>> &vS,
80 std::vector<std::vector<std::vector<double>>> &v2s,
81 std::vector<std::vector<double>> &allTreesTs,
82 std::vector<double> &reconstructionErrors) {
83 std::vector<std::vector<double *>> pVS, pV2s;
86 std::vector<std::vector<std::tuple<ftm::idNode, ftm::idNode, double>>>
87 matchings;
88 return computeReconstructionError(barycenter, inputTrees, pVS, pV2s,
89 vS[0].size(), allTreesTs,
90 reconstructionErrors, matchings, false);
91 }
92
93 template <class dataType>
95 ftm::MergeTree<dataType> &barycenter,
96 std::vector<ftm::MergeTree<dataType>> &inputTrees,
97 std::vector<std::vector<std::vector<double>>> &vS,
98 std::vector<std::vector<std::vector<double>>> &v2s,
99 std::vector<std::vector<double>> &allTreesTs) {
100 std::vector<double> reconstructionErrors;
102 barycenter, inputTrees, vS, v2s, allTreesTs, reconstructionErrors);
103 }
104
105 //----------------------------------------------------------------------------
106 // Interpolation
107 //----------------------------------------------------------------------------
108 double getGeodesicVectorMiddle(std::vector<double> &v,
109 std::vector<double> &v2) {
110 std::vector<double> vProj, v2Proj;
111 ttk::Geometry::addVectorsProjection(v, v2, vProj, v2Proj);
112
113 double alpha = 0.0;
114 int cptDivide = 0;
115 for(unsigned int i = 0; i < vProj.size(); ++i) {
116 if(std::abs(v2Proj[i]) < Geometry::pow(10.0, -DBL_DIG))
117 continue;
118 alpha += (vProj[i] / v2Proj[i]);
119 ++cptDivide;
120 }
121 alpha /= cptDivide;
122 double const m = alpha / (1 + alpha);
123 return m;
124 }
125
126 double getAdjustedTMax(double tMin, double m) {
127 if(std::isnan(m))
128 return tMin;
129 return (m - tMin) * (1 - m) / m + m;
130 }
131
132 double getAdjustedTMin(double tMax, double m) {
133 if(std::isnan(m))
134 return tMax;
135 return (m - tMax) * m / (1 - m) + m;
136 }
137
139 double newT, double m, double &tMin, double &tMax, bool updateTMin) {
140 if(updateTMin) {
141 tMin = std::max(newT, tMin);
142 auto adjustedTMax = getAdjustedTMax(newT, m);
143 if(adjustedTMax > tMin)
144 tMax = std::min(adjustedTMax, tMax);
145 } else {
146 tMax = std::min(newT, tMax);
147 auto adjustedTMin = getAdjustedTMin(newT, m);
148 if(adjustedTMin < tMax)
149 tMin = std::max(adjustedTMin, tMin);
150 }
151 }
152
153 template <class dataType>
154 bool adjustDiagonalT(dataType baryBirth,
155 dataType baryDeath,
156 ftm::idNode node,
157 std::vector<std::vector<double>> &vNew,
158 std::vector<std::vector<double>> &v2New,
159 double &tMin,
160 double &tMax) {
161 bool shortener = false;
162
163 // Compute V1 extremity
164 auto newBirthV1 = baryBirth - vNew[node][0];
165 auto newDeathV1 = baryDeath - vNew[node][1];
166
167 // Compute V2 extremity
168 auto newBirthV2 = baryBirth + v2New[node][0];
169 auto newDeathV2 = baryDeath + v2New[node][1];
170
171 // Adjust t and v
172 if(newBirthV1 > newDeathV1 and newBirthV2 > newDeathV2) {
173 shortener = true;
174
175 double const divisor
176 = (vNew[node][1] - vNew[node][0]) / (baryDeath - baryBirth);
177 vNew[node][0] /= divisor;
178 vNew[node][1] /= divisor;
179 double const divisor2
180 = (v2New[node][0] - v2New[node][1]) / (baryDeath - baryBirth);
181 v2New[node][0] /= divisor2;
182 v2New[node][1] /= divisor2;
183 } else if(newBirthV1 > newDeathV1 or newBirthV2 > newDeathV2) {
184 double const newT
185 = (baryDeath - vNew[node][1] - baryBirth + vNew[node][0])
186 / (vNew[node][0] + v2New[node][0]
187 - (vNew[node][1] + v2New[node][1]));
188 double const m = getGeodesicVectorMiddle(vNew[node], v2New[node]);
189 if(newBirthV1 > newDeathV1)
190 updateT(newT, m, tMin, tMax, true);
191 if(newBirthV2 > newDeathV2)
192 updateT(newT, m, tMin, tMax, false);
193 }
194
195 return shortener;
196 }
197
198 template <class dataType>
200 dataType baryBirth,
201 dataType baryDeath,
202 ftm::idNode node,
203 std::vector<std::vector<double>> &vNew,
204 std::vector<std::vector<double>> &v2New,
205 double &tMin,
206 double &tMax) {
207 bool shortener = false;
208
209 dataType birthParent = 0.0;
210 dataType deathParent = 1.0;
211
212 auto interpolant = [&](int i, double t) {
213 return -vNew[node][i] + t * (vNew[node][i] + v2New[node][i]);
214 };
215
216 // Compute V1 extremity
217 auto newBirthV1 = baryBirth + interpolant(0, tMin);
218 auto newDeathV1 = baryDeath + interpolant(1, tMin);
219 auto parentBirthV1 = 0.0;
220 auto parentDeathV1 = 1.0;
221
222 // Compute V2 extremity
223 auto newBirthV2 = baryBirth + interpolant(0, tMax);
224 auto newDeathV2 = baryDeath + interpolant(1, tMax);
225 auto parentBirthV2 = 0.0;
226 auto parentDeathV2 = 1.0;
227
228 //
229 bool const extremOutPathIn
230 = ((newDeathV1 > parentDeathV1 and not(newBirthV1 < parentBirthV1)
231 and not(newDeathV2 > parentDeathV2) and newBirthV2 < parentBirthV2)
232 or (not(newDeathV1 > parentDeathV1) and newBirthV1 < parentBirthV1
233 and newDeathV2 > parentDeathV2
234 and not(newBirthV2 < parentBirthV2)));
235
236 // --- Adjust V
237 // Both extremities outside and path outside
238 if(((newDeathV1 > parentDeathV1 and newDeathV2 > parentDeathV2)
239 or (newBirthV1 < parentBirthV1 and newBirthV2 < parentBirthV2))
240 and not(extremOutPathIn)) {
241 shortener = true;
242
243 // Shorten V1
244 double coef1 = 1.0;
245 if(newDeathV1 > parentDeathV1 and newBirthV1 < parentBirthV1)
246 if(newBirthV1 < newDeathV1)
247 coef1 = (parentBirthV1 - baryBirth) / interpolant(0, tMin);
248 else
249 coef1 = (parentDeathV1 - baryDeath) / interpolant(1, tMin);
250 else if(newBirthV1 < parentBirthV1)
251 coef1 = (parentBirthV1 - baryBirth) / interpolant(0, tMin);
252 else if(newDeathV1 > parentDeathV1)
253 coef1 = (parentDeathV1 - baryDeath) / interpolant(1, tMin);
254 vNew[node][0] *= coef1;
255 vNew[node][1] *= coef1;
256
257 // Shorten V2
258 double coef2 = 1.0;
259 if(newDeathV2 > parentDeathV2 and newBirthV2 < parentBirthV2)
260 if(newBirthV2 < newDeathV2)
261 coef2 = (parentBirthV2 - baryBirth) / interpolant(0, tMax);
262 else
263 coef2 = (parentDeathV2 - baryDeath) / interpolant(1, tMax);
264 else if(newBirthV2 < parentBirthV2)
265 coef2 = (parentBirthV2 - baryBirth) / interpolant(0, tMax);
266 else if(newDeathV2 > parentDeathV2)
267 coef2 = (parentDeathV2 - baryDeath) / interpolant(1, tMax);
268 v2New[node][0] *= coef2;
269 v2New[node][1] *= coef2;
270 }
271
272 // --- Adjust T
273 // One extremity outside or both extremities outside but path inside
274 if(((newDeathV1 > parentDeathV1 or newBirthV1 < parentBirthV1)
275 != (newDeathV2 > parentDeathV2 or newBirthV2 < parentBirthV2))
276 or extremOutPathIn) {
277 double const m = getGeodesicVectorMiddle(vNew[node], v2New[node]);
278 if(newDeathV1 > parentDeathV1 or newDeathV2 > parentDeathV2) {
279 double const newT = (deathParent - baryDeath + vNew[node][1])
280 / (vNew[node][1] + v2New[node][1]);
281 if(newDeathV1 > parentDeathV1)
282 updateT(newT, m, tMin, tMax, true);
283 if(newDeathV2 > parentDeathV2)
284 updateT(newT, m, tMin, tMax, false);
285 }
286 if(newBirthV1 < parentBirthV1 or newBirthV2 < parentBirthV2) {
287 double const newT = (birthParent - baryBirth + vNew[node][0])
288 / (vNew[node][0] + v2New[node][0]);
289 if(newBirthV1 < parentBirthV1)
290 updateT(newT, m, tMin, tMax, true);
291 if(newBirthV2 < parentBirthV2)
292 updateT(newT, m, tMin, tMax, false);
293 }
294 }
295
296 return shortener;
297 }
298
299 template <class dataType>
301 dataType death,
302 std::vector<std::vector<double>> &vNew,
303 std::vector<std::vector<double>> &v2New,
304 int i,
305 double t,
306 double tMin,
307 double tMax,
308 const std::string &msg,
309 std::stringstream &ssT) {
310 double const tNew = (t * (tMax - tMin) + tMin);
311 std::streamsize const sSize = std::cout.precision();
312 ssT << std::setprecision(12) << std::endl << msg << std::endl;
313 ssT << "interBirth : "
314 << birth - vNew[i][0] + tNew * (vNew[i][0] + v2New[i][0]) << " _ "
315 << "interDeath : "
316 << death - vNew[i][1] + tNew * (vNew[i][1] + v2New[i][1])
317 << std::endl;
318 ssT << "v : " << vNew[i][0] << " _ " << vNew[i][1] << std::endl;
319 ssT << "v2 : " << v2New[i][0] << " _ " << v2New[i][1] << std::endl;
320 ssT << "ts : " << tMin << " _ " << tMax << std::endl;
321 ssT << "t : " << t << " _ tNew : " << tNew << std::endl;
322 std::cout.precision(sSize);
323 }
324
325 template <class dataType>
327 std::vector<std::vector<double>> &v,
328 std::vector<std::vector<double>> &v2,
329 int i,
330 double t) {
331 ftm::FTMTree_MT *baryTree = &(barycenter.tree);
332 double tMin = 0.0, tMax = 1.0;
333
334 // - Get node information
335 auto birthDeath = baryTree->getBirthDeath<dataType>(i);
336 auto birth = std::get<0>(birthDeath);
337 auto death = std::get<1>(birthDeath);
338
339 // - Get parent information
340 auto parent = baryTree->getParentSafe(i);
341 auto parentBirthDeath = baryTree->getBirthDeath<dataType>(parent);
342 auto parentBirth = std::get<0>(parentBirthDeath);
343 auto parentDeath = std::get<1>(parentBirthDeath);
344
345 if(normalizedWasserstein_ and !baryTree->notNeedToNormalize(i)) {
346 birth = (birth - parentBirth) / (parentDeath - parentBirth);
347 death = (death - parentBirth) / (parentDeath - parentBirth);
348 }
349
350 // - Adjust Diagonal T
351 bool diagonalShortener
352 = adjustDiagonalT(birth, death, i, v, v2, tMin, tMax);
353
354 // - Adjust Nesting T
355 bool nestingShortener = false;
356 if(normalizedWasserstein_ and !baryTree->notNeedToNormalize(i)) {
357 nestingShortener
358 = adjustNestingT(barycenter, birth, death, i, v, v2, tMin, tMax);
359 }
360
361 // - Compute new t
362 double const tNew = t * (tMax - tMin) + tMin;
363
364 if(diagonalShortener or nestingShortener)
365 printWrn("[getTNew] shortener");
366
367 return tNew;
368 }
369
370 template <class dataType>
372 std::vector<double *> &v,
373 std::vector<double *> &v2,
374 size_t vSize,
375 double t,
376 std::vector<dataType> &interpolationVectorT,
377 bool transposeVector) {
378 // --- Init
379 ftm::FTMTree_MT *baryTree = &(barycenter.tree);
380 std::vector<dataType> scalarsVector;
381 ttk::ftm::getTreeScalars<dataType>(barycenter, scalarsVector);
382 std::vector<double> interpolationVector(scalarsVector.size());
383 std::vector<std::vector<double>> vNew, v2New;
384 pointersToVectors(v, vSize, vNew);
385 pointersToVectors(v2, vSize, v2New);
386 if(transposeVector) {
387 std::vector<std::vector<double>> out;
389 vNew = out;
391 v2New = out;
392 }
393
394 // --- Tree traversal
395 int cptBelowDiagonal = 0, cptNotNesting = 0;
396 std::queue<ftm::idNode> queue;
397 queue.emplace(baryTree->getRoot());
398 int noNestingShortener = 0, noDiagonalShortener = 0;
399 while(!queue.empty()) {
400 ftm::idNode const i = queue.front();
401 queue.pop();
402
403 // - Get node information
404 auto nodeBirthDeath = baryTree->getBirthDeathNode<dataType>(i);
405 auto nodeBirth = std::get<0>(nodeBirthDeath);
406 auto nodeDeath = std::get<1>(nodeBirthDeath);
407 auto birth = scalarsVector[nodeBirth];
408 auto death = scalarsVector[nodeDeath];
409
410 // - Get parent information
411 auto parent = baryTree->getParentSafe(i);
412 auto parentNodeBirthDeath
413 = baryTree->getBirthDeathNode<dataType>(parent);
414 auto parentNodeBirth = std::get<0>(parentNodeBirthDeath);
415 auto parentNodeDeath = std::get<1>(parentNodeBirthDeath);
416 auto parentBirth = scalarsVector[parentNodeBirth];
417 auto parentDeath = scalarsVector[parentNodeDeath];
418 auto interParentBirth = interpolationVector[parentNodeBirth];
419 auto interParentDeath = interpolationVector[parentNodeDeath];
420
421 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
422 std::stringstream ssT;
423 std::streamsize const sSize2 = std::cout.precision();
424 ssT << std::setprecision(12);
425 ssT << "info" << std::endl;
426 ssT << "birth death : " << birth << " ___ " << death << std::endl;
427 ssT << "par. birth death : " << parentBirth << " ___ " << parentDeath
428 << std::endl;
429 ssT << "par. inter birth death : " << interParentBirth << " ___ "
430 << interParentDeath << std::endl;
431
432 if(normalizedWasserstein_ and !baryTree->notNeedToNormalize(i)) {
433 birth = (birth - parentBirth) / (parentDeath - parentBirth);
434 death = (death - parentBirth) / (parentDeath - parentBirth);
435 ssT << "norm. birth death : " << birth << " ___ " << death
436 << std::endl;
437 }
438 std::cout.precision(sSize2);
439 // --------------------------------------------------------------------
440
441 // - Adjust tMin and tMax
442 double tMin = 0.0, tMax = 1.0;
443
444 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
445 getInterpolationVectorDebugMsg<dataType>(birth, death, vNew, v2New, i,
446 t, tMin, tMax,
447 "before adjustDiagonalT", ssT);
448 // --------------------------------------------------------------------
449
450 // - Adjust Diagonal T
451 bool const diagonalShortener
452 = adjustDiagonalT(birth, death, i, vNew, v2New, tMin, tMax);
453 noDiagonalShortener += diagonalShortener;
454
455 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
456 getInterpolationVectorDebugMsg<dataType>(
457 birth, death, vNew, v2New, i, t, tMin, tMax,
458 "after adjustDiagonalT/before adjustNestingT", ssT);
459 // --------------------------------------------------------------------
460
461 // - Adjust Nesting T
462 if(normalizedWasserstein_ and !baryTree->notNeedToNormalize(i)) {
463 bool const nestingShortener = adjustNestingT(
464 barycenter, birth, death, i, vNew, v2New, tMin, tMax);
465 noNestingShortener += nestingShortener;
466
467 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
468 getInterpolationVectorDebugMsg<dataType>(birth, death, vNew, v2New, i,
469 t, tMin, tMax,
470 "after adjustNestingT", ssT);
471 // ------------------------------------------------------------------
472 }
473
474 // - Compute interpolation
475 double const tNew = t * (tMax - tMin) + tMin;
476 double interBirth
477 = birth - vNew[i][0] + tNew * (vNew[i][0] + v2New[i][0]);
478 double interDeath
479 = death - vNew[i][1] + tNew * (vNew[i][1] + v2New[i][1]);
480 if(normalizedWasserstein_ and !baryTree->notNeedToNormalize(i)) {
481 double const coef = (interParentDeath - interParentBirth);
482 interBirth *= coef;
483 interBirth += interParentBirth;
484 interDeath *= coef;
485 interDeath += interParentBirth;
486 }
487 interpolationVector[nodeBirth] = interBirth;
488 interpolationVector[nodeDeath] = interDeath;
489
490 // - Verify NaN
491 if(std::isnan(interpolationVector[nodeBirth])
492 or std::isnan(interpolationVector[nodeDeath])) {
493 printMsg(ssT.str());
494 printErr("NOT A NUMBER");
495 }
496 // - Verify points below diagonal
497 double const eps = POINTS_BELOW_DIAG_TOLERANCE;
498 if(interpolationVector[nodeBirth] > interpolationVector[nodeDeath]
499 and interpolationVector[nodeBirth] - interpolationVector[nodeDeath]
500 < eps) {
501 interpolationVector[nodeBirth] = interpolationVector[nodeDeath];
502 }
503 if(interpolationVector[nodeBirth] > interpolationVector[nodeDeath]) {
504 ++cptBelowDiagonal;
505 printMsg(ssT.str());
506 std::streamsize const sSize = std::cout.precision();
507 std::stringstream ss;
508 ss << std::setprecision(12) << interpolationVector[nodeBirth] << " > "
509 << interpolationVector[nodeDeath];
510 printErr(ss.str());
511 std::cout.precision(sSize);
512 }
513 // - Verify nesting condition
514 bool const verifyNesting = !baryTree->notNeedToNormalize(i);
515 if(normalizedWasserstein_ and verifyNesting) {
516 if(interpolationVector[nodeBirth] < interParentBirth
517 and (interParentBirth - interpolationVector[nodeBirth]) < eps)
518 interpolationVector[nodeBirth] = interParentBirth;
519 if(interpolationVector[nodeBirth] > interParentDeath
520 and (interpolationVector[nodeBirth] - interParentDeath) < eps) {
521 interpolationVector[nodeBirth] = interParentDeath;
522 }
523 if(interpolationVector[nodeDeath] < interParentBirth
524 and (interParentBirth - interpolationVector[nodeDeath]) < eps) {
525 interpolationVector[nodeDeath] = interParentBirth;
526 }
527 if(interpolationVector[nodeDeath] > interParentDeath
528 and (interpolationVector[nodeDeath] - interParentDeath) < eps)
529 interpolationVector[nodeDeath] = interParentDeath;
530 }
531 if(normalizedWasserstein_ and verifyNesting
532 and (interpolationVector[nodeBirth] < interParentBirth
533 or interpolationVector[nodeBirth] > interParentDeath
534 or interpolationVector[nodeDeath] < interParentBirth
535 or interpolationVector[nodeDeath] > interParentDeath)) {
536 ++cptNotNesting;
537 printMsg(ssT.str());
538 std::streamsize const sSize = std::cout.precision();
539 std::stringstream ss;
540 ss << std::setprecision(12) << interpolationVector[nodeBirth] << " _ "
541 << interpolationVector[nodeDeath] << " --- " << interParentBirth
542 << " _ " << interParentDeath;
543 printErr(ss.str());
544 std::cout.precision(sSize);
545 }
546
547 // - Push children to the queue
548 std::vector<ftm::idNode> children;
549 baryTree->getChildren(i, children);
550 for(auto child : children)
551 queue.emplace(child);
552 }
553 if(noNestingShortener != 0)
554 printWrn("[getInterpolationVector] "
555 + std::to_string(noNestingShortener)
556 + " nesting vector shortener.");
557 if(noDiagonalShortener != 0)
558 printMsg("[getInterpolationVector] "
559 + std::to_string(noDiagonalShortener)
560 + " diagonal vector shortener.",
562 if(cptBelowDiagonal != 0)
563 printErr("[getInterpolationVector] point below diagonal.");
564 if(cptNotNesting != 0)
565 printErr("[getInterpolationVector] nesting condition not ok.");
566
567 interpolationVectorT.resize(scalarsVector.size());
568 for(unsigned int i = 0; i < interpolationVectorT.size(); ++i)
569 interpolationVectorT[i] = interpolationVector[i];
570 }
571
572 template <class dataType>
574 std::vector<double *> &v,
575 std::vector<double *> &v2,
576 size_t vSize,
577 double t,
578 ftm::MergeTree<dataType> &interpolated,
579 bool transposeVector = true) {
580 ftm::FTMTree_MT *barycenterTree = &(barycenter.tree);
581
582 // Compute new scalars vector
583 std::vector<dataType> newScalarsVector;
584 getInterpolationVector<dataType>(
585 barycenter, v, v2, vSize, t, newScalarsVector, transposeVector);
586
587 // Create new tree
588 interpolated
589 = ttk::ftm::createEmptyMergeTree<dataType>(newScalarsVector.size());
590 ttk::ftm::setTreeScalars<dataType>(interpolated, newScalarsVector);
591 ftm::FTMTree_MT *treeNew = &(interpolated.tree);
592
593 // Copy the barycenter tree structure
594 treeNew->copyMergeTreeStructure(barycenterTree);
595
596 // Delete diagonal and almost-diagonal points
597 persistenceThresholding<dataType>(treeNew, 0.001); // 0.001 %
598 }
599
600 template <class dataType>
602 std::vector<std::vector<double>> &v,
603 std::vector<std::vector<double>> &v2,
604 double t,
605 ftm::MergeTree<dataType> &interpolated) {
606 std::vector<double *> pV, pV2;
607 vectorsToPointers(v, pV);
608 vectorsToPointers(v2, pV2);
609 return getInterpolation<dataType>(
610 barycenter, pV, pV2, v[0].size(), t, interpolated, false);
611 }
612
613 template <class dataType>
615 std::vector<std::vector<double *>> &vS,
616 std::vector<std::vector<double *>> &v2s,
617 size_t vSize,
618 std::vector<double> &ts,
619 ftm::MergeTree<dataType> &interpolated,
620 bool transposeVector = true) {
621 getInterpolation<dataType>(
622 barycenter, vS[0], v2s[0], vSize, ts[0], interpolated, transposeVector);
623 for(unsigned int i = 1; i < vS.size(); ++i) {
624 ftm::MergeTree<dataType> newInterpolated;
625 getInterpolation<dataType>(interpolated, vS[i], v2s[i], vSize, ts[i],
626 newInterpolated, transposeVector);
627 interpolated = newInterpolated;
628 }
629 }
630
631 template <class dataType>
632 void
634 std::vector<std::vector<std::vector<double>>> &vS,
635 std::vector<std::vector<std::vector<double>>> &v2s,
636 std::vector<double> &ts,
637 ftm::MergeTree<dataType> &interpolated) {
638 std::vector<std::vector<double *>> pVS, pV2s;
640 vectorOfVectorsToPointers(v2s, pV2s);
642 barycenter, pVS, pV2s, vS[0][0].size(), ts, interpolated, false);
643 }
644
645 template <class dataType>
646 void
648 std::vector<std::vector<std::vector<double>>> &vS,
649 std::vector<std::vector<std::vector<double>>> &v2s,
650 std::vector<std::vector<double>> &v,
651 std::vector<std::vector<double>> &v2,
652 std::vector<double> &ts,
653 double t,
654 ftm::MergeTree<dataType> &interpolated) {
655 std::vector<std::vector<std::vector<double>>> vSTemp = vS, v2sTemp = v2s;
656 vSTemp.push_back(v);
657 v2sTemp.push_back(v2);
658 std::vector<double> tsTemp = ts;
659 if(tsTemp.size() != 0)
660 tsTemp[vSTemp.size() - 1] = t;
661 else
662 tsTemp.push_back(t);
663 getMultiInterpolation(barycenter, vSTemp, v2sTemp, tsTemp, interpolated);
664 }
665
666 // ----------------------------------------------------------------------------
667 // Vector Utils
668 // ----------------------------------------------------------------------------
669 void callGramSchmidt(std::vector<std::vector<double>> &vS,
670 std::vector<double> &v,
671 std::vector<double> &newV);
672
673 void vectorToPointer(std::vector<double> &vec, double *&pVec);
674
675 void vectorsToPointers(std::vector<std::vector<double>> &vec,
676 std::vector<double *> &pVec);
677
679 std::vector<std::vector<std::vector<double>>> &vS,
680 std::vector<std::vector<double *>> &pVS);
681
682 void pointerToVector(double *pVec, size_t size, std::vector<double> &vec);
683
684 void pointersToVectors(std::vector<double *> &pVec,
685 std::vector<size_t> sizes,
686 std::vector<std::vector<double>> &vec);
687
688 void pointersToVectors(std::vector<double *> &pVec,
689 size_t size,
690 std::vector<std::vector<double>> &vec);
691 }; // MergeTreePrincipalGeodesicsBase class
692
693} // namespace ttk
#define ttkNotUsed(x)
Mark function/method parameters that are not used in the function body at all.
Definition BaseClass.h:47
#define POINTS_BELOW_DIAG_TOLERANCE
Minimalist debugging class.
Definition Debug.h:88
int printWrn(const std::string &msg, const debug::LineMode &lineMode=debug::LineMode::NEW, std::ostream &stream=std::cerr) const
Definition Debug.h:159
void setDebugMsgPrefix(const std::string &prefix)
Definition Debug.h:364
int printErr(const std::string &msg, const debug::LineMode &lineMode=debug::LineMode::NEW, std::ostream &stream=std::cerr) const
Definition Debug.h:149
double getGeodesicVectorMiddle(std::vector< double > &v, std::vector< double > &v2)
dataType computeReconstructionError(ftm::MergeTree< dataType > &barycenter, std::vector< ftm::MergeTree< dataType > > &inputTrees, std::vector< std::vector< std::vector< double > > > &vS, std::vector< std::vector< std::vector< double > > > &v2s, std::vector< std::vector< double > > &allTreesTs)
void getInterpolationVectorDebugMsg(dataType birth, dataType death, std::vector< std::vector< double > > &vNew, std::vector< std::vector< double > > &v2New, int i, double t, double tMin, double tMax, const std::string &msg, std::stringstream &ssT)
std::vector< std::vector< double > > allTreesTs_
std::vector< std::vector< std::vector< double > > > v2s_
void vectorToPointer(std::vector< double > &vec, double *&pVec)
void pointersToVectors(std::vector< double * > &pVec, std::vector< size_t > sizes, std::vector< std::vector< double > > &vec)
double getTNew(ftm::MergeTree< dataType > &barycenter, std::vector< std::vector< double > > &v, std::vector< std::vector< double > > &v2, int i, double t)
std::vector< std::vector< std::vector< double > > > trees2V2s_
void getMultiInterpolation(ftm::MergeTree< dataType > &barycenter, std::vector< std::vector< double * > > &vS, std::vector< std::vector< double * > > &v2s, size_t vSize, std::vector< double > &ts, ftm::MergeTree< dataType > &interpolated, bool transposeVector=true)
std::vector< std::vector< std::vector< double > > > vS_
void getInterpolation(ftm::MergeTree< dataType > &barycenter, std::vector< double * > &v, std::vector< double * > &v2, size_t vSize, double t, ftm::MergeTree< dataType > &interpolated, bool transposeVector=true)
void vectorsToPointers(std::vector< std::vector< double > > &vec, std::vector< double * > &pVec)
bool adjustNestingT(ftm::MergeTree< dataType > &ttkNotUsed(barycenter), dataType baryBirth, dataType baryDeath, ftm::idNode node, std::vector< std::vector< double > > &vNew, std::vector< std::vector< double > > &v2New, double &tMin, double &tMax)
std::vector< std::vector< double > > allTs_
std::vector< std::vector< double > > branchesCorrelationMatrix_
void getMultiInterpolation(ftm::MergeTree< dataType > &barycenter, std::vector< std::vector< std::vector< double > > > &vS, std::vector< std::vector< std::vector< double > > > &v2s, std::vector< double > &ts, ftm::MergeTree< dataType > &interpolated)
std::vector< std::vector< double > > persCorrelationMatrix_
std::vector< std::vector< std::tuple< ftm::idNode, ftm::idNode, double > > > baryMatchings_
std::vector< std::vector< std::tuple< ftm::idNode, ftm::idNode, double > > > baryMatchings2_
bool adjustDiagonalT(dataType baryBirth, dataType baryDeath, ftm::idNode node, std::vector< std::vector< double > > &vNew, std::vector< std::vector< double > > &v2New, double &tMin, double &tMax)
void getMultiInterpolation(ftm::MergeTree< dataType > &barycenter, std::vector< std::vector< std::vector< double > > > &vS, std::vector< std::vector< std::vector< double > > > &v2s, std::vector< std::vector< double > > &v, std::vector< std::vector< double > > &v2, std::vector< double > &ts, double t, ftm::MergeTree< dataType > &interpolated)
void pointerToVector(double *pVec, size_t size, std::vector< double > &vec)
void getInterpolation(ftm::MergeTree< dataType > &barycenter, std::vector< std::vector< double > > &v, std::vector< std::vector< double > > &v2, double t, ftm::MergeTree< dataType > &interpolated)
void getInterpolationVector(ftm::MergeTree< dataType > &barycenter, std::vector< double * > &v, std::vector< double * > &v2, size_t vSize, double t, std::vector< dataType > &interpolationVectorT, bool transposeVector)
std::vector< std::vector< std::vector< double > > > trees2Vs_
std::vector< std::vector< double > > allScaledTs_
void vectorOfVectorsToPointers(std::vector< std::vector< std::vector< double > > > &vS, std::vector< std::vector< double * > > &pVS)
dataType computeReconstructionError(ftm::MergeTree< dataType > &barycenter, std::vector< ftm::MergeTree< dataType > > &inputTrees, std::vector< std::vector< double * > > &vS, std::vector< std::vector< double * > > &v2s, size_t vSize, std::vector< std::vector< double > > &allTreesTs, std::vector< double > &reconstructionErrors, std::vector< std::vector< std::tuple< ftm::idNode, ftm::idNode, double > > > &matchings, bool transposeVector=true)
void updateT(double newT, double m, double &tMin, double &tMax, bool updateTMin)
dataType computeReconstructionError(ftm::MergeTree< dataType > &barycenter, std::vector< ftm::MergeTree< dataType > > &inputTrees, std::vector< std::vector< std::vector< double > > > &vS, std::vector< std::vector< std::vector< double > > > &v2s, std::vector< std::vector< double > > &allTreesTs, std::vector< double > &reconstructionErrors)
void callGramSchmidt(std::vector< std::vector< double > > &vS, std::vector< double > &v, std::vector< double > &newV)
bool notNeedToNormalize(idNode nodeId)
std::tuple< dataType, dataType > getBirthDeath(idNode nodeId)
std::tuple< ftm::idNode, ftm::idNode > getBirthDeathNode(idNode nodeId)
idNode getParentSafe(idNode nodeId)
void getChildren(idNode nodeId, std::vector< idNode > &res)
void copyMergeTreeStructure(FTMTree_MT *tree)
std::string to_string(__int128)
Definition ripserpy.cpp:99
T1 pow(const T1 val, const T2 n)
Definition Geometry.h:454
void addVectorsProjection(const std::vector< T > &a, const std::vector< T > &b, std::vector< T > &a_out, std::vector< T > &b_out)
Definition Geometry.cpp:636
void transposeMatrix(const std::vector< std::vector< T > > &a, std::vector< std::vector< T > > &out)
Definition Geometry.cpp:764
unsigned int idNode
Node index in vect_nodes_.
The Topology ToolKit.
ftm::FTMTree_MT tree
Definition FTMTree_MT.h:901
printMsg(debug::output::BOLD+" | | | | | . \\ | | (__| | / __/| |_| / __/|__ _|"+debug::output::ENDCOLOR, debug::Priority::PERFORMANCE, debug::LineMode::NEW, stream)