28#define treesMatchingVector \
29 std::vector<std::vector<std::tuple<ftm::idNode, ftm::idNode, double>>>
30#define matchingVectorType std::vector<treesMatchingVector>
49 template <
class dataType2>
53 bool parallelizeUpdate_ =
true;
55 unsigned int noCentroids_ = 2;
58 int noIterationC_ = 0;
59 double addDeletedNodesTime_ = 0;
62 bool acceleratedInitialized_ =
false;
63 std::vector<std::vector<double>> lowerBound_;
64 std::vector<double> upperBound_;
65 std::vector<int> bestCentroid_, oldBestCentroid_;
66 std::vector<double> bestDistance_;
67 std::vector<bool> recompute_;
68 std::vector<ftm::MergeTree<dataType2>> oldCentroids_, oldCentroids2_;
71 std::vector<std::vector<int>> trees2NodeCorr_;
76 "MergeTreeClustering");
82 noCentroids_ = noCentroidsT;
90 return trees2NodeCorr_;
101 template <
class dataType>
103 std::vector<ftm::FTMTree_MT *> &trees,
104 std::vector<ftm::FTMTree_MT *> &trees2,
108 std::vector<dataType> distances(
109 trees.size(), std::numeric_limits<dataType>::max());
113 std::vector<ftm::MergeTree<dataType>> mTreesLimited, mTrees2Limited;
117 getSizeLimitedTrees<dataType>(
119 if(trees2.size() != 0)
121 limitPercent, mTrees2Limited);
125 for(
unsigned int i = 0; i < noCentroids_; ++i) {
128 bestIndex = getBestInitTreeIndex<dataType>(
129 trees, trees2, limitPercent,
false);
133 for(
auto val : distances)
135 double bestValue = std::numeric_limits<double>::lowest();
136 std::vector<double> probabilities(trees.size());
137 for(
unsigned int j = 0; j < distances.size(); ++j) {
139 = (sum != 0 ? distances[j] / sum : 1.0 / distances.size());
140 if(probabilities[j] > bestValue) {
141 bestValue = probabilities[j];
146 std::random_device rd;
147 std::default_random_engine generator(rd());
148 std::discrete_distribution<int> distribution(
149 probabilities.begin(), probabilities.end());
150 bestIndex = distribution(generator);
157 = ftm::copyMergeTree<dataType>(trees[bestIndex],
true);
159 ftm::cleanMergeTree<dataType>(allCentroids[0][i]);
160 if(trees2.size() != 0) {
162 = ftm::copyMergeTree<dataType>(trees2[bestIndex],
true);
164 ftm::cleanMergeTree<dataType>(allCentroids[1][i]);
167 if(i == noCentroids_ - 1)
169#ifdef TTK_ENABLE_OPENMP44
170#pragma omp parallel for schedule(dynamic) shared(allCentroids) \
171 num_threads(this->threadNumber_) if(parallelize_)
173 for(
unsigned int j = 0; j < trees.size(); ++j) {
174 std::vector<std::tuple<ftm::idNode, ftm::idNode, double>> matching,
176 dataType distanceT, distanceT2;
178 = (doSizeLimit ? &(mTreesLimited[j].tree) : trees[j]);
179 computeOneDistance<dataType>(treeToUse, allCentroids[0][i], matching,
181 if(trees2.size() != 0) {
183 = (doSizeLimit ? &(mTrees2Limited[j].tree) : trees2[j]);
184 computeOneDistance<dataType>(tree2ToUse, allCentroids[1][i],
187 distanceT = mixDistances<dataType>(distanceT, distanceT2);
189 distances[j] = std::min(distances[j], distanceT);
194 template <
class dataType>
198 std::vector<std::tuple<double, int>> distancesAndIndexes(
199 bestDistance_.size());
200 for(
unsigned int i = 0; i < bestDistance_.size(); ++i)
201 distancesAndIndexes[i] = std::make_tuple(-bestDistance_[i], i);
202 std::sort(distancesAndIndexes.begin(), distancesAndIndexes.end());
203 int const bestIndex = std::get<1>(distancesAndIndexes[noNewCentroid]);
204 centroid = ftm::copyMergeTree<dataType>(trees[bestIndex],
true);
206 ftm::cleanMergeTree<dataType>(centroid);
209 template <
class dataType>
211 std::vector<ftm::FTMTree_MT *> &trees,
213 std::vector<ftm::FTMTree_MT *> &
ttkNotUsed(trees2)) {
216 trees.size(), std::vector<double>(centroids.size(), 0));
218 upperBound_.resize(trees.size(), std::numeric_limits<double>::max());
219 bestCentroid_.clear();
220 bestCentroid_.resize(trees.size(), -1);
221 oldBestCentroid_.clear();
222 oldBestCentroid_.resize(trees.size(), -1);
223 bestDistance_.clear();
224 bestDistance_.resize(trees.size(), std::numeric_limits<double>::max());
226 recompute_.resize(trees.size(),
true);
229 template <
class dataType>
233 std::vector<ftm::FTMTree_MT *> &trees2,
235 acceleratedInitialized_ =
true;
236 std::vector<std::tuple<int, int>> assignmentC;
237 std::vector<dataType> bestDistanceT(
238 trees.size(), std::numeric_limits<dataType>::max());
239 assignmentCentroidsNaive<dataType>(
240 trees, centroids, assignmentC, bestDistanceT, trees2, centroids2);
241 for(
unsigned int i = 0; i < bestDistanceT.size(); ++i)
242 bestDistance_[i] = bestDistanceT[i];
243 for(
auto asgn : assignmentC)
244 bestCentroid_[std::get<1>(asgn)] = std::get<0>(asgn);
245 for(
unsigned int i = 0; i < bestDistance_.size(); ++i)
246 upperBound_[i] = bestDistance_[i];
249 template <
class dataType>
252 oldCentroids.clear();
253 for(
unsigned int i = 0; i < centroids.size(); ++i)
254 oldCentroids.push_back(ftm::copyMergeTree<dataType>(centroids[i]));
260 template <
class dataType>
262 std::vector<ftm::FTMTree_MT *> &trees,
264 std::vector<std::tuple<int, int>> &assignmentC,
265 std::vector<dataType> &bestDistanceT,
266 std::vector<ftm::FTMTree_MT *> &trees2,
268 if(not acceleratedInitialized_) {
269 initAcceleratedKMeans<dataType>(trees, centroids, trees2, centroids2);
272 std::vector<dataType> distanceShift(centroids.size()),
273 distanceShift2(centroids2.size());
274#ifdef TTK_ENABLE_OPENMP4
275#pragma omp parallel for schedule(dynamic) \
276 shared(centroids, centroids2, oldCentroids_, oldCentroids2_) \
277 num_threads(this->threadNumber_) if(parallelize_)
279 for(
unsigned int i = 0; i < centroids.size(); ++i) {
280 std::vector<std::tuple<ftm::idNode, ftm::idNode, double>> matching,
282 computeOneDistance<dataType>(centroids[i], oldCentroids_[i], matching,
284 if(trees2.size() != 0) {
285 computeOneDistance<dataType>(centroids2[i], oldCentroids2_[i],
286 matching2, distanceShift2[i],
289 = mixDistances<dataType>(distanceShift[i], distanceShift2[i]);
294 for(
unsigned int i = 0; i < trees.size(); ++i)
295 for(
unsigned int c = 0; c < centroids.size(); ++c)
297 = std::max(lowerBound_[i][c] - distanceShift[c], 0.0);
300 for(
unsigned int i = 0; i < trees.size(); ++i) {
301 upperBound_[i] = upperBound_[i] + distanceShift[bestCentroid_[i]];
302 recompute_[i] =
true;
307 std::vector<std::vector<double>> centroidsDistance, centroidsDistance2;
308 getCentroidsDistanceMatrix<dataType>(
310 if(trees2.size() != 0) {
311 getCentroidsDistanceMatrix<dataType>(
315 std::vector<double> centroidScore(
316 centroids.size(), std::numeric_limits<double>::max());
317 for(
unsigned int i = 0; i < centroids.size(); ++i)
318 for(
unsigned int j = i + 1; j < centroids.size(); ++j) {
319 if(0.5 * centroidsDistance[i][j] < centroidScore[i])
320 centroidScore[i] = 0.5 * centroidsDistance[i][j];
321 if(0.5 * centroidsDistance[i][j] < centroidScore[j])
322 centroidScore[j] = 0.5 * centroidsDistance[i][j];
326 std::vector<bool> identified(trees.size());
327 for(
unsigned int i = 0; i < trees.size(); ++i)
328 identified[i] = (upperBound_[i] <= centroidScore[bestCentroid_[i]]);
331#ifdef TTK_ENABLE_OPENMP4
332#pragma omp parallel for schedule(dynamic) shared(centroids, centroids2) \
333 num_threads(this->threadNumber_) if(parallelize_)
335 for(
unsigned int i = 0; i < trees.size(); ++i)
336 for(
unsigned int c = 0; c < centroids.size(); ++c) {
337 if(not identified[i] and (
int) c != bestCentroid_[i]
338 and upperBound_[i] > lowerBound_[i][c]
340 > 0.5 * centroidsDistance[bestCentroid_[i]][c]) {
343 std::vector<std::tuple<ftm::idNode, ftm::idNode, double>>
345 dataType distance, distance2;
346 computeOneDistance<dataType>(trees[i],
347 centroids[bestCentroid_[i]],
349 if(trees2.size() != 0) {
350 computeOneDistance<dataType>(
351 trees2[i], centroids2[bestCentroid_[i]], matching2, distance2,
353 distance = mixDistances<dataType>(distance, distance2);
355 recompute_[i] =
false;
356 lowerBound_[i][bestCentroid_[i]] = distance;
357 upperBound_[i] = distance;
358 bestDistance_[i] = distance;
360 bestDistance_[i] = upperBound_[i];
363 if(bestDistance_[i] > lowerBound_[i][c]
365 > 0.5 * centroidsDistance[bestCentroid_[i]][c]) {
366 std::vector<std::tuple<ftm::idNode, ftm::idNode, double>>
368 dataType distance, distance2;
369 computeOneDistance<dataType>(
371 if(trees2.size() != 0) {
372 computeOneDistance<dataType>(trees2[i], centroids2[c],
373 matching2, distance2,
375 distance = mixDistances<dataType>(distance, distance2);
377 lowerBound_[i][c] = distance;
378 if(distance < bestDistance_[i]) {
379 bestCentroid_[i] = c;
380 upperBound_[i] = distance;
381 bestDistance_[i] = distance;
388 copyCentroids<dataType>(centroids, oldCentroids_);
389 if(trees2.size() != 0)
390 copyCentroids<dataType>(centroids2, oldCentroids2_);
393 for(
unsigned int i = 0; i < bestDistance_.size(); ++i)
394 bestDistanceT[i] = bestDistance_[i];
395 for(
unsigned int i = 0; i < bestCentroid_.size(); ++i)
396 assignmentC.emplace_back(bestCentroid_[i], i);
399 template <
class dataType>
403 std::vector<std::tuple<int, int>> &assignmentC,
404 std::vector<dataType> &bestDistanceT,
405 std::vector<ftm::FTMTree_MT *> &trees2,
407 oldBestCentroid_ = bestCentroid_;
408 assignmentCentroidsAccelerated<dataType>(
409 trees, centroids, assignmentC, bestDistanceT, trees2, centroids2);
412 template <
class dataType>
414 std::vector<ftm::FTMTree_MT *> &trees,
417 std::vector<std::tuple<int, int>> &assignmentC,
418 std::vector<dataType> &bestDistanceT,
419 std::vector<ftm::FTMTree_MT *> &trees2,
422 int noC = centroids.size();
423 std::vector<std::vector<ftm::FTMTree_MT *>> assignedTrees(noC),
425 std::vector<std::vector<int>> assignedTreesIndex(noC);
427 for(
auto asgn : assignmentC) {
428 assignedTreesIndex[std::get<0>(asgn)].push_back(std::get<1>(asgn));
429 assignedTrees[std::get<0>(asgn)].push_back(trees[std::get<1>(asgn)]);
430 if(trees2.size() != 0)
431 assignedTrees2[std::get<0>(asgn)].push_back(
432 trees2[std::get<1>(asgn)]);
435#ifdef TTK_ENABLE_OPENMP4
436#pragma omp parallel for schedule(dynamic) shared(centroids, centroids2) \
437 num_threads(this->threadNumber_) if(parallelize_)
439 for(
unsigned int i = 0; i < centroids.size(); ++i) {
440 std::vector<dataType> distances(assignedTrees[i].size(), 0);
441 std::vector<dataType> distances2(assignedTrees[i].size(), 0);
443 assignment<dataType>(
445 matchingsC[i] = matching;
446 if(trees2.size() != 0) {
447 assignment<dataType>(assignedTrees2[i], centroids2[i], matching2,
449 matchingsC2[i] = matching2;
450 for(
unsigned int j = 0; j < assignedTreesIndex[i].size(); ++j)
451 distances[j] = mixDistances<dataType>(distances[j], distances2[j]);
453 for(
unsigned int j = 0; j < assignedTreesIndex[i].size(); ++j) {
454 int const index = assignedTreesIndex[i][j];
455 bestDistanceT[index] = distances[j];
460 template <
class dataType>
462 std::vector<ftm::FTMTree_MT *> &trees,
464 std::vector<std::tuple<int, int>> &assignmentC,
465 std::vector<dataType> &bestDistanceT,
466 std::vector<ftm::FTMTree_MT *> &trees2,
468 std::vector<int> bestCentroidT(trees.size(), -1);
470#ifdef TTK_ENABLE_OPENMP4
471#pragma omp parallel for schedule(dynamic) shared(centroids, centroids2) \
472 num_threads(this->threadNumber_) if(parallelize_)
474 for(
unsigned int i = 0; i < trees.size(); ++i) {
475 for(
unsigned int j = 0; j < centroids.size(); ++j) {
476 std::vector<std::tuple<ftm::idNode, ftm::idNode, double>> matching;
477 std::vector<std::tuple<ftm::idNode, ftm::idNode, double>> matching2;
478 dataType distance, distance2;
479 computeOneDistance<dataType>(
481 if(trees2.size() != 0) {
482 computeOneDistance<dataType>(trees2[i], centroids2[j], matching2,
484 distance = mixDistances<dataType>(distance, distance2);
486 if(distance < bestDistanceT[i]) {
487 bestDistanceT[i] = distance;
488 bestDistance_[i] = distance;
489 bestCentroidT[i] = j;
490 bestCentroid_[i] = j;
495 for(
unsigned int i = 0; i < bestCentroidT.size(); ++i)
496 assignmentC.emplace_back(bestCentroidT[i], i);
499 template <
class dataType>
502 std::vector<std::vector<double>> &distanceMatrix,
503 bool useDoubleInput =
false,
504 bool isFirstInput =
true) {
505 std::vector<ftm::FTMTree_MT *> trees(centroids.size());
506 for(
size_t i = 0; i < centroids.size(); ++i) {
507 trees[i] = &(centroids[i].tree);
509 getDistanceMatrix<dataType>(
510 trees, distanceMatrix, useDoubleInput, isFirstInput);
514 std::vector<int> &nodeCorr,
515 std::vector<int> &assignedTreesIndex) {
516 for(
int const i : assignedTreesIndex) {
517 std::vector<std::tuple<ftm::idNode, ftm::idNode, double>> newMatching;
518 for(
auto tup : matchingT[i])
519 newMatching.emplace_back(
520 nodeCorr[std::get<0>(tup)], std::get<1>(tup), std::get<2>(tup));
521 matchingT[i] = newMatching;
529 for(
unsigned int i = 0; i < bestCentroid_.size(); ++i)
530 if(bestCentroid_[i] == clusterId
531 and bestCentroid_[i] != oldBestCentroid_[i])
536 template <
class dataType>
539 std::vector<double> &alphas,
540 std::vector<std::tuple<int, int>> &assignmentC) {
541 bool oneCentroidUpdated =
false;
542 int noC = centroids.size();
543 std::vector<std::vector<ftm::FTMTree_MT *>> assignedTrees(noC);
544 std::vector<std::vector<int>> assignedTreesIndex(noC);
545 std::vector<std::vector<double>> assignedAlphas(noC);
547 for(
auto asgn : assignmentC) {
548 assignedTrees[std::get<0>(asgn)].push_back(trees[std::get<1>(asgn)]);
549 assignedTreesIndex[std::get<0>(asgn)].push_back(std::get<1>(asgn));
550 assignedAlphas[std::get<0>(asgn)].push_back(alphas[std::get<1>(asgn)]);
554 std::vector<int> noNewCentroid(centroids.size(), -1);
555 for(
unsigned int i = 0; i < centroids.size(); ++i)
556 if(assignedTrees[i].size() == 0) {
557 noNewCentroid[i] = cpt;
561#ifdef TTK_ENABLE_OPENMP4
562#pragma omp parallel num_threads(this->threadNumber_) \
563 shared(centroids) if(parallelize_ and parallelizeUpdate_)
565#pragma omp single nowait
568 for(
unsigned int i = 0; i < centroids.size(); ++i) {
569#ifdef TTK_ENABLE_OPENMP4
570#pragma omp task firstprivate(i) shared(centroids)
573 if(assignedTrees[i].size() == 0) {
575 initNewCentroid<dataType>(
576 trees, centroids[i], noNewCentroid[i]);
577 for(
unsigned int t = 0; t < trees.size(); ++t)
578 lowerBound_[t][i] = 0;
579 }
else if(assignedTrees[i].size() == 1) {
581 = ftm::copyMergeTree<dataType>(assignedTrees[i][0],
true);
583 ftm::cleanMergeTree<dataType>(centroids[i]);
587 oneCentroidUpdated =
true;
588 double alphasSum = 0;
589 for(
unsigned int j = 0; j < assignedAlphas[i].size(); ++j)
590 alphasSum += assignedAlphas[i][j];
591 for(
unsigned int j = 0; j < assignedAlphas[i].size(); ++j)
592 assignedAlphas[i][j] /= alphasSum;
594 computeOneBarycenter<dataType>(
595 assignedTrees[i], centroids[i], assignedAlphas[i], matching);
596 std::vector<ftm::idNode> deletedNodesT;
597 persistenceThresholding<dataType>(
598 &(centroids[i].tree), 0, deletedNodesT);
599 ftm::cleanMergeTree<dataType>(centroids[i]);
601#ifdef TTK_ENABLE_OPENMP4
605#ifdef TTK_ENABLE_OPENMP4
610 return oneCentroidUpdated;
613 template <
class dataType>
615 std::vector<ftm::FTMTree_MT *> &trees,
617 std::vector<double> &alphas,
618 std::vector<std::vector<std::tuple<ftm::idNode, ftm::idNode, double>>>
637 trees, baryMergeTree, alphas, finalMatchings);
645 template <
class dataType>
649 std::vector<double> &alphas,
650 std::vector<int> &clusteringAssignment,
651 std::vector<ftm::FTMTree_MT *> &trees2,
659 int noCentroidsT = centroids.size();
660 bool converged =
false;
661 dataType inertia = -1;
662 dataType minInertia = std::numeric_limits<dataType>::max();
665 std::vector<std::tuple<int, int>> assignmentC;
666 std::vector<dataType> bestDistanceT(
667 trees.size(), std::numeric_limits<dataType>::max());
668 while(not converged) {
672 std::stringstream ssIter;
673 ssIter <<
"Iteration " << noIterationC_;
678 assignmentCentroids<dataType>(
679 trees, centroids, assignmentC, bestDistanceT, trees2, centroids2);
685 bool trees1Updated =
true, trees2Updated =
true;
687 = updateCentroids<dataType>(trees, centroids, alphas, assignmentC);
688 if(trees2.size() != 0)
689 trees2Updated = updateCentroids<dataType>(
690 trees2, centroids2, alphas, assignmentC);
696 dataType currentInertia = 0;
697 for(
auto distance : bestDistanceT)
698 currentInertia += distance * distance;
699 converged = std::abs((
double)(inertia - currentInertia)) < 0.01;
700 inertia = currentInertia;
701 std::stringstream ss3;
702 ss3 <<
"Inertia : " << inertia;
705 minInertia = std::min(minInertia, inertia);
707 cptBlocked += (minInertia < inertia) ? 1 : 0;
708 converged = (cptBlocked >= 10);
713 converged = converged or (not trees1Updated and not trees2Updated);
718 bestDistanceT.clear();
719 bestDistanceT.resize(
720 trees.size(), std::numeric_limits<dataType>::max());
729 finalAssignmentCentroids<dataType>(trees, centroids, matchingsC,
730 assignmentC, bestDistanceT, trees2,
731 centroids2, matchingsC2);
732 for(
auto dist : bestDistanceT)
734 dataType currentInertia = 0;
735 for(
auto distance : bestDistanceT)
736 currentInertia += distance * distance;
737 std::stringstream ss;
738 ss <<
"Inertia : " << currentInertia;
742 std::vector<int> cptCentroid(centroids.size(), 0);
743 for(
auto asgn : assignmentC) {
744 int const centroid = std::get<0>(asgn);
745 int const tree = std::get<1>(asgn);
747 clusteringAssignment[tree] = centroid;
748 outputMatching[centroid][tree]
749 = matchingsC[centroid][cptCentroid[centroid]];
750 if(trees2.size() != 0)
751 outputMatching2[centroid][tree]
752 = matchingsC2[centroid][cptCentroid[centroid]];
753 ++cptCentroid[centroid];
756 auto clusteringTime = t_clust.
getElapsedTime() - addDeletedNodesTime_;
760 template <
class dataType>
763 std::vector<double> &alphas,
764 std::vector<int> &clusteringAssignment,
773 if(trees2.size() != 0) {
774 trees2NodeCorr_.resize(trees2.size());
775 preprocessingClustering<dataType>(trees2, trees2NodeCorr_,
false);
777 std::vector<ftm::FTMTree_MT *> treesT;
778 ftm::mergeTreeToFTMTree<dataType>(trees, treesT);
779 std::vector<ftm::FTMTree_MT *> treesT2;
780 ftm::mergeTreeToFTMTree<dataType>(trees2, treesT2);
784 std::vector<std::vector<ftm::MergeTree<dataType>>> allCentroids;
785 initCentroids<dataType>(treesT, treesT2, allCentroids);
786 centroids = allCentroids[0];
787 if(trees2.size() != 0)
788 centroids2 = allCentroids[1];
796 initAcceleratedKMeansVectors<dataType>(treesT, centroids, treesT2);
799 computeCentroids<dataType>(treesT, centroids, outputMatching, alphas,
800 clusteringAssignment, treesT2, centroids2,
806 postprocessingClustering<dataType>(
807 trees, centroids, outputMatching, clusteringAssignment);
816 template <
class dataType>
819 std::vector<int> &clusteringAssignment,
824 if(trees2.size() != 0)
825 printMsg(
"Use join and split trees");
827 std::vector<double> alphas;
828 for(
unsigned int i = 0; i < trees.size(); ++i)
829 alphas.push_back(1.0 / trees.size());
831 execute<dataType>(trees, outputMatching, alphas, clusteringAssignment,
832 trees2, outputMatching2, centroids, centroids2);
835 template <
class dataType>
838 std::vector<int> &clusteringAssignment,
840 std::vector<ftm::MergeTree<dataType>> trees2, centroids2;
842 execute<dataType>(trees, outputMatching, clusteringAssignment, trees2,
843 outputMatching2, centroids, centroids2);
849 template <
class dataType>
851 std::vector<std::vector<int>> &nodeCorr,
852 bool useMinMaxPairT =
true) {
853 for(
unsigned int i = 0; i < trees.size(); ++i) {
854 preprocessingPipeline<dataType>(
857 if(trees.size() < 40)
858 printTreeStats(trees[i]);
866 template <
class dataType>
869 for(
unsigned int i = 0; i < centroids.size(); ++i)
870 fixMergedRootOriginBarycenter<dataType>(centroids[i]);
873 template <
class dataType>
876 for(
unsigned int i = 0; i < centroids2.size(); ++i)
880 template <
class dataType>
885 std::vector<int> &clusteringAssignment) {
886 for(
unsigned int i = 0; i < trees.size(); ++i)
887 postprocessingPipeline<dataType>(&(trees[i].tree));
888 for(
unsigned int i = 0; i < centroids.size(); ++i)
889 postprocessingPipeline<dataType>(&(centroids[i].tree));
890 for(
unsigned int c = 0; c < centroids.size(); ++c)
891 for(
unsigned int i = 0; i < trees.size(); ++i)
892 if(clusteringAssignment[i] == (
int)c)
893 convertBranchDecompositionMatching<dataType>(
894 &(centroids[c].tree), &(trees[i].tree), outputMatching[c][i]);
900 template <
class dataType>
904 for(
auto ¢roid : centroids)
906 for(
auto ¢roid : centroids2)
#define ttkNotUsed(x)
Mark function/method parameters that are not used in the function body at all.
#define matchingVectorType
#define treesMatchingVector
virtual int setThreadNumber(const int threadNumber)
Minimalist debugging class.
void setDebugMsgPrefix(const std::string &prefix)
virtual int setDebugLevel(const int &debugLevel)
void limitSizeBarycenter(ftm::MergeTree< dataType > &bary, std::vector< ftm::FTMTree_MT * > &trees, unsigned int barycenterMaximumNumberOfPairs, double percent, bool useBD=true)
double getAddDeletedNodesTime()
void setIsCalled(bool ic)
double barycenterSizeLimitPercent_
void computeBarycenter(std::vector< ftm::FTMTree_MT * > &trees, ftm::MergeTree< dataType > &baryMergeTree, std::vector< double > &alphas, std::vector< std::vector< std::tuple< ftm::idNode, ftm::idNode, double > > > &finalMatchings, bool finalAsgnDoubleInput=false, bool finalAsgnFirstInput=true)
unsigned int barycenterMaximumNumberOfPairs_
void setDeterministic(bool deterministicT)
std::vector< double > finalDistances_
bool progressiveBarycenter_
void printBaryStats(ftm::FTMTree_MT *baryTree, const debug::Priority &priority=debug::Priority::INFO)
void setProgressiveBarycenter(bool progressive)
void setBarycenterMaximumNumberOfPairs(unsigned int maxi)
void setBarycenterSizeLimitPercent(double percent)
void setBranchDecomposition(bool useBD)
void setNormalizedWasserstein(bool normalizedWasserstein)
void setDistanceSquaredRoot(bool distanceSquaredRoot)
double mixtureCoefficient_
void setAssignmentSolver(int assignmentSolver)
bool normalizedWasserstein_
void printTreesStats(std::vector< ftm::FTMTree_MT * > &trees)
void copyMinMaxPair(ftm::MergeTree< dataType > &mTree1, ftm::MergeTree< dataType > &mTree2, bool setOrigins=false)
std::vector< std::vector< int > > treesNodeCorr_
void setKeepSubtree(bool keepSubtree)
bool branchDecomposition_
void mixDistancesMatrix(std::vector< std::vector< dataType > > &distanceMatrix, std::vector< std::vector< dataType > > &distanceMatrix2)
void computeCentroids(std::vector< ftm::FTMTree_MT * > &trees, std::vector< ftm::MergeTree< dataType > > ¢roids, matchingVectorType &outputMatching, std::vector< double > &alphas, std::vector< int > &clusteringAssignment, std::vector< ftm::FTMTree_MT * > &trees2, std::vector< ftm::MergeTree< dataType > > ¢roids2, matchingVectorType &outputMatching2)
void assignmentCentroidsNaive(std::vector< ftm::FTMTree_MT * > &trees, std::vector< ftm::MergeTree< dataType > > ¢roids, std::vector< std::tuple< int, int > > &assignmentC, std::vector< dataType > &bestDistanceT, std::vector< ftm::FTMTree_MT * > &trees2, std::vector< ftm::MergeTree< dataType > > ¢roids2)
void copyCentroids(std::vector< ftm::MergeTree< dataType > > ¢roids, std::vector< ftm::MergeTree< dataType > > &oldCentroids)
void setMixtureCoefficient(double coef)
void postprocessingClustering(std::vector< ftm::MergeTree< dataType > > &trees, std::vector< ftm::MergeTree< dataType > > ¢roids, matchingVectorType &outputMatching, std::vector< int > &clusteringAssignment)
void initAcceleratedKMeans(std::vector< ftm::FTMTree_MT * > &trees, std::vector< ftm::MergeTree< dataType > > ¢roids, std::vector< ftm::FTMTree_MT * > &trees2, std::vector< ftm::MergeTree< dataType > > ¢roids2)
void fixMergedRootOriginClustering(std::vector< ftm::MergeTree< dataType > > ¢roids)
void getCentroidsDistanceMatrix(std::vector< ftm::MergeTree< dataType > > ¢roids, std::vector< std::vector< double > > &distanceMatrix, bool useDoubleInput=false, bool isFirstInput=true)
void initAcceleratedKMeansVectors(std::vector< ftm::FTMTree_MT * > &trees, std::vector< ftm::MergeTree< dataType > > ¢roids, std::vector< ftm::FTMTree_MT * > &ttkNotUsed(trees2))
void printCentroidsStats(std::vector< ftm::MergeTree< dataType > > ¢roids, std::vector< ftm::MergeTree< dataType > > ¢roids2)
void computeOneBarycenter(std::vector< ftm::FTMTree_MT * > &trees, ftm::MergeTree< dataType > &baryMergeTree, std::vector< double > &alphas, std::vector< std::vector< std::tuple< ftm::idNode, ftm::idNode, double > > > &finalMatchings)
void setNoCentroids(unsigned int noCentroidsT)
void preprocessingClustering(std::vector< ftm::MergeTree< dataType > > &trees, std::vector< std::vector< int > > &nodeCorr, bool useMinMaxPairT=true)
void finalAssignmentCentroids(std::vector< ftm::FTMTree_MT * > &trees, std::vector< ftm::MergeTree< dataType > > ¢roids, matchingVectorType &matchingsC, std::vector< std::tuple< int, int > > &assignmentC, std::vector< dataType > &bestDistanceT, std::vector< ftm::FTMTree_MT * > &trees2, std::vector< ftm::MergeTree< dataType > > ¢roids2, matchingVectorType &matchingsC2)
void execute(std::vector< ftm::MergeTree< dataType > > &trees, matchingVectorType &outputMatching, std::vector< double > &alphas, std::vector< int > &clusteringAssignment, std::vector< ftm::MergeTree< dataType > > &trees2, matchingVectorType &outputMatching2, std::vector< ftm::MergeTree< dataType > > ¢roids, std::vector< ftm::MergeTree< dataType > > ¢roids2)
std::vector< std::vector< int > > getTrees2NodeCorr()
void assignmentCentroidsAccelerated(std::vector< ftm::FTMTree_MT * > &trees, std::vector< ftm::MergeTree< dataType > > ¢roids, std::vector< std::tuple< int, int > > &assignmentC, std::vector< dataType > &bestDistanceT, std::vector< ftm::FTMTree_MT * > &trees2, std::vector< ftm::MergeTree< dataType > > ¢roids2)
void execute(std::vector< ftm::MergeTree< dataType > > &trees, matchingVectorType &outputMatching, std::vector< int > &clusteringAssignment, std::vector< ftm::MergeTree< dataType > > ¢roids)
void putBackMinMaxPair(std::vector< ftm::MergeTree< dataType > > ¢roids, std::vector< ftm::MergeTree< dataType > > ¢roids2)
bool samePreviousAssignment(int clusterId)
bool updateCentroids(std::vector< ftm::FTMTree_MT * > &trees, std::vector< ftm::MergeTree< dataType > > ¢roids, std::vector< double > &alphas, std::vector< std::tuple< int, int > > &assignmentC)
void initCentroids(std::vector< ftm::FTMTree_MT * > &trees, std::vector< ftm::FTMTree_MT * > &trees2, std::vector< std::vector< ftm::MergeTree< dataType > > > &allCentroids)
void execute(std::vector< ftm::MergeTree< dataType > > &trees, matchingVectorType &outputMatching, std::vector< int > &clusteringAssignment, std::vector< ftm::MergeTree< dataType > > &trees2, matchingVectorType &outputMatching2, std::vector< ftm::MergeTree< dataType > > ¢roids, std::vector< ftm::MergeTree< dataType > > ¢roids2)
~MergeTreeClustering() override=default
void matchingCorrespondence(treesMatchingVector &matchingT, std::vector< int > &nodeCorr, std::vector< int > &assignedTreesIndex)
void initNewCentroid(std::vector< ftm::FTMTree_MT * > &trees, ftm::MergeTree< dataType > ¢roid, int noNewCentroid)
void assignmentCentroids(std::vector< ftm::FTMTree_MT * > &trees, std::vector< ftm::MergeTree< dataType > > ¢roids, std::vector< std::tuple< int, int > > &assignmentC, std::vector< dataType > &bestDistanceT, std::vector< ftm::FTMTree_MT * > &trees2, std::vector< ftm::MergeTree< dataType > > ¢roids2)
printMsg(debug::output::BOLD+" | | | | | . \\ | | (__| | / __/| |_| / __/|__ _|"+debug::output::ENDCOLOR, debug::Priority::PERFORMANCE, debug::LineMode::NEW, stream)