#include <CommonTools/Statistics/interface/PartitionGenerator.h>
Public Types | |
typedef std::vector< int > | Partition |
Public Member Functions | |
std::vector< Partition > | partitions (int collectionSize, int minCollectionSize=1) const |
Return partitions in a row. | |
std::vector< std::vector < Partition > > | sortedPartitions (int collectionSize, int minCollectionSize=1) const |
Return partitions ordered according to the number of subcollections they have. | |
Classes | |
class | LessCollections |
a private class just defining the () operator More... |
A Partition is a list of subcollection sizes that add up to 'collectionSize', ordered in decreasing order of subcollection size. No subcollection size is less than 'minCollectionSize'.
Definition at line 13 of file PartitionGenerator.h.
typedef std::vector<int> PartitionGenerator::Partition |
Definition at line 17 of file PartitionGenerator.h.
vector< PartitionGenerator::Partition > PartitionGenerator::partitions | ( | int | collectionSize, | |
int | minCollectionSize = 1 | |||
) | const |
Return partitions in a row.
Definition at line 8 of file PartitionGenerator.cc.
References edmNew::copy(), first, and edm::second().
Referenced by CombinationGenerator< T >::combinations(), and sortedPartitions().
00009 { 00010 00011 vector<Partition> partitions; 00012 00013 // at the very least, we have a single bag of size 'collectionSize' 00014 partitions.push_back( Partition(1, collectionSize) ); 00015 00016 int first = collectionSize - minCollectionSize, second = minCollectionSize; 00017 while( first >= second ) { 00018 // try to further divide the first 00019 vector<Partition> subPartitions = this->partitions(first, second); 00020 vector<Partition>::iterator isub; 00021 for( isub = subPartitions.begin(); isub != subPartitions.end(); isub++ ) { 00022 const Partition& sub = *isub; 00023 // reject subPartitions of first with a last element smaller than second 00024 if( sub.back() < second ) continue; 00025 Partition partition( sub.size()+1 ); 00026 copy( sub.begin(), sub.end(), partition.begin() ); 00027 partition[ partition.size()-1 ] = second; 00028 partitions.push_back( partition ); 00029 } 00030 first--; second++; 00031 } 00032 00033 return partitions; 00034 }
vector< vector< PartitionGenerator::Partition > > PartitionGenerator::sortedPartitions | ( | int | collectionSize, | |
int | minCollectionSize = 1 | |||
) | const |
Return partitions ordered according to the number of subcollections they have.
'sortedPartitions[N]' = list of partitions with N subcollections.
Definition at line 38 of file PartitionGenerator.cc.
References i, partitions(), and python::multivaluedict::sort().
Referenced by CombinationGenerator< T >::combinations().
00039 { 00040 00041 vector<Partition> partitions 00042 = this->partitions(collectionSize, minCollectionSize); 00043 sort (partitions.begin(), partitions.end(), LessCollections()); 00044 00045 vector< vector<Partition> > sortedPartitions; 00046 sortedPartitions.resize(partitions.rbegin()->size()); 00047 00048 for (vector<Partition>::const_iterator i = partitions.begin(); 00049 i != partitions.end(); i++) { 00050 sortedPartitions[(*i).size() - 1].push_back(*i); 00051 } 00052 00053 return sortedPartitions; 00054 }