LTI-Lib latest version v1.9 - last update 10 Apr 2010

lti::quickMedian2< T, U > Class Template Reference
[Basic Statistics]

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. More...

#include <ltiQuickMedian.h>

Inheritance diagram for lti::quickMedian2< T, U >:
Inheritance graph
[legend]
Collaboration diagram for lti::quickMedian2< T, U >:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 quickMedian2 ()
 quickMedian2 (const quickMedian2< T, U > &other)
virtual ~quickMedian2 ()
virtual const char * getTypeName () const
apply (vector< T > &keys, vector< U > &data) const
virtual functorclone () const

Protected Member Functions

findMedian (vector< T > &vct, vector< U > &data, const int &begin, const int &end, const int &medianPos) const
int partition (vector< T > &vct, vector< U > &data, const int &begin, const int &end) const

Detailed Description

template<class T, class U>
class lti::quickMedian2< T, U >

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 lti::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.

See also:
lti::quickMedian, lti::sort, lti::sort2

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.

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


Constructor & Destructor Documentation

template<class T, class U>
lti::quickMedian2< T, U >::quickMedian2 (  ) 

default constructor

template<class T, class U>
lti::quickMedian2< T, U >::quickMedian2 ( const quickMedian2< T, U > &  other  ) 

copy constructor

Parameters:
other the object to be copied
template<class T, class U>
virtual lti::quickMedian2< T, U >::~quickMedian2 (  )  [virtual]

destructor


Member Function Documentation

template<class T, class U>
T lti::quickMedian2< T, U >::apply ( vector< T > &  keys,
vector< U > &  data 
) const

operates on the given parameter.

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.

Parameters:
keys vector<T> with the key data. The median of this data is partially sorted while looking for the median.
data vector<U> 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.
Returns:
a the median value of keys.
template<class T, class U>
virtual functor* lti::quickMedian2< T, U >::clone (  )  const [virtual]

returns a pointer to a clone of this functor.

Reimplemented from lti::quickMedian< T >.

template<class T, class U>
T lti::quickMedian2< T, U >::findMedian ( vector< T > &  vct,
vector< U > &  data,
const int &  begin,
const int &  end,
const int &  medianPos 
) const [protected]

this method calculates the median in a recursively form

template<class T, class U>
virtual const char* lti::quickMedian2< T, U >::getTypeName (  )  const [virtual]

returns the name of this type ("quickMedian2")

Reimplemented from lti::quickMedian< T >.

template<class T, class U>
int lti::quickMedian2< T, U >::partition ( vector< T > &  vct,
vector< U > &  data,
const int &  begin,
const int &  end 
) const [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 documentation for this class was generated from the following file:

Generated on Sat Apr 10 15:28:38 2010 for LTI-Lib by Doxygen 1.6.1