47 std::vector<std::vector<double *>> &vS,
48 std::vector<std::vector<double *>> &v2s,
50 std::vector<std::vector<double>> &allTreesTs,
51 std::vector<double> &reconstructionErrors,
52 std::vector<std::vector<std::tuple<ftm::idNode, ftm::idNode, double>>>
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)
61 for(
unsigned int i = 0; i < inputTrees.size(); ++i) {
63 getMultiInterpolation<dataType>(barycenter, vS, v2s, vSize,
64 allTreesTs[i], reconstructedTree,
67 computeOneDistance<dataType>(
68 reconstructedTree, inputTrees[i], matchings[i], error,
true);
69 reconstructionError += error / inputTrees.size();
70 reconstructionErrors[i] = error;
72 return reconstructionError;
157 std::vector<std::vector<double>> &vNew,
158 std::vector<std::vector<double>> &v2New,
161 bool shortener =
false;
164 auto newBirthV1 = baryBirth - vNew[node][0];
165 auto newDeathV1 = baryDeath - vNew[node][1];
168 auto newBirthV2 = baryBirth + v2New[node][0];
169 auto newDeathV2 = baryDeath + v2New[node][1];
172 if(newBirthV1 > newDeathV1 and newBirthV2 > newDeathV2) {
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) {
185 = (baryDeath - vNew[node][1] - baryBirth + vNew[node][0])
186 / (vNew[node][0] + v2New[node][0]
187 - (vNew[node][1] + v2New[node][1]));
189 if(newBirthV1 > newDeathV1)
190 updateT(newT, m, tMin, tMax,
true);
191 if(newBirthV2 > newDeathV2)
192 updateT(newT, m, tMin, tMax,
false);
203 std::vector<std::vector<double>> &vNew,
204 std::vector<std::vector<double>> &v2New,
207 bool shortener =
false;
209 dataType birthParent = 0.0;
210 dataType deathParent = 1.0;
212 auto interpolant = [&](
int i,
double t) {
213 return -vNew[node][i] + t * (vNew[node][i] + v2New[node][i]);
217 auto newBirthV1 = baryBirth + interpolant(0, tMin);
218 auto newDeathV1 = baryDeath + interpolant(1, tMin);
219 auto parentBirthV1 = 0.0;
220 auto parentDeathV1 = 1.0;
223 auto newBirthV2 = baryBirth + interpolant(0, tMax);
224 auto newDeathV2 = baryDeath + interpolant(1, tMax);
225 auto parentBirthV2 = 0.0;
226 auto parentDeathV2 = 1.0;
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)));
238 if(((newDeathV1 > parentDeathV1 and newDeathV2 > parentDeathV2)
239 or (newBirthV1 < parentBirthV1 and newBirthV2 < parentBirthV2))
240 and not(extremOutPathIn)) {
245 if(newDeathV1 > parentDeathV1 and newBirthV1 < parentBirthV1)
246 if(newBirthV1 < newDeathV1)
247 coef1 = (parentBirthV1 - baryBirth) / interpolant(0, tMin);
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;
259 if(newDeathV2 > parentDeathV2 and newBirthV2 < parentBirthV2)
260 if(newBirthV2 < newDeathV2)
261 coef2 = (parentBirthV2 - baryBirth) / interpolant(0, tMax);
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;
274 if(((newDeathV1 > parentDeathV1 or newBirthV1 < parentBirthV1)
275 != (newDeathV2 > parentDeathV2 or newBirthV2 < parentBirthV2))
276 or extremOutPathIn) {
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);
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);
327 std::vector<std::vector<double>> &v,
328 std::vector<std::vector<double>> &v2,
332 double tMin = 0.0, tMax = 1.0;
336 auto birth = std::get<0>(birthDeath);
337 auto death = std::get<1>(birthDeath);
341 auto parentBirthDeath = baryTree->
getBirthDeath<dataType>(parent);
342 auto parentBirth = std::get<0>(parentBirthDeath);
343 auto parentDeath = std::get<1>(parentBirthDeath);
346 birth = (birth - parentBirth) / (parentDeath - parentBirth);
347 death = (death - parentBirth) / (parentDeath - parentBirth);
351 bool diagonalShortener
355 bool nestingShortener =
false;
362 double const tNew = t * (tMax - tMin) + tMin;
364 if(diagonalShortener or nestingShortener)
372 std::vector<double *> &v,
373 std::vector<double *> &v2,
376 std::vector<dataType> &interpolationVectorT,
377 bool transposeVector) {
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;
386 if(transposeVector) {
387 std::vector<std::vector<double>> out;
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()) {
405 auto nodeBirth = std::get<0>(nodeBirthDeath);
406 auto nodeDeath = std::get<1>(nodeBirthDeath);
407 auto birth = scalarsVector[nodeBirth];
408 auto death = scalarsVector[nodeDeath];
412 auto parentNodeBirthDeath
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];
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
429 ssT <<
"par. inter birth death : " << interParentBirth <<
" ___ "
430 << interParentDeath << std::endl;
433 birth = (birth - parentBirth) / (parentDeath - parentBirth);
434 death = (death - parentBirth) / (parentDeath - parentBirth);
435 ssT <<
"norm. birth death : " << birth <<
" ___ " << death
438 std::cout.precision(sSize2);
442 double tMin = 0.0, tMax = 1.0;
445 getInterpolationVectorDebugMsg<dataType>(birth, death, vNew, v2New, i,
447 "before adjustDiagonalT", ssT);
451 bool const diagonalShortener
453 noDiagonalShortener += diagonalShortener;
456 getInterpolationVectorDebugMsg<dataType>(
457 birth, death, vNew, v2New, i, t, tMin, tMax,
458 "after adjustDiagonalT/before adjustNestingT", ssT);
464 barycenter, birth, death, i, vNew, v2New, tMin, tMax);
465 noNestingShortener += nestingShortener;
468 getInterpolationVectorDebugMsg<dataType>(birth, death, vNew, v2New, i,
470 "after adjustNestingT", ssT);
475 double const tNew = t * (tMax - tMin) + tMin;
477 = birth - vNew[i][0] + tNew * (vNew[i][0] + v2New[i][0]);
479 = death - vNew[i][1] + tNew * (vNew[i][1] + v2New[i][1]);
481 double const coef = (interParentDeath - interParentBirth);
483 interBirth += interParentBirth;
485 interDeath += interParentBirth;
487 interpolationVector[nodeBirth] = interBirth;
488 interpolationVector[nodeDeath] = interDeath;
491 if(std::isnan(interpolationVector[nodeBirth])
492 or std::isnan(interpolationVector[nodeDeath])) {
498 if(interpolationVector[nodeBirth] > interpolationVector[nodeDeath]
499 and interpolationVector[nodeBirth] - interpolationVector[nodeDeath]
501 interpolationVector[nodeBirth] = interpolationVector[nodeDeath];
503 if(interpolationVector[nodeBirth] > interpolationVector[nodeDeath]) {
506 std::streamsize
const sSize = std::cout.precision();
507 std::stringstream ss;
508 ss << std::setprecision(12) << interpolationVector[nodeBirth] <<
" > "
509 << interpolationVector[nodeDeath];
511 std::cout.precision(sSize);
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;
523 if(interpolationVector[nodeDeath] < interParentBirth
524 and (interParentBirth - interpolationVector[nodeDeath]) < eps) {
525 interpolationVector[nodeDeath] = interParentBirth;
527 if(interpolationVector[nodeDeath] > interParentDeath
528 and (interpolationVector[nodeDeath] - interParentDeath) < eps)
529 interpolationVector[nodeDeath] = interParentDeath;
532 and (interpolationVector[nodeBirth] < interParentBirth
533 or interpolationVector[nodeBirth] > interParentDeath
534 or interpolationVector[nodeDeath] < interParentBirth
535 or interpolationVector[nodeDeath] > interParentDeath)) {
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;
544 std::cout.precision(sSize);
548 std::vector<ftm::idNode> children;
550 for(
auto child : children)
551 queue.emplace(child);
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.");
567 interpolationVectorT.resize(scalarsVector.size());
568 for(
unsigned int i = 0; i < interpolationVectorT.size(); ++i)
569 interpolationVectorT[i] = interpolationVector[i];