CVR-Lib last update 20 Sep 2009

cvr::quickMedian Class Reference
[Statistics]

Quick median search. More...

#include <cvrQuickMedian.h>

Inheritance diagram for cvr::quickMedian:

Inheritance graph
[legend]
Collaboration diagram for cvr::quickMedian:

Collaboration graph
[legend]

List of all members.

Classes

class  parameters
 The parameters for the class quickMedian. More...

Public Member Functions

 quickMedian ()
 quickMedian (const parameters &param)
 quickMedian (const eMedianEvenCase medianEvenCase)
 quickMedian (const quickMedian &other)
virtual ~quickMedian ()
const std::string & name () const
template<typename T >
bool apply (matrix< T > &src, T &median) const
template<typename T >
bool apply (const matrix< T > &src, T &median) const
template<typename T >
bool apply (const matrix< T > &src, matrix< T > &dest, T &median) const
template<class V >
bool apply (V &srcdest, typename V::value_type &median) const
template<class V >
bool apply (const V &src, typename V::value_type &median) const
template<class V >
bool apply (const V &src, V &dest, typename V::value_type &median) const
template<class V >
V::value_type median (const V &src) const
quickMediancopy (const quickMedian &other)
virtual quickMedianclone () const
virtual quickMediannewInstance () const
const parametersgetParameters () const

Protected Member Functions

template<class V >
V::value_type findMedian (V &vct, const int begin, const int end, const int medianPos) const
template<class V >
int partition (V &vct, const int begin, const int end) const


Detailed Description

Quick median search.

This class is used to extract the median of the elements of a given vector or matrix. The median is defined as the element at the middle position of the sorted vector. The algorithm used is based on the quick sort. For vectors (or matrices) with an even number n of elements, the median will be the element at (n/2) or (n/2)-1 depending on the parameter settings.

On-place applies are in this implementation faster than on copy ones.

The type of the vector elements (T) must accept the operators < and >.


Constructor & Destructor Documentation

cvr::quickMedian::quickMedian (  ) 

Default constructor.

cvr::quickMedian::quickMedian ( const parameters param  ) 

Constructor to set parameters.

cvr::quickMedian::quickMedian ( const eMedianEvenCase  medianEvenCase  ) 

Constructor with indicator what to do for even-sized vectors.

cvr::quickMedian::quickMedian ( const quickMedian other  ) 

copy constructor

Parameters:
other the object to be copied

virtual cvr::quickMedian::~quickMedian (  )  [virtual]

destructor


Member Function Documentation

template<class V >
bool cvr::quickMedian::apply ( const V &  src,
V &  dest,
typename V::value_type &  median 
) const [inline]

Operates on the given parameter.

Parameters:
src vector with the source data.
dest the partially sorted vector. The elements at the first half of the vector are less or equal than the median and on the other half greater or equal.
median the median value
Returns:
true on success false otherwise

template<class V >
bool cvr::quickMedian::apply ( const V &  src,
typename V::value_type &  median 
) const [inline]

Operates on the given parameter.

Parameters:
src vector with the source data.
median the median value
Returns:
true on success false otherwise

template<class V >
bool cvr::quickMedian::apply ( V &  srcdest,
typename V::value_type &  median 
) const [inline]

Find the median of a vector type V, which can be an cvr::genericVector or its derived classes, or a std::vector.

In principle the container type V just needs to support:

  • the type definitions V::size_type and V::value_type,
  • the operator[] returning elements of type V::value_type
  • the V::value_type has to be comparable with the operator<.
  • the method empty()
  • the method size() returning a V::size_type

The resulting vector contains the elements less or equal than the median for the indexes x such that x < size()/2, and higher or equal otherwise.

Parameters:
srcdest vector<T> with the source data. The result will be left here too.
median the median value
Returns:
true on success false otherwise

template<typename T >
bool cvr::quickMedian::apply ( const matrix< T > &  src,
matrix< T > &  dest,
T &  median 
) const [inline]

Calculates the median of src, the result is left in dest.

The elements of the matrix will be considered as part of a vector with "columns()" times "rows()" elements.

Parameters:
src matrix<T> with the source data.
dest partially sorted matrix.
median the median value of the given matrix.
Returns:
true on success false otherwise

template<typename T >
bool cvr::quickMedian::apply ( const matrix< T > &  src,
T &  median 
) const [inline]

Calculates the median of the given matrix, which is NOT modified.

The elements of the matrix will be considered as part of a vector with "columns()" times "rows()" elements.

Parameters:
src matrix<T> with the source data.
median the median value of the given matrix.
Returns:
true on success false otherwise

template<typename T >
bool cvr::quickMedian::apply ( matrix< T > &  src,
T &  median 
) const [inline]

Calculates the median of the given matrix, which WILL BE modified.

The elements of the matrix will be considered as part of a vector with "columns()" times "rows()" elements.

Parameters:
src matrix<T> with the source data.
median the median value of the given matrix.
Returns:
true on success false otherwise

virtual quickMedian* cvr::quickMedian::clone (  )  const [virtual]

Returns a pointer to a clone of this functor.

Implements cvr::functor.

quickMedian& cvr::quickMedian::copy ( const quickMedian other  ) 

Copy data of "other" functor.

Parameters:
other the functor to be copied
Returns:
a reference to this functor object

template<class V >
V::value_type cvr::quickMedian::findMedian ( V &  vct,
const int  begin,
const int  end,
const int  medianPos 
) const [inline, protected]

This method calculates the median in a recursively form.

The template type V has to be a vector following an interface like the cvr::vector or the std::vector, implementing the operator[]

const parameters& cvr::quickMedian::getParameters (  )  const

Returns used parameters.

Reimplemented from cvr::parametersManager.

template<class V >
V::value_type cvr::quickMedian::median ( const V &  src  )  const [inline]

A shortcut function for apply(const vector<T>&, T&) const.

Note that internally another vector and T are used.

Parameters:
src vector whose median is sought
Returns:
the median of src

const std::string& cvr::quickMedian::name (  )  const [virtual]

Returns the name of this class.

Implements cvr::functor.

virtual quickMedian* cvr::quickMedian::newInstance (  )  const [virtual]

Returns a pointer to a new instance of this functor.

Implements cvr::functor.

template<class V >
int cvr::quickMedian::partition ( V &  vct,
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.

The template type V has to be a vector following an interface like the cvr::vector or the std::vector, implementing the operator[]


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

Generated on Sun Sep 20 22:09:02 2009 for CVR-Lib by Doxygen 1.5.8