OpenWalnut  1.5.0dev
Public Member Functions | Private Member Functions | Private Attributes | List of all members
WHtreeProcesser Class Reference

this class implements methods for dendrogram processing, such as pruning, node collapsing and decimation it operates over the class WHtree. More...

#include <WHtreeProcesser.h>

+ Collaboration diagram for WHtreeProcesser:

Public Member Functions

 WHtreeProcesser (WHtree *const tree)
 Constructor. More...
 
 ~WHtreeProcesser ()
 Destructor. More...
 
std::pair< size_t, size_t > pruneTree (float condition, size_t safeSize, const HTPROC_MODE pruneType)
 Prunes the tree according to the options specified. More...
 
std::pair< size_t, size_t > pruneRandom (const size_t numberPruned, unsigned int seed=0)
 Prunes the tree from randomly chosen leaves. More...
 
size_t collapseTree (const dist_t flatGap, const dist_t distLevelLimit, const bool keepBaseNodes)
 Collapses the nodes of the tree that have branch lenghts equal or lower to the one indicated. More...
 
size_t collapseTreeLinear (const dist_t coefficient, const bool keepBaseNodes)
 Collapses the nodes of the tree that have branch lenghts smoller than the distance level multiplied by the coefficient indicated. More...
 
size_t collapseTreeSquare (const dist_t coefficient, const bool keepBaseNodes)
 Collapses the nodes of the tree that have branch lenghts smoller than the squared distance level multiplied by the coefficient indicated. More...
 
size_t collapseBranch (const dist_t flatGap, const dist_t distLevelLimit, size_t root, const bool keepBaseNodes)
 Collapses the nodes of the subtree that have branch lenghts equal or lower to the one indicated. More...
 
size_t flattenSelection (const std::list< size_t > selection, const bool keepBaseNodes)
 Collapses all the nodes of the subtrees indicated (using only non-leaf node ID) More...
 
size_t flattenSelection (const std::vector< size_t > &selection, const bool keepBaseNodes)
 Collapses all the nodes of the subtrees indicated (using only non-leaf node ID) More...
 
size_t flattenSelection (const std::vector< nodeID_t > &selection, const bool keepBaseNodes)
 Collapses all the nodes of the subtrees indicated (using full boolean-integer node ID) More...
 
std::pair< size_t, size_t > pruneSelection (const std::vector< size_t > &selection)
 Prunes all of the subtrees indicated (using only non-leaf node ID) More...
 
std::pair< size_t, size_t > pruneSelection (const std::vector< nodeID_t > &selection)
 Prunes all of the subtrees indicated (using full boolean-integer node ID) More...
 
void flagSelection (const std::vector< size_t > &selection)
 set flags for pruning all of the subtrees indicated (using only non-leaf node ID) More...
 
void flagSelection (const std::vector< nodeID_t > &selection)
 set flags for pruning all of the subtrees indicated (using full boolean-integer node ID) More...
 
void flagLeaves (const std::vector< size_t > &selection)
 set flags for pruning all of the leaves indicated More...
 
void coarseTree (const unsigned int coarseRatio)
 Reduces the tree grid size by the ratio specified (as if it had been obtained from an image of lower resolution) More...
 
size_t baseNodes2Leaves ()
 converts the base nodes into leaves, pruning out all excess leaves and information More...
 
void forceMonotonicity (double errorMult=1)
 calls on private WHtree member to eliminate non monotonic steps in the tree while keeping as much information as possible. More...
 
void forceMonotonicityUp ()
 calls on private WHtree member to eliminate non monotonic steps in the tree bottom-up, lowering the level of children involved in the non-monotonic steps to the parent level More...
 
void forceMonotonicityDown ()
 calls on private WHtree member to eliminate non monotonic steps in the tree top-down, raising the level of parents involved in the non-monotonic steps to the children level More...
 
size_t debinarize (const bool keepBaseNodes)
 calls on private WHtree member to merge nodes joining binary at the same level into non-binary structures More...
 

Private Member Functions

