58 #include "core/common/WStringUtils.h"
60 #include "WHtreePartition.h"
76 std::vector< std::vector< size_t> >* partitionVectorPointer,
const bool verbose )
78 std::vector< float >& partitionValues = *partitionValuesPointer;
79 std::vector< std::vector< size_t> >& partitionVector = *partitionVectorPointer;
81 partitionValues.clear();
82 partitionVector.clear();
84 size_t match250( 0 ), mismatch250( 0 ), match500( 0 ), mismatch500( 0 ), match1000( 0 ), mismatch1000( 0 );
85 size_t match2000( 0 ), mismatch2000( 0 ), match5000( 0 ), mismatch5000( 0 );
88 std::vector< size_t > currentPartition, lastPartition;
94 std::vector< nodeID_t > firstKids( treeRoot.
getChildren() );
95 for(
size_t i = 0; i < firstKids.size(); ++i )
98 if( firstKids[i].first )
100 currentPartition.push_back( firstKids[i].second );
106 partitionValues.push_back( currentValue );
107 partitionVector.push_back( currentPartition );
110 lastPartition = currentPartition;
113 std::cout <<
"Step: " << 0 <<
". Current partition size: " << currentPartition.size() <<
". Current value: " << currentValue << std::flush;
121 std::cout <<
"\rStep: " << stepNr <<
". Current partition size: ";
122 std::cout << currentPartition.size() <<
". Current value: ";
123 std::cout << currentValue <<
" " << std::flush;
125 std::vector<float> currentLevels;
126 currentLevels.reserve( currentPartition.size() );
127 size_t highestLevelindex( 0 );
128 for(
size_t i = 0; i < currentPartition.size(); ++i )
131 if( currentLevels[i] > currentLevels[highestLevelindex] )
133 highestLevelindex = i;
137 lastPartition = currentPartition;
139 std::vector< std::vector< size_t > > derivedPartitionSet;
140 std::vector< std::vector< unsigned int > > derivedIndexes(
m_tree.
getBranching( currentPartition, levelDepth, &derivedPartitionSet ) );
142 std::vector< double > derivedPartitionValues( derivedPartitionSet.size(), -1 );
143 bool stopLoop(
true );
146 #pragma omp parallel for schedule( guided )
147 for(
size_t i = 0; i < derivedPartitionSet.size(); ++i )
164 size_t bestPartitionIndex( 0 );
165 float bestValue( -1 );
166 for(
size_t j = 0; j < derivedPartitionValues.size(); ++j )
169 if( derivedPartitionValues[j] > bestValue )
171 bestValue = derivedPartitionValues[j];
172 bestPartitionIndex = j;
176 unsigned int firstBranchIndex( derivedIndexes[bestPartitionIndex].front() );
179 if( derivedIndexes[bestPartitionIndex].size() == 1 )
182 currentPartition = derivedPartitionSet[bestPartitionIndex];
186 size_t nextBestIndex( 0 );
187 bool notFound(
true );
189 for(
size_t j = 0; j < derivedIndexes.size(); ++j )
191 if( ( derivedIndexes[j].size() == 1 ) && ( derivedIndexes[j].front() == firstBranchIndex ) )
200 throw std::runtime_error(
"ERROR @ partitionMatcher::findMatchingPartitions(): best match index not found" );
203 currentPartition = derivedPartitionSet[nextBestIndex];
204 currentValue = derivedPartitionValues[nextBestIndex];
208 partitionValues.push_back( currentValue );
209 partitionVector.push_back( currentPartition );
212 std::vector< nodeID_t > partHozFullID;
214 std::vector< size_t > partHoz;
215 partHoz.reserve( partHozFullID.size() );
216 for(
size_t i = 0; i < partHozFullID.size(); ++i )
218 if( partHozFullID[i].first )
220 partHoz.push_back( partHozFullID[i].second );
224 std::vector< size_t > currentCopy( currentPartition );
225 std::sort( partHoz.begin(), partHoz.end() );
226 std::sort( currentCopy.begin(), currentCopy.end() );
230 bool matchcondition( partHoz == currentCopy );
233 if( currentPartition.size() <= 250 )
244 if( currentPartition.size() <= 500 )
255 if( currentPartition.size() <= 1000 )
266 if( currentPartition.size() <= 2000 )
277 if( currentPartition.size() <= 5000 )
292 std::cout << std::endl;
297 std::cout <<
"Are partition decisions the same as in horizontal partitioning???" << std::endl;
298 std::cout <<
"250 % match: " << ( match250*100.0 )/( match250+mismatch250 );
299 std::cout <<
". Total matches: " << match250 <<
". fails: " << mismatch250 << std::endl;
300 std::cout <<
"500 % match: " << ( match500*100.0 )/( match500+mismatch500 );
301 std::cout <<
". Total matches: " << match500 <<
". fails: " << mismatch500 << std::endl;
302 std::cout <<
"1000 % match: " << ( match1000*100.0 )/( match1000+mismatch1000 );
303 std::cout <<
". Total matches: " << match1000 <<
". fails: " << mismatch1000 << std::endl;
304 std::cout <<
"2000 % match: " << ( match2000*100.0 )/( match2000+mismatch2000 );
305 std::cout <<
". Total matches: " << match2000 <<
". fails: " << mismatch2000 << std::endl;
306 std::cout <<
"5000 % match: " << ( match5000*100.0 )/( match5000+mismatch5000 );
307 std::cout <<
". Total matches: " << match5000 <<
". fails: " << mismatch5000 << std::endl;
317 std::vector< std::vector< size_t> >* partitionVectorPointer,
320 std::vector< float >& partitionValues = *partitionValuesPointer;
321 std::vector< std::vector< size_t> >& partitionVector = *partitionVectorPointer;
323 partitionValues.clear();
324 partitionVector.clear();
326 std::vector< size_t > currentPartition, lastPartition;
332 std::vector< nodeID_t > firstKids( treeRoot.
getChildren() );
333 for(
size_t i = 0; i < firstKids.size(); ++i )
336 if( firstKids[i].first )
338 currentPartition.push_back( firstKids[i].second );
344 partitionValues.push_back( currentValue );
345 partitionVector.push_back( currentPartition );
348 lastPartition = currentPartition;
351 std::cout <<
"Step: " << 0 <<
". Current partition size: " << currentPartition.size() <<
". Current value: " << currentValue << std::flush;
355 size_t partSizeCounter( currentPartition.size() );
356 size_t lastSize( currentPartition.size() );
358 while( partSizeCounter <= 5000 )
362 std::cout <<
"\rStep: " << stepNr <<
". Current partition size: ";
363 std::cout << currentPartition.size() <<
". Current value: ";
364 std::cout << currentValue <<
" " << std::flush;
366 std::vector<nodeID_t> partHozFullID;
368 currentPartition.clear();
369 currentPartition.reserve( partHozFullID.size() );
370 for(
size_t i = 0; i < partHozFullID.size(); ++i )
372 if( partHozFullID[i].first )
374 currentPartition.push_back( partHozFullID[i].second );
379 partitionValues.push_back( currentValue );
380 partitionVector.push_back( currentPartition );
381 partSizeCounter = currentPartition.size();
383 if( lastSize == partSizeCounter )
388 lastSize = partSizeCounter;
393 std::cout << std::endl;
403 std::vector< float > *partValPoint,
404 std::vector< std::vector< size_t> > *partVectorPoint )
406 std::vector< float > &partValues( *partValPoint );
407 std::vector< std::vector< size_t> > &partVector( *partVectorPoint );
409 std::vector< float > filteredValues;
410 std::vector< std::vector< size_t> > filteredPartitions;
412 size_t partCount( 0 ), bestIndex( 0 );
413 float bestValue( -1 );
415 for(
size_t i = 0; i < partValues.size(); ++i )
418 std::vector< float > currentValues;
419 currentValues.reserve( 1+ ( 2*filterRadius ) );
420 size_t jDownLimit( ( i > filterRadius ) ? ( i - filterRadius ) : 0 );
421 size_t jUpLimit( std::min( i + filterRadius + 1, partValues.size() ) );
424 size_t centreIndex( 0 );
425 for(
size_t j = jDownLimit; j < jUpLimit; ++j )
429 centreIndex = currentValues.size();
431 currentValues.push_back( partValues[j] );
435 if( std::max_element( currentValues.begin(), currentValues.end() ) == ( currentValues.begin() + centreIndex ) )
437 filteredValues.push_back( partValues[i] );
438 filteredPartitions.push_back( partVector[i] );
440 if( partValues[i] > bestValue )
442 bestValue = partValues[i];
443 bestIndex = partCount;
450 partValues.swap( filteredValues );
451 partVector.swap( filteredPartitions );
459 const std::vector< float > &partitionValues,
460 const std::vector< std::vector< size_t> > &patitionVector )
462 std::ofstream partFile( partFileName.c_str() );
465 std::cerr <<
"ERROR: unable to open out file: \"" << partFileName <<
"\"" << std::endl;
471 partFile <<
"#value size" << std::endl;
473 for(
size_t i = 0; i < partitionValues.size(); ++i )
475 partFile << partitionValues[i] <<
" " << patitionVector[i].size() << std::endl;
487 std::vector<nodeID_t> partFullID;
488 partFullID.reserve( partition.size() );
489 for(
size_t i = 0; i < partition.size(); ++i )
491 partFullID.push_back( std::make_pair(
true, partition[i] ) );
508 std::vector<nodeID_t> partFullID;
509 partFullID.reserve( partition.size() );
510 for(
size_t i = 0; i < partition.size(); ++i )
512 partFullID.push_back( std::make_pair(
true, partition[i] ) );
521 double spreadSum( 0 );
524 for(
size_t i = 0; i < partition.size(); ++i )
538 double part1( sizeSum/partition.size() );
539 double part2( sepSum/spreadSum );
541 return ( part1*part2 );
547 std::vector<nodeID_t> partFullID;
548 partFullID.reserve( partition.size() );
549 for(
size_t i = 0; i < partition.size(); ++i )
551 partFullID.push_back( std::make_pair(
true, partition[i] ) );
557 double diffSqSum( 0 ), sizeSum( 0 );
558 for(
size_t i = 0; i < partition.size() - 1; ++i )
561 for(
size_t j = i+1; j < partition.size(); ++j )
564 double sizeDif( size1 - size2 );
565 diffSqSum += sizeDif*sizeDif;
570 double M( partition.size() * ( partition.size() -1 ) / 2.0 );
571 return std::make_pair( sizeSum/partition.size(), diffSqSum/M );
576 std::vector<nodeID_t> partFullID;
577 partFullID.reserve( partition.size() );
578 for(
size_t i = 0; i < partition.size(); ++i )
580 partFullID.push_back( std::make_pair(
true, partition[i] ) );
587 double iaDistSum( 0 );
588 for(
size_t i = 0; i < partition.size(); ++i )
593 return iaDistSum/partition.size();
599 std::vector<nodeID_t> partFullID;
600 partFullID.reserve( partition.size() );
601 for(
size_t i = 0; i < partition.size(); ++i )
603 partFullID.push_back( std::make_pair(
true, partition[i] ) );
609 double iaWDistSum( 0 );
611 for(
size_t i = 0; i < partition.size(); ++i )
617 return iaWDistSum/sizeSum;
622 std::vector<nodeID_t> partFullID;
623 partFullID.reserve( partition.size() );
624 for(
size_t i = 0; i < partition.size(); ++i )
626 partFullID.push_back( std::make_pair(
true, partition[i] ) );
633 double iaDistSum( 0 );
634 for(
size_t i = 0; i < partition.size(); ++i )
640 return iaDistSum/partition.size();
646 std::vector<nodeID_t> partFullID;
647 partFullID.reserve( partition.size() );
648 for(
size_t i = 0; i < partition.size(); ++i )
650 partFullID.push_back( std::make_pair(
true, partition[i] ) );
656 double iaDistSum( 0 ), sizeSum( 0 );
657 for(
size_t i = 0; i < partition.size(); ++i )
660 size_t thisSize( thisNode.
getSize() );
665 return iaDistSum/sizeSum;
673 const bool excludeLeaves,
const size_t root )
const
678 std::cerr <<
"ERROR @ WHtree::partitionClassic(): branch root ID is out of boundaries (ID: "
683 std::list<nodeID_t> worklist;
684 std::list<nodeID_t> storelist;
685 worklist.push_back( std::make_pair(
true, root ) );
686 float currentValue( 0 );
688 bool loopCondition(
true );
694 if( condition == HTC_CNUM )
708 std::cerr <<
"ERROR @ WHtree::partitionClassic(): mode not recognized " << std::endl;
716 loopCondition = ( currentValue >
compValue );
719 loopCondition = ( worklist.size() + storelist.size() <
compValue );
722 std::cerr <<
"ERROR @ WHtree::partitionClassic(): condition not recognized " << std::endl;
727 while( loopCondition )
730 worklist.pop_front();
731 std::vector<nodeID_t> kids( current.
getChildren() );
732 for(
size_t i = 0; i < kids.size(); ++i )
737 storelist.push_back( thisKid.
getFullID() );
739 else if( thisKid.
getHLevel() == 1 && excludeLeaves )
741 storelist.push_back( thisKid.
getFullID() );
745 worklist.push_back( thisKid.
getFullID() );
749 if( worklist.empty() )
766 currentValue = currentNode.
getSize();
781 loopCondition = ( currentValue >
compValue );
784 loopCondition = ( worklist.size() + storelist.size() <
compValue );
791 storelist.insert( storelist.end(), worklist.begin(), worklist.end() );
799 if( !currentNode.
isRoot() )
809 output = currentValue;
812 output = currentValue;
819 partition->reserve( storelist.size() );
820 for( std::list<nodeID_t>::iterator it( storelist.begin() ); it != storelist.end(); ++it )
822 partition->push_back( *it );
829 const bool excludeLeaves,
const size_t root,
const size_t levelDepth )
const
831 std::cout <<
"DEBUG. level depth: " << levelDepth << std::endl;
834 size_t OPTPARTLIMIT = 500;
839 std::cerr <<
"ERROR @ WHtree::partitionOptimized(): branch root ID is out of boundaries (ID: "
844 std::vector< nodeID_t > bestPartition;
845 float condValue( 0 );
847 bestPartition.push_back( currentNode.
getFullID() );
849 bool loopCondition(
true );
860 if( condition == HTC_CNUM )
868 std::cout <<
"DEBUG: Spread-Separation" << std::endl;
871 if( condition == HTC_CNUM )
877 partition->push_back( currentNode.
getFullID() );
889 loopCondition = ( condValue >
compValue );
892 std::cout <<
"DEBUG: by clust num" << std::endl;
893 loopCondition = ( bestPartition.size() <
compValue );
899 while( loopCondition )
901 std::vector< std::vector< nodeID_t > > derivedPartitionSet;
902 std::vector< std::vector< unsigned int > > derivedIndexes(
m_tree.
getBranching( bestPartition,
904 &derivedPartitionSet,
906 std::vector< float > derivedPartitionValues;
907 float bestValue( 0 );
916 derivedPartitionValues.assign( derivedPartitionSet.size(), std::numeric_limits< double >::max() );
917 bestValue = std::numeric_limits< double >::max();
922 derivedPartitionValues.assign( derivedPartitionSet.size(), -1 );
929 bool stopLoop(
true );
932 #pragma omp parallel for schedule( guided )
933 for(
size_t i = 0; i < derivedPartitionSet.size(); ++i )
958 derivedPartitionValues[i] = (
evalPartOptimal( derivedPartitionSet[i] ) );
972 size_t bestPartIndex( 0 );
973 for(
size_t i = 0; i < derivedPartitionValues.size(); ++i )
980 if( derivedPartitionValues[i] < bestValue )
982 bestValue = derivedPartitionValues[i];
989 if( derivedPartitionValues[i] > bestValue )
991 bestValue = derivedPartitionValues[i];
1001 if( derivedIndexes[bestPartIndex].size() == 1 )
1004 bestPartition = derivedPartitionSet[bestPartIndex];
1008 unsigned int firstBranchIndex( derivedIndexes[bestPartIndex].front() );
1010 size_t nextBestIndex( 0 );
1011 bool notFound(
true );
1013 for(
size_t j = 0; j < derivedIndexes.size(); ++j )
1015 if( ( derivedIndexes[j].size() == 1 ) && ( derivedIndexes[j].front() == firstBranchIndex ) )
1024 throw std::runtime_error(
"ERROR @ partitionMatcher::findMatchingPartitions(): best match index not found" );
1027 bestPartition = derivedPartitionSet[nextBestIndex];
1028 bestValue = derivedPartitionValues[nextBestIndex];
1042 condValue = bestValue;
1052 if( bestPartition.size() > OPTPARTLIMIT )
1054 loopCondition =
false;
1064 loopCondition = ( condValue <
compValue );
1067 loopCondition = ( condValue >
compValue );
1075 loopCondition = ( bestPartition.size() <
compValue );
1084 std::sort( bestPartition.begin(), bestPartition.end() );
1085 *partition = bestPartition;
1091 std::vector<nodeID_t>* partition,
1092 const bool excludeLeaves,
1094 const bool normalized )
const
1097 float longestBranch( 0 );
1101 std::cerr <<
"ERROR @ WHtree::partitionSharp(): branch root ID is out of boundaries (ID: "
1106 std::list<nodeID_t> worklist;
1107 std::list<nodeID_t> storelist;
1109 worklist.push_back( std::make_pair(
true, root ) );
1110 while( !worklist.empty() )
1113 worklist.pop_front();
1114 std::vector<nodeID_t> kids( current.
getChildren() );
1115 for(
size_t i = 0; i < kids.size(); ++i )
1125 storelist.push_back( thisKid.
getFullID() );
1126 if( branchValue > longestBranch )
1128 longestBranch = branchValue;
1135 else if( thisKid.
getHLevel() == 1 && excludeLeaves )
1141 worklist.push_back( thisKid.
getFullID() );
1147 partition->reserve( storelist.size() );
1148 for( std::list<nodeID_t>::iterator it( storelist.begin() ); it != storelist.end(); ++it )
1150 partition->push_back( *it );
1152 return longestBranch;
1159 float longestGap( 0 );
1163 std::cerr <<
"ERROR @ WHtree::partitionSmooth(): branch root ID is out of boundaries (ID: "
1174 for(
size_t i = 0; i < bases.size(); ++i )
1176 conditionMet[bases[i]] = 1;
1187 conditionMet[dad.
getID()] = 1;
1196 for(
size_t i = 0; i < conditionMet.size(); ++i )
1200 if( conditionMet[i] == 1 )
1211 if( gap > longestGap )
1215 conditionMet[dad.
getID()] = 1;
1218 else if( conditionMet[i] == 0 )
1221 for(
size_t j = 0; j < kids.size(); ++j )
1225 if( conditionMet[kids[j].second] == 1 )
1227 conditionMet[kids[j].second] = 2;
1234 std::cerr <<
"ERROR @ WHtree::partitionSmooth()" << std::endl;
1238 for(
size_t i = 0; i < conditionMet.size(); ++i )
1240 if( conditionMet[i] == 2 )
1245 std::sort( partition->begin(), partition->end() );
1253 size_t branchPos, std::vector<size_t> branch,
1254 std::vector< std::vector< dist_t > > oldMatrix )
1256 std::vector< std::vector< dist_t > >newMatrix;
1257 newMatrix.reserve( oldPartition.size() + branch.size() );
1260 if( oldMatrix.empty() )
1262 for(
size_t i = 0; i < oldPartition.size(); ++i )
1264 std::vector< dist_t > newLine;
1265 newLine.reserve( i );
1266 for(
size_t j = 0; j < i; ++j )
1270 newMatrix.push_back( newLine );
1275 for(
size_t i = 0; i < oldPartition.size(); ++i )
1280 newMatrix.push_back( oldMatrix[i] );
1283 else if( i == branchPos )
1285 for(
size_t j = 0; j < branch.size(); ++j )
1287 std::vector< float > newLine( oldMatrix[branchPos] );
1289 newLine.insert( newLine.end(), extra.begin(), extra.end() );
1290 newMatrix.push_back( newLine );
1295 std::vector< float > newLine( oldMatrix[i] );
1296 std::vector< float >::iterator insertPoint( newLine.begin() + branchPos );
1297 std::vector< float > extra( branch.size()-1, *insertPoint );
1298 newLine.insert( insertPoint, extra.begin(), extra.end() );
1299 newMatrix.push_back( newLine );
1309 if( partition.size() != icdMatrix.size() )
1311 std::cerr <<
"ERROR: matrix size: " << icdMatrix.size() <<
". PArtition size: " << partition.size() << std::endl;
1312 throw std::runtime_error(
" ERROR @ WHtreePartition::evalPartitInterD(): partition and icd matrix dimensions dont match" );
1315 double irDistSum( 0 );
1317 for(
size_t i = 0; i < partition.size(); ++i )
1319 if( icdMatrix[i].size() != i )
1321 std::cerr <<
"ERROR: matrix row " << i <<
" size: " << icdMatrix[i].size() << std::endl;
1322 throw std::runtime_error(
" ERROR @ WHtreePartition::evalPartitInterD(): matrix has wrong dimensions" );
1324 for(
size_t j = 0; j < i; ++j )
1326 dist_t ieDist( icdMatrix[i][j] );
1327 irDistSum += ieDist;
1330 double M( partition.size() * ( partition.size() -1 ) / 2.0 );
1337 if( partition.size() != icdMatrix.size() )
1339 std::cerr <<
"ERROR: matrix size: " << icdMatrix.size() <<
". PArtition size: " << partition.size() << std::endl;
1340 throw std::runtime_error(
" ERROR @ WHtreePartition::evalPartitInterD(): partition and icd matrix dimensions dont match" );
1343 double irDistSum( 0 ), sizeSum( 0 );
1345 for(
size_t i = 0; i < partition.size(); ++i )
1348 size_t sizeI( nodeI.
getSize() );
1349 if( icdMatrix[i].size() != i )
1351 std::cerr <<
"ERROR: matrix row " << i <<
" size: " << icdMatrix[i].size() << std::endl;
1352 throw std::runtime_error(
" ERROR @ WHtreePartition::evalPartitInterD(): matrix has wrong dimensions" );
1354 for(
size_t j = 0; j < i; ++j )
1357 size_t sizeJ( nodeJ.
getSize() );
1358 dist_t ieDist( icdMatrix[i][j] );
1359 irDistSum += ieDist * ( sizeI+sizeJ );
1360 sizeSum += sizeI+sizeJ;
1364 return irDistSum/sizeSum;
1370 std::vector<nodeID_t>& partition( *partitionPointer );
1372 std::vector<size_t> partitionst;
1374 partition.reserve( partitionst.size() );
1376 for(
size_t i = 0; i < partitionst.size(); ++i )
1378 partition.push_back( std::make_pair(
true, partitionst[i] ) );
1385 std::vector<size_t>& partition( *partitionPointer );
1391 for(
size_t i = 0; i < baseNodes.size(); ++i )
1393 if( checkvector[ baseNodes[i] ] )
1401 partition.push_back( baseNodes[i] );
1402 checkvector[ baseNodes[i] ] =
true;
1406 partition.push_back( parent );
1407 checkvector[ parent ] =
true;
1410 for(
size_t j = 0; j < kids.size(); ++j )
1414 checkvector[ kids[j].second ] =
true;
this class implements a hierarchical tree node with several relevant attributes
size_t getSize() const
returns number of elements contained by the node
bool isLeaf() const
returns true if object is a leaf
size_t getHLevel() const
returns maximum number of nodes between the node and a leaf element
bool isRoot() const
returns true if object is the root of the tree
size_t getID() const
returns node/leaf ID
dist_t getDistLevel() const
returns distance level at which the element was formed
nodeID_t getFullID() const
returns full ID
nodeID_t getParent() const
returns parent ID
std::vector< nodeID_t > getChildren() const
returns a vector with the ids of the children of that node
std::pair< float, float > evalPartClustSizeDiff(const std::vector< size_t > &partition) const
Evaluate partition cluster size difference (using only non-leaf node ID)
void writePartitionSet(std::string partFileName, const std::vector< float > &partitionValues, const std::vector< std::vector< size_t > > &patitionVector)
write a set of partitions and their quality values to a text file
WHtreePartition(WHtree *const tree)
Constructor.
float evalSSindex(const std::vector< size_t > &partition) const
Evaluate spread-separation index for selected partition (using only non-leaf node ID)
float evalPartInterDist(const std::vector< size_t > &partition, const std::vector< std::vector< dist_t > > &icdMatrix) const
Evaluate full inter cluster distance factor for selected partition (DEPRECATED)
void scanOptimalPartitions(const size_t levelDepth, std::vector< float > *partitionValuesPointer, std::vector< std::vector< size_t > > *patitionVectorPointer, const bool verbose=false)
Obtain the partition quality values for the optimized (inter vs weighted intra cluster distance) part...
size_t filterMaxPartitions(const unsigned int filterRadius, std::vector< float > *partValPoint, std::vector< std::vector< size_t > > *partVectorPoint)
Filter a set of partitions across granularity levels in orther to keep only local maxima within a cer...
float evalPartOptimal(const std::vector< size_t > &partition) const
Evaluate partition quality: spread-separation index (using only non-leaf node ID)
float evalPartIntraDist(const std::vector< size_t > &partition) const
Evaluate intra cluster distance factor for selected partition (using only non-leaf node ID)
float evalPartIntraDistWeighted(const std::vector< size_t > &partition) const
Evaluate weighted intra cluster distance factor for selected partition (using only non-leaf node ID)
std::vector< std::vector< dist_t > > getICDmatrix(const std::vector< size_t > &oldPartition, size_t branchPos=0, std::vector< size_t > branch=std::vector< size_t >(), std::vector< std::vector< dist_t > > oldMatrix=std::vector< std::vector< dist_t > >())
Obtain pairwise intercluster distance matrix for the selected partition, or derive new icd matrix fro...
float evalPartInterDistWeighted(const std::vector< size_t > &partition, const std::vector< std::vector< dist_t > > &icdMatrix) const
Evaluate full weighted inter cluster distance factor for selected partition (DEPRECATED)
float partitionClassic(float compValue, std::vector< nodeID_t > *const partition, const HT_PARTMODE mode, const HT_CONDITION condition, const bool excludeLeaves, const size_t root) const
Gets a classic partition for the tree (those where clusters are further subdivided until a condition ...
void level2granularity(std::vector< nodeID_t > *partition) const
obtain the partition corresponding to the second lowest level of granularity of a tree (using full bo...
float evalPartBranchDistWeighted(const std::vector< size_t > &partition) const
Evaluate approximated weighted inter cluster distance factor for selected partition (using only non-l...
float partitionSharp(const float compValue, std::vector< nodeID_t > *const partition, const bool excludeLeaves, const size_t root, const bool normalized) const
Finds clusters with sharp boundaries (long branches) the tree.
float evalPartBranchDist(const std::vector< size_t > &partition) const
Evaluate approximated inter cluster distance factor for selected partition (using only non-leaf node ...
WHtree & m_tree
tree object
float partitionOptimized(float compValue, std::vector< nodeID_t > *const partition, const HT_PARTMODE2 mode, const HT_CONDITION condition, const bool excludeLeaves, const size_t root, const size_t levelDepth) const
Gets an optimized partition for the tree (those where a partition characteristic must be cosnidered f...
float partitionSmooth(const float compValue, std::vector< nodeID_t > *const partition, const bool excludeLeaves, const size_t root) const
Finds regions without sharp inner boundaries the tree.
~WHtreePartition()
Destructor.
void scanHozPartitions(std::vector< float > *partitionValuesPointer, std::vector< std::vector< size_t > > *patitionVectorPointer, const bool verbose=false)
Obtain the partition quality values for the classic partitions at each granulairty of the tree.
this class implements a hierarchical tree and provides functions for creation, partitioning,...
std::vector< size_t > getRootBaseNodes() const
returns a vector with all the nodes that have direct link to leaves from the main root
const WHnode & getRoot() const
returns a const reference to the root node
size_t getCommonAncestor(const size_t nodeID1, const size_t nodeID2) const
retrieves the the first common ancestor node of two given nodes
std::vector< size_t > getBaseNodes(const size_t root) const
returns a vector with all the nodes that have direct link to leaves fro the indicated subtree
size_t getNumNodes() const
Returns the number of nodes of the tree.
const WHnode & getNode(const nodeID_t &thisNode) const
returns a const pointer to the node indicated by the ID
const WHnode & getLeaf(const size_t thisLeaf) const
returns a const pointer to the leaf indicated by the ID
void sortByHLevel(std::vector< size_t > *const nodeVector) const
Reorders the nodes in the vector according to their hierarchical level.
void sortBySize(std::vector< size_t > *const nodeVector) const
Reorders the nodes in the vector according to their size.
size_t getNumLeaves() const
Returns the number of leaves of the tree.
std::vector< std::vector< unsigned int > > getBranching(const std::vector< nodeID_t > &thisPartition, size_t depthLevel, std::vector< std::vector< nodeID_t > > *partitionSet, const bool excludeLeaves)
gets all possble sets of sub-partitions in a tree given an initial partition and a depth level (where...
implements a compare operator for clusters, depending on custom value of the cluster