18 template <
class dataType>
21 std::vector<idNode> rootChildren;
23 idNode child = rootChildren[0];
25 dataType min = std::numeric_limits<dataType>::max();
37 template <
class dataType>
40 std::vector<double> &excludeLower,
41 std::vector<double> &excludeHigher)
const {
44 dataType lowestNodeValue
47 = (rootValue > lowestNodeValue ? rootValue - lowestNodeValue
48 : lowestNodeValue - rootValue);
50 threshold = rootPers * threshold;
52 auto isImportantPairOneNode = [&](
idNode node) {
56 bool isExcluded =
false;
57 if(excludeLower.size() == excludeHigher.size())
58 for(
unsigned i = 0; i < excludeLower.size(); ++i) {
59 isExcluded |= (pers > rootPers * excludeLower[i] / 100.0
60 and pers < rootPers * excludeHigher[i] / 100.0);
62 return (pers > threshold and not isExcluded);
65 if(isImportantPairOneNode(nodeId))
74 std::queue<idNode> queue;
76 queue.emplace(leafNode);
77 while(!queue.empty()) {
78 idNode node = queue.front();
81 if(isImportantPairOneNode(node))
84 nodeDone[node] =
true;
87 if(parent != saddleNode)
88 if(not nodeDone[parent])
89 queue.emplace(parent);
91 std::vector<idNode> children;
93 for(
auto child : children)
94 if(not nodeDone[child])
101 template <
class dataType>
103 std::vector<double> excludeLower, excludeHigher;
105 nodeId, threshold, excludeLower, excludeHigher);
108 template <
class dataType>
110 auto parentBirthDeath
112 dataType parentBirth = std::get<0>(parentBirthDeath);
113 dataType parentDeath = std::get<1>(parentBirthDeath);
115 dataType birth = std::get<0>(birthDeath);
116 dataType death = std::get<1>(birthDeath);
117 bool const parentInconsistent
118 = parentDeath < death or parentBirth > birth;
119 return parentInconsistent;
122 template <
class dataType>
124 bool inconsistency =
false;
125 std::queue<idNode> queue;
126 queue.emplace(this->
getRoot());
127 while(!queue.empty()) {
128 idNode node = queue.front();
134 inconsistency =
true;
136 std::vector<idNode> children;
138 for(
idNode const child : children)
139 queue.emplace(child);
141 return inconsistency;
147 template <
class dataType>
149 dataType maxPers = std::numeric_limits<dataType>::lowest();
154 and this->
getNode(j)->getOrigin() == (
int)root) {
156 if(nodePers > maxPers) {
165 template <
class dataType>
167 idNode lowestNode = nodeStart;
169 dataType bestVal =
isJT ? std::numeric_limits<dataType>::max()
170 : std::numeric_limits<dataType>::lowest();
171 std::queue<idNode> queue;
172 queue.emplace(nodeStart);
173 while(!queue.empty()) {
174 idNode node = queue.front();
177 if((val < bestVal and
isJT) or (val > bestVal and not
isJT)) {
181 std::vector<idNode> children;
183 for(
idNode const child : children)
184 queue.emplace(child);
192 template <
class dataType>
193 std::tuple<dataType, dataType>
197 dataType birth = std::min(scalar1, scalar2);
198 dataType death = std::max(scalar1, scalar2);
199 return std::make_tuple(birth, death);
202 template <
class dataType>
203 std::tuple<dataType, dataType>
208 auto nodeBirth = (nodeValue < node2Value ? nodeId1 : nodeId2);
209 auto nodeDeath = (nodeValue < node2Value ? nodeId2 : nodeId1);
210 return std::make_tuple(nodeBirth, nodeDeath);
213 template <
class dataType>
214 std::tuple<dataType, dataType>
219 nodeId, this->
getNode(nodeId)->getOrigin());
221 return std::make_tuple(0.0, 0.0);
224 template <
class dataType>
225 std::tuple<ftm::idNode, ftm::idNode>
229 nodeId, this->
getNode(nodeId)->getOrigin());
231 return std::make_tuple(0.0, 0.0);
234 template <
class dataType>
242 template <
class dataType>
243 std::tuple<ftm::idNode, ftm::idNode>
251 template <
class dataType>
256 template <
class dataType>
258 std::tuple<dataType, dataType> birthDeath
260 return std::get<1>(birthDeath) - std::get<0>(birthDeath);
263 template <
class dataType>
273 dataType maxPers = std::numeric_limits<dataType>::lowest();
276 and this->
getNode(i)->getOrigin() == (
int)root)
282 template <
class dataType>
285 dataType pers = std::numeric_limits<dataType>::lowest();
291 if(not(nodeOrigin == root
292 and this->
getNode(nodeOrigin)->getOrigin() == (
int)i)) {
294 if(pers < nodePers) {
304 template <
class dataType>
310 template <
class dataType>
312 std::vector<std::tuple<idNode, idNode, dataType>> &pairs,
314 std::vector<idNode> nodes;
321 for(
auto node : nodes) {
324 std::make_tuple(node, this->
getNode(node)->getOrigin(), pers));
326 auto comp = [&](
const std::tuple<idNode, idNode, dataType> a,
327 const std::tuple<idNode, idNode, dataType> b) {
328 return std::get<2>(a) < std::get<2>(b);
330 sort(pairs.begin(), pairs.end(), comp);
333 template <
class dataType>
335 std::vector<idNode> multiPersOrigins;
337 std::vector<std::tuple<idNode, idNode, dataType>> pairs;
342 for(
auto pair : pairs) {
343 idNode const nodeBirth = std::get<0>(pair);
344 idNode const nodeDeath = std::get<1>(pair);
346 origins[nodeDeath].push_back(nodeBirth);
347 birthFound[nodeBirth] =
true;
350 for(
unsigned int i = 0; i < origins.size(); ++i)
352 for(
auto node : origins[i])
353 multiPersOrigins.push_back(node);
355 return multiPersOrigins;
361 template <
class dataType>
363 bool doPrint)
const {
365 std::stringstream ss;
375 template <
class dataType>
377 std::stringstream ss;
381 ss << mergedRootOrigin;
393 template <
class dataType>
395 bool doPrint)
const {
396 std::stringstream wholeSS;
397 std::streamsize
const sSize = std::cout.precision();
402 or (not printNodeAlone
405 std::stringstream ss;
406 ss << i <<
" _ " << std::setprecision(12)
410 wholeSS << ss.str() << std::endl;
415 std::cout.precision(sSize);
419 template <
class dataType>
422 bool doPrint)
const {
423 std::stringstream ss;
424 std::vector<std::tuple<idNode, idNode, dataType>> pairs;
426 ss <<
"size=" << pairs.size() << std::endl;
428 for(
auto pair : pairs) {
429 ss << std::get<0>(pair) <<
" ("
431 ss << std::get<1>(pair) <<
" ("
433 ss << std::get<2>(pair) << std::endl;
443 template <
class dataType>
445 bool useBD,
bool printPairs,
bool doPrint)
const {
446 std::vector<std::tuple<idNode, idNode, dataType>> pairs;
450 for(
auto pair : pairs) {
451 noOrigin[std::get<0>(pair)]++;
452 noMultiPers += (noOrigin[std::get<0>(pair)] > 1) ? 1 : 0;
453 noOrigin[std::get<1>(pair)]++;
454 noMultiPers += (noOrigin[std::get<1>(pair)] > 1) ? 1 : 0;
456 std::stringstream ss;
457 ss <<
"Number of multi pers pairs : " << noMultiPers << std::endl;
460 for(
auto node : multiPers)
461 ss << node << std::endl;
int printErr(const std::string &msg, const debug::LineMode &lineMode=debug::LineMode::NEW, std::ostream &stream=std::cerr) const
std::stringstream printMultiPersPairsFromTree(bool useBD=false, bool printPairs=true, bool doPrint=true) const
std::tuple< dataType, dataType > getMergedRootBirthDeath() const
Node * getNode(idNode nodeId) const
const scalarType & getValue(SimplexId nodeId) const
void getChildren(idNode nodeId, std::vector< idNode > &res) const
std::tuple< ftm::idNode, ftm::idNode > getBirthDeathNode(idNode nodeId) const
std::tuple< dataType, dataType > getBirthDeathNodeFromIds(idNode nodeId1, idNode nodeId2) const
std::stringstream printNode2(idNode nodeId, bool doPrint=true) const
idNode getNumberOfNodes() const
bool isParentInconsistent(ftm::idNode nodeId) const
bool verifyBranchDecompositionInconsistency() const
std::stringstream printTreeScalars(bool printNodeAlone=true, bool doPrint=true) const
idNode getLowestNode(idNode nodeStart) const
ftm::idNode getSecondMaximumPersistenceNode() const
idNode getParentSafe(idNode nodeId) const
std::vector< ftm::idNode > getMultiPersOrigins(bool useBD) const
idNode getMergedRootOrigin() const
dataType getMaximumPersistence() const
dataType getSecondMaximumPersistence() const
std::tuple< ftm::idNode, ftm::idNode > getMergedRootBirthDeathNode() const
void getLeavesFromTree(std::vector< idNode > &res) const
dataType getNodePersistence(idNode nodeId) const
std::stringstream printPairsFromTree(bool useBD=false, bool printPairs=true, bool doPrint=true) const
bool isNodeOriginDefined(idNode nodeId) const
bool isLeaf(idNode nodeId) const
std::tuple< dataType, dataType > getBirthDeathFromIds(idNode nodeId1, idNode nodeId2) const
bool isRoot(idNode nodeId) const
std::tuple< dataType, dataType > getBirthDeath(idNode nodeId) const
std::stringstream printMergedRoot(bool doPrint=true) const
bool isNodeIdInconsistent(idNode nodeId) const
bool isNodeAlone(idNode nodeId) const
void getPersistencePairsFromTree(std::vector< std::tuple< ftm::idNode, ftm::idNode, dataType > > &pairs, bool useBD) const
bool isImportantPair(idNode nodeId, double threshold, std::vector< double > &excludeLower, std::vector< double > &excludeHigher) const
dataType getBirth(idNode nodeId) const
SimplexId getOrigin() const
unsigned int idNode
Node index in vect_nodes_.
TTK base package defining the standard types.
printMsg(debug::output::BOLD+" | | | | | . \\ | | (__| | / __/| |_| / __/| (_) |"+debug::output::ENDCOLOR, debug::Priority::PERFORMANCE, debug::LineMode::NEW, stream)