size_t flattenBranch (size_t root, const bool keepBaseNodes)
 Collapses all the nodes of the subtree. More...
 
void collapseNode (const size_t thisNodeID, const dist_t coefficient, HTPROC_COLLAPSE collapseMode=HTPR_C_CONSTANT)
 eliminates branchings in the tree, raising them to the parent level More...
 
void collapseNode (const nodeID_t &thisNodeID, const dist_t coefficient, HTPROC_COLLAPSE collapseMode=HTPR_C_CONSTANT)
 eliminates non monotonic steps in the tree, raising them to the parent level More...
 

Private Attributes

WHtreem_tree
 tree object More...
 

Detailed Description

this class implements methods for dendrogram processing, such as pruning, node collapsing and decimation it operates over the class WHtree.

As a result of its operations the tree structure is changed and previous structure cannot be recovered unless a class copy is previously made.

Definition at line 83 of file WHtreeProcesser.h.

Constructor & Destructor Documentation

◆ WHtreeProcesser()

WHtreeProcesser::WHtreeProcesser ( WHtree *const  tree)
explicit

Constructor.

Parameters
treea pointer to the tree to be processed

Definition at line 60 of file WHtreeProcesser.cpp.

◆ ~WHtreeProcesser()

WHtreeProcesser::~WHtreeProcesser ( )

Destructor.

Definition at line 64 of file WHtreeProcesser.cpp.

Member Function Documentation

◆ baseNodes2Leaves()

size_t WHtreeProcesser::baseNodes2Leaves ( )

converts the base nodes into leaves, pruning out all excess leaves and information

Returns
new number of leaves of the tree

Definition at line 505 of file WHtreeProcesser.cpp.

References WHtree::cleanup(), WHtree::fetchLeaf(), WHtree::getLeaves4node(), WHtree::getNumLeaves(), WHtree::getRootBaseNodes(), m_tree, WHtree::m_treeName, WHnode::setFlag(), and WHtree::testRootBaseNodes().

+ Here is the call graph for this function:

◆ coarseTree()

void WHtreeProcesser::coarseTree ( const unsigned int  coarseRatio)

Reduces the tree grid size by the ratio specified (as if it had been obtained from an image of lower resolution)

Parameters
coarseRatiocoarsing ratio

Definition at line 410 of file WHtreeProcesser.cpp.

References WHtree::cleanup(), WHtree::debinarize(), WHtree::fetchLeaf(), WHtree::m_coordinates, WHtree::m_datasetSize, WHtree::m_discarded, m_tree, WHtree::m_treeName, WHcoord::m_x, WHcoord::m_y, WHcoord::m_z, WHnode::setFlag(), and string_utils::toString().

+ Here is the call graph for this function:

◆ collapseBranch()

size_t WHtreeProcesser::collapseBranch ( const dist_t  flatGap,
const dist_t  distLevelLimit,
size_t  root,
const bool  keepBaseNodes 
)

Collapses the nodes of the subtree that have branch lenghts equal or lower to the one indicated.

Parameters
flatGapbranch lenght limit to be collapsed
distLevelLimitdistance level under which no collapsing will take place
rootroot node of the subtree
keepBaseNodesflag to avoid collapsing base nodes (those that have only single-leaf children)
Returns
number of nodes eliminated

Definition at line 350 of file WHtreeProcesser.cpp.

References collapseNode(), WHtree::debinarize(), WHtree::getBranchNodes(), WHnode::getDistLevel(), WHtree::getNode(), and m_tree.

+ Here is the call graph for this function:

◆ collapseNode() [1/2]

void WHtreeProcesser::collapseNode ( const nodeID_t &  thisNodeID,
const dist_t  coefficient,
HTPROC_COLLAPSE  collapseMode = HTPR_C_CONSTANT 
)
private

eliminates non monotonic steps in the tree, raising them to the parent level

Parameters
thisNodeIDid of the sub-branch node where to start the flatteing
coefficientcoefficient for collapsing depending on distance level
collapseModecollapsing mode

