UFO
|
Partitions an array into groups of elements equivalent according to certain criteria. More...
#include <RecursiveSplitter.h>
Classes | |
class | Group |
A range of indices of all array elements belonging to a particular equivalence class. More... | |
class | GroupIterator |
An iterator over all equivalence classes. More... | |
class | GroupRange |
A range of equivalence classes. More... | |
class | MultiElementGroupIterator |
An iterator over equivalence classes consisting of more than one element. More... | |
class | MultiElementGroupRange |
A range of equivalence classes consisting of more than one element. More... | |
Public Member Functions | |
RecursiveSplitter (size_t numIds) | |
Initialize partitioning of an array of numIds elements. More... | |
void | groupBy (const std::vector< size_t > &categories) |
Split existing equivalence classes according to a new criterion. More... | |
void | groupBy (const std::vector< int > &categories) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
void | groupBy (const std::vector< std::string > &categories) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
GroupRange | groups () const |
Return the range of equivalence classes. More... | |
MultiElementGroupRange | multiElementGroups () const |
Return the range of equivalence classes consisting of more than one element. More... | |
template<typename Compare > | |
void | sortGroupsBy (Compare comp) |
Sort the elements in each equivalence class in ascending order. More... | |
void | shuffleGroups (unsigned int seed) |
Randomly shuffle the elements of each equivalence class. More... | |
void | shuffleGroups () |
Randomly shuffle the elements of each equivalence class. More... | |
Private Member Functions | |
void | initializeEncodedGroups () |
template<typename T > | |
void | groupByImpl (const std::vector< T > &categories) |
Private Attributes | |
std::vector< size_t > | orderedIds_ |
Indices of elements of the partitioned array ordered by equivalence class. More... | |
std::vector< size_t > | encodedGroups_ |
Encoded locations of multi-element equivalence classes in orderedIds_. More... | |
Partitions an array into groups of elements equivalent according to certain criteria.
Output:
Definition at line 62 of file src/ufo/utils/RecursiveSplitter.h.
|
explicit |
Initialize partitioning of an array of numIds
elements.
Initially, all elements are assumed to belong to the same equivalence class.
Definition at line 18 of file RecursiveSplitter.cc.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 280 of file src/ufo/utils/RecursiveSplitter.h.
|
inline |
Split existing equivalence classes according to a new criterion.
categories | A vector assigning each element of the partitioned array to a unique category. |
Each existing equivalence class E consisting of N_E elements with indices E_i (0 <= i < N_E) is split into one or more classes according to the equivalence relation
E_i'th element is equivalent to E_j'th element if and only if categories[E_i] == categories[E_j].
Definition at line 275 of file src/ufo/utils/RecursiveSplitter.h.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 285 of file src/ufo/utils/RecursiveSplitter.h.
|
private |
|
inline |
Return the range of equivalence classes.
Definition at line 290 of file src/ufo/utils/RecursiveSplitter.h.
|
private |
|
inline |
Return the range of equivalence classes consisting of more than one element.
Definition at line 293 of file src/ufo/utils/RecursiveSplitter.h.
void ufo::RecursiveSplitter::shuffleGroups | ( | ) |
Randomly shuffle the elements of each equivalence class.
This overload uses the defaul seed.
Definition at line 87 of file RecursiveSplitter.cc.
void ufo::RecursiveSplitter::shuffleGroups | ( | unsigned int | seed | ) |
Randomly shuffle the elements of each equivalence class.
seed | Seed with which to initialise the random number generator used by the shuffling algorithm if this hasn't been done before (in a previous call to shuffleGroups() or another function calling util::shuffle()). |
Definition at line 77 of file RecursiveSplitter.cc.
void ufo::RecursiveSplitter::sortGroupsBy | ( | Compare | comp | ) |
Sort the elements in each equivalence class in ascending order.
The elements are compared using the binary comparison function comp
. This function needs to satisfy the same requirements as the comp
argument of std::sort().
Definition at line 329 of file src/ufo/utils/RecursiveSplitter.h.
|
private |
Encoded locations of multi-element equivalence classes in orderedIds_.
Definition at line 325 of file src/ufo/utils/RecursiveSplitter.h.
|
private |
Indices of elements of the partitioned array ordered by equivalence class.
Definition at line 323 of file src/ufo/utils/RecursiveSplitter.h.