18 template <
class dataType>
21 std::vector<idNode> rootChildren;
23 idNode child = rootChildren[0];
25 dataType min = std::numeric_limits<dataType>::max();
27 dataType value = this->getValue<dataType>(i);
34 return this->getValue<dataType>(root) > this->getValue<dataType>(child);
37 template <
class dataType>
40 std::vector<double> &excludeLower,
41 std::vector<double> &excludeHigher) {
42 dataType rootPers = this->getNodePersistence<dataType>(this->
getRoot());
45 threshold = rootPers * threshold;
46 auto pers = this->getNodePersistence<dataType>(nodeId);
49 bool isExcluded =
false;
50 if(excludeLower.size() == excludeHigher.size())
51 for(
unsigned i = 0; i < excludeLower.size(); ++i) {
52 isExcluded |= (pers > rootPers * excludeLower[i] / 100.0
53 and pers < rootPers * excludeHigher[i] / 100.0);
56 return pers > threshold and not isExcluded;
59 template <
class dataType>
61 std::vector<double> excludeLower, excludeHigher;
62 return this->isImportantPair<dataType>(
63 nodeId, threshold, excludeLower, excludeHigher);
66 template <
class dataType>
70 dataType parentBirth = std::get<0>(parentBirthDeath);
71 dataType parentDeath = std::get<1>(parentBirthDeath);
72 auto birthDeath = this->getBirthDeath<dataType>(nodeId);
73 dataType birth = std::get<0>(birthDeath);
74 dataType death = std::get<1>(birthDeath);
75 bool const parentInconsistent
76 = parentDeath < death or parentBirth > birth;
77 return parentInconsistent;
80 template <
class dataType>
82 bool inconsistency =
false;
83 std::queue<idNode> queue;
85 while(!queue.empty()) {
86 idNode node = queue.front();
88 if(!this->
isRoot(node) and this->isParentInconsistent<dataType>(node)) {
90 this->printNode2<dataType>(node);
94 std::vector<idNode> children;
96 for(
idNode const child : children)
105 template <
class dataType>
107 dataType maxPers = std::numeric_limits<dataType>::lowest();
113 dataType nodePers = this->getNodePersistence<dataType>(j);
114 if(nodePers > maxPers) {
123 template <
class dataType>
125 idNode lowestNode = nodeStart;
126 bool isJT = this->isJoinTree<dataType>();
127 dataType bestVal =
isJT ? std::numeric_limits<dataType>::max()
128 : std::numeric_limits<dataType>::lowest();
129 std::queue<idNode> queue;
130 queue.emplace(nodeStart);
131 while(!queue.empty()) {
132 idNode node = queue.front();
134 dataType val = this->getValue<dataType>(node);
135 if((val < bestVal and
isJT) or (val > bestVal and not
isJT)) {
139 std::vector<idNode> children;
141 for(
idNode const child : children)
142 queue.emplace(child);
150 template <
class dataType>
151 std::tuple<dataType, dataType>
153 dataType scalar1 = this->getValue<dataType>(nodeId1);
154 dataType scalar2 = this->getValue<dataType>(nodeId2);
155 dataType birth = std::min(scalar1, scalar2);
156 dataType death = std::max(scalar1, scalar2);
157 return std::make_tuple(birth, death);
160 template <
class dataType>
161 std::tuple<dataType, dataType>
163 auto nodeValue = this->getValue<dataType>(nodeId1);
164 auto node2Value = this->getValue<dataType>(nodeId2);
165 auto nodeBirth = (nodeValue < node2Value ? nodeId1 : nodeId2);
166 auto nodeDeath = (nodeValue < node2Value ? nodeId2 : nodeId1);
167 return std::make_tuple(nodeBirth, nodeDeath);
170 template <
class dataType>
174 return this->getBirthDeathFromIds<dataType>(
175 nodeId, this->
getNode(nodeId)->getOrigin());
177 return std::make_tuple(0.0, 0.0);
180 template <
class dataType>
181 std::tuple<ftm::idNode, ftm::idNode>
184 return this->getBirthDeathNodeFromIds<dataType>(
185 nodeId, this->
getNode(nodeId)->getOrigin());
187 return std::make_tuple(0.0, 0.0);
190 template <
class dataType>
193 return this->getBirthDeath<dataType>(this->
getRoot());
194 return this->getBirthDeathFromIds<dataType>(
195 this->
getRoot(), this->getMergedRootOrigin<dataType>());
198 template <
class dataType>
199 std::tuple<ftm::idNode, ftm::idNode>
202 return this->getBirthDeathNode<dataType>(this->
getRoot());
203 return this->getBirthDeathNodeFromIds<dataType>(
204 this->
getRoot(), this->getMergedRootOrigin<dataType>());
207 template <
class dataType>
209 return std::get<0>(this->getBirthDeath<dataType>(nodeId));
212 template <
class dataType>
214 std::tuple<dataType, dataType> birthDeath
215 = this->getBirthDeath<dataType>(nodeId);
216 return std::get<1>(birthDeath) - std::get<0>(birthDeath);
219 template <
class dataType>
226 return this->getNodePersistence<dataType>(this->
getRoot());
229 dataType maxPers = std::numeric_limits<dataType>::lowest();
233 maxPers = std::max(maxPers, this->getNodePersistence<dataType>(i));
238 template <
class dataType>
241 dataType pers = std::numeric_limits<dataType>::lowest();
247 if(not(nodeOrigin == root
248 and this->
getNode(nodeOrigin)->getOrigin() == (
int)i)) {
249 auto nodePers = this->getNodePersistence<dataType>(i);
250 if(pers < nodePers) {
260 template <
class dataType>
262 return this->getNodePersistence<dataType>(
263 this->getSecondMaximumPersistenceNode<dataType>());
266 template <
class dataType>
268 std::vector<std::tuple<idNode, idNode, dataType>> &pairs,
bool useBD) {
269 std::vector<idNode> nodes;
276 for(
auto node : nodes) {
277 auto pers = this->getNodePersistence<dataType>(node);
279 std::make_tuple(node, this->
getNode(node)->getOrigin(), pers));
281 auto comp = [&](
const std::tuple<idNode, idNode, dataType> a,
282 const std::tuple<idNode, idNode, dataType> b) {
283 return std::get<2>(a) < std::get<2>(b);
285 sort(pairs.begin(), pairs.end(), comp);
288 template <
class dataType>
290 std::vector<idNode> multiPersOrigins;
292 std::vector<std::tuple<idNode, idNode, dataType>> pairs;
297 for(
auto pair : pairs) {
298 idNode const nodeBirth = std::get<0>(pair);
299 idNode const nodeDeath = std::get<1>(pair);
301 origins[nodeDeath].push_back(nodeBirth);
302 birthFound[nodeBirth] =
true;
305 for(
unsigned int i = 0; i < origins.size(); ++i)
307 for(
auto node : origins[i])
308 multiPersOrigins.push_back(node);
310 return multiPersOrigins;
316 template <
class dataType>
319 std::stringstream ss;
320 ss <<
"nodeId = " << nodeId <<
" (" << this->getValue<dataType>(nodeId)
323 ss <<
" (" << this->getValue<dataType>(origin) <<
")";
329 template <
class dataType>
331 std::stringstream ss;
332 ss << this->
getRoot() <<
" (" << this->getValue<dataType>(this->
getRoot())
334 auto mergedRootOrigin = this->getMergedRootOrigin<dataType>();
335 ss << mergedRootOrigin;
337 ss <<
" (" << this->getValue<dataType>(mergedRootOrigin) <<
")";
338 ss <<
" _ " << this->getNodePersistence<dataType>(this->
getRoot());
340 ss <<
" _ " << this->getNodePersistence<dataType>(mergedRootOrigin);
347 template <
class dataType>
350 std::stringstream wholeSS;
351 std::streamsize
const sSize = std::cout.precision();
356 or (not printNodeAlone
359 std::stringstream ss;
360 ss << i <<
" _ " << std::setprecision(12)
361 << this->getValue<dataType>(i);
364 wholeSS << ss.str() << std::endl;
369 std::cout.precision(sSize);
373 template <
class dataType>
377 std::stringstream ss;
378 std::vector<std::tuple<idNode, idNode, dataType>> pairs;
380 ss <<
"size=" << pairs.size() << std::endl;
382 for(
auto pair : pairs) {
383 ss << std::get<0>(pair) <<
" ("
384 << this->getValue<dataType>(std::get<0>(pair)) <<
") _ ";
385 ss << std::get<1>(pair) <<
" ("
386 << this->getValue<dataType>(std::get<1>(pair)) <<
") _ ";
387 ss << std::get<2>(pair) << std::endl;
397 template <
class dataType>
401 std::vector<std::tuple<idNode, idNode, dataType>> pairs;
405 for(
auto pair : pairs) {
406 noOrigin[std::get<0>(pair)]++;
407 noMultiPers += (noOrigin[std::get<0>(pair)] > 1) ? 1 : 0;
408 noOrigin[std::get<1>(pair)]++;
409 noMultiPers += (noOrigin[std::get<1>(pair)] > 1) ? 1 : 0;
411 std::stringstream ss;
412 ss <<
"Number of multi pers pairs : " << noMultiPers << std::endl;
414 auto multiPers = this->getMultiPersOrigins<dataType>(useBD);
415 for(
auto node : multiPers)
416 ss << node << std::endl;
int printErr(const std::string &msg, const debug::LineMode &lineMode=debug::LineMode::NEW, std::ostream &stream=std::cerr) const
std::vector< ftm::idNode > getMultiPersOrigins(bool useBD)
std::stringstream printMultiPersPairsFromTree(bool useBD=false, bool printPairs=true, bool doPrint=true)
bool isNodeIdInconsistent(idNode nodeId)
dataType getNodePersistence(idNode nodeId)
idNode getNumberOfNodes() const
std::stringstream printTreeScalars(bool printNodeAlone=true, bool doPrint=true)
dataType getMaximumPersistence()
std::tuple< dataType, dataType > getBirthDeath(idNode nodeId)
bool isRoot(idNode nodeId)
std::tuple< ftm::idNode, ftm::idNode > getBirthDeathNode(idNode nodeId)
bool isParentInconsistent(ftm::idNode nodeId)
idNode getParentSafe(idNode nodeId)
bool isNodeOriginDefined(idNode nodeId)
std::tuple< ftm::idNode, ftm::idNode > getMergedRootBirthDeathNode()
idNode getMergedRootOrigin()
ftm::idNode getSecondMaximumPersistenceNode()
bool verifyBranchDecompositionInconsistency()
bool isImportantPair(idNode nodeId, double threshold, std::vector< double > &excludeLower, std::vector< double > &excludeHigher)
std::stringstream printNode2(idNode nodeId, bool doPrint=true)
void getPersistencePairsFromTree(std::vector< std::tuple< ftm::idNode, ftm::idNode, dataType > > &pairs, bool useBD)
void getChildren(idNode nodeId, std::vector< idNode > &res)
std::tuple< dataType, dataType > getMergedRootBirthDeath()
std::stringstream printPairsFromTree(bool useBD=false, bool printPairs=true, bool doPrint=true)
std::tuple< dataType, dataType > getBirthDeathFromIds(idNode nodeId1, idNode nodeId2)
bool isNodeAlone(idNode nodeId)
void getLeavesFromTree(std::vector< idNode > &res)
idNode getLowestNode(idNode nodeStart)
Node * getNode(idNode nodeId)
std::stringstream printMergedRoot(bool doPrint=true)
dataType getSecondMaximumPersistence()
dataType getBirth(idNode nodeId)
std::tuple< dataType, dataType > getBirthDeathNodeFromIds(idNode nodeId1, idNode nodeId2)
SimplexId getOrigin() const
unsigned int idNode
Node index in vect_nodes_.
printMsg(debug::output::BOLD+" | | | | | . \\ | | (__| | / __/| |_| / __/|__ _|"+debug::output::ENDCOLOR, debug::Priority::PERFORMANCE, debug::LineMode::NEW, stream)