Definition at line 661 of file WHtreeProcesser.cpp.

References collapseNode().

+ Here is the call graph for this function:

◆ collapseNode() [2/2]

void WHtreeProcesser::collapseNode ( const size_t  thisNodeID,
const dist_t  coefficient,
HTPROC_COLLAPSE  collapseMode = HTPR_C_CONSTANT 
)
private

eliminates branchings in the tree, raising them to the parent level

Parameters
thisNodeIDid of the sub-branch node where to start the flatteing
coefficientcoefficient for collapsing depending on distance level
collapseModecollapsing mode

Definition at line 674 of file WHtreeProcesser.cpp.

References WHtree::fetchNode(), WHnode::getChildren(), WHnode::getDistLevel(), WHnode::getFullID(), WHnode::getID(), WHtree::getNode(), WHtree::getRoot(), WHnode::isNode(), m_tree, and WHnode::setDistLevel().

Referenced by collapseBranch(), collapseNode(), collapseTree(), collapseTreeLinear(), collapseTreeSquare(), and flattenBranch().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ collapseTree()

size_t WHtreeProcesser::collapseTree ( const dist_t  flatGap,
const dist_t  distLevelLimit,
const bool  keepBaseNodes 
)

Collapses the nodes of the tree that have branch lenghts equal or lower to the one indicated.

Parameters
flatGapbranch lenght limit to be collapsed
distLevelLimitdistance level under which no collapsing will take place
keepBaseNodesflag to avoid collapsing base nodes (those that have only single-leaf children)
Returns
number of nodes eliminated

Definition at line 273 of file WHtreeProcesser.cpp.

References collapseNode(), WHtree::debinarize(), WHtree::forceMonotonicityDown(), WHnode::getDistLevel(), WHnode::getID(), WHtree::getNode(), WHtree::getRoot(), m_tree, and WHtree::m_treeName.

+ Here is the call graph for this function:

◆ collapseTreeLinear()

size_t WHtreeProcesser::collapseTreeLinear ( const dist_t  coefficient,
const bool  keepBaseNodes 
)

Collapses the nodes of the tree that have branch lenghts smoller than the distance level multiplied by the coefficient indicated.

Parameters
coefficientcoefficient for collapsing depending on distance level
keepBaseNodesflag to avoid collapsing base nodes (those that have only single-leaf children)
Returns
number of nodes eliminated

Definition at line 303 of file WHtreeProcesser.cpp.

References collapseNode(), WHtree::debinarize(), WHnode::getID(), WHtree::getRoot(), m_tree, and WHtree::m_treeName.

Referenced by WMHierchClustDisplay::moduleMain().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ collapseTreeSquare()

size_t WHtreeProcesser::collapseTreeSquare ( const dist_t  coefficient,
const bool  keepBaseNodes 
)

Collapses the nodes of the tree that have branch lenghts smoller than the squared distance level multiplied by the coefficient indicated.

Parameters
coefficientcoefficient for collapsing depending on distance level
keepBaseNodesflag to avoid collapsing base nodes (those that have only single-leaf children)
Returns
number of nodes eliminated

Definition at line 326 of file WHtreeProcesser.cpp.

References collapseNode(), WHtree::debinarize(), WHnode::getID(), WHtree::getRoot(), m_tree, and WHtree::m_treeName.

+ Here is the call graph for this function:

◆ debinarize()

size_t WHtreeProcesser::debinarize ( const bool  keepBaseNodes)

calls on private WHtree member to merge nodes joining binary at the same level into non-binary structures

Parameters
keepBaseNodesif set base nodes ( nodes with only single leaves as children) will not be merged
Returns
number of nodes collapsed

Definition at line 549 of file WHtreeProcesser.cpp.

References WHtree::debinarize(), and m_tree.

+ Here is the call graph for this function:

◆ flagLeaves()

void WHtreeProcesser::flagLeaves ( const std::vector< size_t > &  selection)

set flags for pruning all of the leaves indicated

Parameters
selectionvector with the leaves to be pruned

Definition at line 650 of file WHtreeProcesser.cpp.

