last update 20 Sep 2009 |
#include <cvrQuickMedian2.h>
Public Member Functions | |
quickMedian2 () | |
quickMedian2 (const parameters ¶m) | |
quickMedian2 (const eMedianEvenCase medianEvenCase) | |
quickMedian2 (const quickMedian2 &other) | |
virtual | ~quickMedian2 () |
const std::string & | name () const |
virtual quickMedian2 * | clone () const |
virtual quickMedian2 * | newInstance () const |
const parameters & | getParameters () const |
template<class V , class W > | |
bool | apply (V &keys, W &data, typename V::value_type &median) const |
template<class V , class W > | |
bool | apply (V &keys, W &data) const |
Protected Member Functions | |
template<class V , class W > | |
V::value_type | findMedian (V &vct, W &data, const int begin, const int end, const int medianPos) const |
template<class V , class W > | |
int | partition (V &vct, W &data, const int begin, const int end) const |
This class is used to extract the median of the elements of a given vector or matrix, partitioning at the same time a second vector. The median is defined as the element at the middle position of the sorted vector. The algorithm used is based on the quick sort.
The difference with the cvr::quickMedian functor is that you can "sort" a second vector, which might contain for example the indices of the elements. This way, you can easily find out, which elements of the original vector are under the median, and which ones above.
The type of the vector elements (T) must accept the operators < and >.
cvr::quickMedian2::quickMedian2 | ( | ) |
Default constructor.
cvr::quickMedian2::quickMedian2 | ( | const parameters & | param | ) |
Constructor to set parameters.
cvr::quickMedian2::quickMedian2 | ( | const eMedianEvenCase | medianEvenCase | ) |
Constructor with indicator what to do for even-sized vectors.
cvr::quickMedian2::quickMedian2 | ( | const quickMedian2 & | other | ) |
virtual cvr::quickMedian2::~quickMedian2 | ( | ) | [virtual] |
Destructor.
bool cvr::quickMedian2::apply | ( | V & | keys, | |
W & | data | |||
) | const [inline] |
Operates on the given arguments.
Please note that the arguments will be both modified.
The resulting keys vector contains the elements less or equal than the median for the indexes x
such that x < size()/2
, and higher or equal otherwise.
Both vectors must have the same size.
keys | V with the key data. The median of this data is partially sorted while looking for the median. | |
data | W with data to be sorted the same way as the keys. You can for example use a ivector initialized with the index values (i.e. data(i)=i), so that after the apply method you can check which elements are below the median and which above. |
bool cvr::quickMedian2::apply | ( | V & | keys, | |
W & | data, | |||
typename V::value_type & | median | |||
) | const [inline] |
Operates on the given arguments.
Please note that the arguments will be both modified.
The resulting keys vector contains the elements less or equal than the median for the indexes x
such that x < size()/2
, and higher or equal otherwise.
Both vectors must have the same size.
The types V and W, can be an cvr::genericVector or its derived classes, or a std::vector. In principle the container type V,W just needs to support:
keys | vector with the key data. The median of this data is partially sorted while looking for the median. | |
data | vector with data to be sorted the same way as the keys. You can for example use a ivector initialized with the index values (i.e. data(i)=i), so that after the apply method you can check which elements are below the median and which above. | |
median | the median value of keys. |
virtual quickMedian2* cvr::quickMedian2::clone | ( | ) | const [virtual] |
V::value_type cvr::quickMedian2::findMedian | ( | V & | vct, | |
W & | data, | |||
const int | begin, | |||
const int | end, | |||
const int | medianPos | |||
) | const [inline, protected] |
this method calculates the median in a recursively form
const parameters& cvr::quickMedian2::getParameters | ( | ) | const |
const std::string& cvr::quickMedian2::name | ( | ) | const [virtual] |
virtual quickMedian2* cvr::quickMedian2::newInstance | ( | ) | const [virtual] |
int cvr::quickMedian2::partition | ( | V & | vct, | |
W & | data, | |||
const int | begin, | |||
const int | end | |||
) | const [inline, protected] |
this method chooses a pivot-value and ensures that lower values lie at the left and higher values at the right of its final position, which will be returned.