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 {
45 threshold = rootPers * threshold;
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;
63 nodeId, threshold, excludeLower, excludeHigher);
66 template <
class dataType>
70 dataType parentBirth = std::get<0>(parentBirthDeath);
71 dataType parentDeath = std::get<1>(parentBirthDeath);
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();
94 std::vector<idNode> children;
96 for(
idNode const child : children)
105 template <
class dataType>
107 dataType maxPers = std::numeric_limits<dataType>::lowest();
112 and this->
getNode(j)->getOrigin() == (
int)root) {
114 if(nodePers > maxPers) {
123 template <
class dataType>
125 idNode lowestNode = nodeStart;
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();
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>
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>
166 auto nodeBirth = (nodeValue < node2Value ? nodeId1 : nodeId2);
167 auto nodeDeath = (nodeValue < node2Value ? nodeId2 : nodeId1);
168 return std::make_tuple(nodeBirth, nodeDeath);
171 template <
class dataType>
172 std::tuple<dataType, dataType>
177 nodeId, this->
getNode(nodeId)->getOrigin());
179 return std::make_tuple(0.0, 0.0);
182 template <
class dataType>
183 std::tuple<ftm::idNode, ftm::idNode>
187 nodeId, this->
getNode(nodeId)->getOrigin());
189 return std::make_tuple(0.0, 0.0);
192 template <
class dataType>
200 template <
class dataType>
201 std::tuple<ftm::idNode, ftm::idNode>
209 template <
class dataType>
214 template <
class dataType>
216 std::tuple<dataType, dataType> birthDeath
218 return std::get<1>(birthDeath) - std::get<0>(birthDeath);
221 template <
class dataType>
231 dataType maxPers = std::numeric_limits<dataType>::lowest();
234 and this->
getNode(i)->getOrigin() == (
int)root)
240 template <
class dataType>
243 dataType pers = std::numeric_limits<dataType>::lowest();
249 if(not(nodeOrigin == root
250 and this->
getNode(nodeOrigin)->getOrigin() == (
int)i)) {
252 if(pers < nodePers) {
262 template <
class dataType>
268 template <
class dataType>
270 std::vector<std::tuple<idNode, idNode, dataType>> &pairs,
272 std::vector<idNode> nodes;
279 for(
auto node : nodes) {
282 std::make_tuple(node, this->
getNode(node)->getOrigin(), pers));
284 auto comp = [&](
const std::tuple<idNode, idNode, dataType> a,
285 const std::tuple<idNode, idNode, dataType> b) {
286 return std::get<2>(a) < std::get<2>(b);
288 sort(pairs.begin(), pairs.end(), comp);
291 template <
class dataType>
293 std::vector<idNode> multiPersOrigins;
295 std::vector<std::tuple<idNode, idNode, dataType>> pairs;
300 for(
auto pair : pairs) {
301 idNode const nodeBirth = std::get<0>(pair);
302 idNode const nodeDeath = std::get<1>(pair);
304 origins[nodeDeath].push_back(nodeBirth);
305 birthFound[nodeBirth] =
true;
308 for(
unsigned int i = 0; i < origins.size(); ++i)
310 for(
auto node : origins[i])
311 multiPersOrigins.push_back(node);
313 return multiPersOrigins;
319 template <
class dataType>
321 bool doPrint)
const {
323 std::stringstream ss;
333 template <
class dataType>
335 std::stringstream ss;
339 ss << mergedRootOrigin;
351 template <
class dataType>
353 bool doPrint)
const {
354 std::stringstream wholeSS;
355 std::streamsize
const sSize = std::cout.precision();
360 or (not printNodeAlone
363 std::stringstream ss;
364 ss << i <<
" _ " << std::setprecision(12)
368 wholeSS << ss.str() << std::endl;
373 std::cout.precision(sSize);
377 template <
class dataType>
380 bool doPrint)
const {
381 std::stringstream ss;
382 std::vector<std::tuple<idNode, idNode, dataType>> pairs;
384 ss <<
"size=" << pairs.size() << std::endl;
386 for(
auto pair : pairs) {
387 ss << std::get<0>(pair) <<
" ("
389 ss << std::get<1>(pair) <<
" ("
391 ss << std::get<2>(pair) << std::endl;
401 template <
class dataType>
403 bool useBD,
bool printPairs,
bool doPrint)
const {
404 std::vector<std::tuple<idNode, idNode, dataType>> pairs;
408 for(
auto pair : pairs) {
409 noOrigin[std::get<0>(pair)]++;
410 noMultiPers += (noOrigin[std::get<0>(pair)] > 1) ? 1 : 0;
411 noOrigin[std::get<1>(pair)]++;
412 noMultiPers += (noOrigin[std::get<1>(pair)] > 1) ? 1 : 0;
414 std::stringstream ss;
415 ss <<
"Number of multi pers pairs : " << noMultiPers << std::endl;
418 for(
auto node : multiPers)
419 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
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)