References WHtree::fetchLeaf(), m_tree, and WHnode::setFlag().

Referenced by flagSelection().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ flagSelection() [1/2]

void WHtreeProcesser::flagSelection ( const std::vector< nodeID_t > &  selection)

set flags for pruning all of the subtrees indicated (using full boolean-integer node ID)

Parameters
selectionvector with the nodes to be pruned

Definition at line 641 of file WHtreeProcesser.cpp.

References flagLeaves(), WHtree::getLeaves4node(), and m_tree.

+ Here is the call graph for this function:

◆ flagSelection() [2/2]

void WHtreeProcesser::flagSelection ( const std::vector< size_t > &  selection)

set flags for pruning all of the subtrees indicated (using only non-leaf node ID)

Parameters
selectionvector with the nodes to be pruned

Definition at line 632 of file WHtreeProcesser.cpp.

References flagLeaves(), WHtree::getLeaves4node(), and m_tree.

Referenced by pruneSelection().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ flattenBranch()

size_t WHtreeProcesser::flattenBranch ( size_t  root,
const bool  keepBaseNodes 
)
private

Collapses all the nodes of the subtree.

Parameters
rootroot node of the subtree
keepBaseNodesif set base nodes ( nodes with only single leaves as children) will not be merged
Returns
number of nodes eliminated

Definition at line 557 of file WHtreeProcesser.cpp.

References collapseNode(), WHtree::debinarize(), and m_tree.

+ Here is the call graph for this function:

◆ flattenSelection() [1/3]

size_t WHtreeProcesser::flattenSelection ( const std::list< size_t >  selection,
const bool  keepBaseNodes 
)

Collapses all the nodes of the subtrees indicated (using only non-leaf node ID)

Parameters
selectionlist with the root nodes of the subtree
keepBaseNodesflag to avoid collapsing base nodes (those that have only single-leaf children)
Returns
number of nodes eliminated

Definition at line 567 of file WHtreeProcesser.cpp.

References WHtree::cleanup(), WHtree::fetchNode(), WHnode::getChildren(), WHnode::getHLevel(), WHtree::getNode(), m_tree, WHnode::setFlag(), and WHtree::testRootBaseNodes().

Referenced by flattenSelection(), and WMHierchClustDisplay::moduleMain().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ flattenSelection() [2/3]

size_t WHtreeProcesser::flattenSelection ( const std::vector< nodeID_t > &  selection,
const bool  keepBaseNodes 
)

Collapses all the nodes of the subtrees indicated (using full boolean-integer node ID)

Parameters
selectionvector with the root nodes of the subtree
keepBaseNodesflag to avoid collapsing base nodes (those that have only single-leaf children)
Returns
number of nodes eliminated

Definition at line 605 of file WHtreeProcesser.cpp.

References flattenSelection().

+ Here is the call graph for this function:

◆ flattenSelection() [3/3]

size_t WHtreeProcesser::flattenSelection ( const std::vector< size_t > &  selection,
const bool  keepBaseNodes 
)

Collapses all the nodes of the subtrees indicated (using only non-leaf node ID)

Parameters
selectionvector with the root nodes of the subtree
keepBaseNodesflag to avoid collapsing base nodes (those that have only single-leaf children)
Returns
number of nodes eliminated

Definition at line 600 of file WHtreeProcesser.cpp.

References flattenSelection().

+ Here is the call graph for this function:

◆ forceMonotonicity()

void WHtreeProcesser::forceMonotonicity ( double  errorMult = 1)

calls on private WHtree member to eliminate non monotonic steps in the tree while keeping as much information as possible.

it searches bottom-up for non-monotonic steps. When detected a corrected value for the parent node is computed this value consists of a average between the non-monotonic children levels weighted by their sizes in number of leaves and the parent level weighted by the sizes of the remaining monotonic children in orther to avoid infinite loops an error tolerance is included. default value is 1*E-5

Parameters
errorMultmultiplier to increase the base error tolerance (default value is 1 makign the tolerance 1*E-5, maximum value is 100 making the tolerance 1*E-3)

Definition at line 543 of file WHtreeProcesser.cpp.

References WHtree::forceMonotonicity(), and m_tree.

+ Here is the call graph for this function:

◆ forceMonotonicityDown()

void WHtreeProcesser::forceMonotonicityDown ( )

calls on private WHtree member to eliminate non monotonic steps in the tree top-down, raising the level of parents involved in the non-monotonic steps to the children level

Definition at line 537 of file WHtreeProcesser.cpp.

References WHtree::forceMonotonicityDown(), and m_tree.

+ Here is the call graph for this function:

◆ forceMonotonicityUp()

void WHtreeProcesser::forceMonotonicityUp ( )

calls on private WHtree member to eliminate non monotonic steps in the tree bottom-up, lowering the level of children involved in the non-monotonic steps to the parent level

Definition at line 531 of file WHtreeProcesser.cpp.

References WHtree::forceMonotonicityUp(), and m_tree.

+ Here is the call graph for this function:

◆ pruneRandom()

std::pair< size_t, size_t > WHtreeProcesser::pruneRandom ( const size_t  numberPruned,
unsigned int  seed = 0 
)

Prunes the tree from randomly chosen leaves.

Parameters
numberPrunednumber of leaves to be pruned
seedseed for the random number generator to choose the leaves to be pruned
Returns
pair with the number of nodes and leaves eliminated

Definition at line 235 of file WHtreeProcesser.cpp.

References WHtree::cleanup(), WHtree::debinarize(), WHtree::fetchLeaf(), WHtree::getNumLeaves(), WHnode::isFlagged(), m_tree, WHtree::m_treeName, WHnode::setFlag(), and string_utils::toString().

Referenced by WMHierchClustDisplay::moduleMain().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pruneSelection() [1/2]

std::pair< size_t, size_t > WHtreeProcesser::pruneSelection ( const std::vector< nodeID_t > &  selection)

Prunes all of the subtrees indicated (using full boolean-integer node ID)

Parameters
selectionvector with the nodes to be pruned
Returns
pair with the number of nodes and leaves eliminated

Definition at line 625 of file WHtreeProcesser.cpp.

References WHtree::cleanup(), flagSelection(), and m_tree.

+ Here is the call graph for this function:

◆ pruneSelection() [2/2]

std::pair< size_t, size_t > WHtreeProcesser::pruneSelection ( const std::vector< size_t > &  selection)

Prunes all of the subtrees indicated (using only non-leaf node ID)

Parameters
selectionvector with the nodes to be pruned
Returns
pair with the number of nodes and leaves eliminated

Definition at line 619 of file WHtreeProcesser.cpp.

References WHtree::cleanup(), flagSelection(), and m_tree.

Referenced by WMHierchClustDisplay::moduleMain().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pruneTree()

std::pair< size_t, size_t > WHtreeProcesser::pruneTree ( float  condition,
size_t  safeSize,
const HTPROC_MODE  pruneType 
)

Prunes the tree according to the options specified.

Parameters
conditionvalue of the condition to choose when pruning (size of joining cluster, size ratio or joining level)
safeSizemaximum size that a cluster can have in order to be pruned, bigger clusters wont be prune regardless of the condition
pruneTypetype of pruning method (max size, maxlevel, sizeratio)
Returns
pair with the number of nodes and leaves eliminated

Definition at line 72 of file WHtreeProcesser.cpp.

References WHtree::cleanup(), WHtree::debinarize(), WHtree::fetchNode(), WHnode::getChildren(), WHnode::getDistLevel(), WHtree::getNode(), WHtree::getNumLeaves(), WHnode::getSize(), WHnode::isFlagged(), WHtree::m_leaves, WHtree::m_nodes, m_tree, WHtree::m_treeName, WHnode::setFlag(), and string_utils::toString().

Referenced by WMHierchClustDisplay::moduleMain().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_tree

WHtree& WHtreeProcesser::m_tree
private

The documentation for this class was generated from the following files: