| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

ModeFunctions Namespace Reference

ModeFunctions.h "ModeFunctions.h. More...


Functions

template<typename TYPE>
double shorth (TYPE start, TYPE stop)
 calculate the shorth the mean of the half sample
template<typename TYPE>
double LMS (TYPE start, TYPE stop)
 calculate the LMS average of the values of the half sample
template<typename TYPE>
std::pair< TYPE, TYPE > halfSample (TYPE start, TYPE stop)
 calculate the halfSample value of i for which distance x_i, x_i+h is minimum where h is the half sample
template<typename TYPE>
double halfSampleWidth (TYPE start, TYPE stop)
 calculate the halfSampleWidth size of the half sample
template<typename TYPE>
double generalizedMean (TYPE start, TYPE stop, double p=-0.5)
 Generalized Mean
template<typename TYPE>
std::pair< TYPE, TYPE > halfSample (TYPE start, TYPE stop)
 calculate the halfSample value of i for which distance x_i, x_i+h is minimum where h is the half sample
template<typename TYPE>
double halfSampleWidth (TYPE start, TYPE stop)
 calculate the halfSampleWidth size of the half sample
template<typename TYPE>
double shorth (TYPE start, TYPE stop)
 calculate the shorth the mean of the half sample
template<typename TYPE>
double LMS (TYPE start, TYPE stop)
 calculate the LMS average of the values of the half sample
template<typename TYPE>
double generalizedMean (TYPE start, TYPE stop, double power)
 Generalized Mean

Detailed Description

ModeFunctions.h "ModeFunctions.h.

namespace containing fuctions for getting robust estimate of the mode reasoanbly generic interface......

Author:
Matthew Needham Matthew.Needham@cern.ch


Function Documentation

template<typename TYPE>
double ModeFunctions::shorth ( TYPE  start,
TYPE  stop 
) [inline]

calculate the shorth the mean of the half sample

Parameters:
start beginning of sequence
stop end of sequence
Returns:
double shorth

Definition at line 96 of file ModeFunctions.h.

00096                                                         {
00097    // trivial cases
00098    if (start == stop) {
00099     return 0.0;
00100    }
00101    else if (stop - start == 1) {
00102      return *start;
00103    } 
00104    else if (stop - start == 2){
00105      return (*start + *(start+1))/2u;
00106    }
00107    std::pair<TYPE,TYPE> bestpos = halfSample(start,stop);
00108    const unsigned int halfSize = (unsigned int)((stop-start)/2u); 
00109     return std::accumulate(bestpos.first, bestpos.second,0.0)/double(halfSize);
00110 }

template<typename TYPE>
double ModeFunctions::LMS ( TYPE  start,
TYPE  stop 
) [inline]

calculate the LMS average of the values of the half sample

Parameters:
start beginning of sequence
stop end of sequence
Returns:
double LMS

Definition at line 113 of file ModeFunctions.h.

00113                                                      {
00114    // trivial cases
00115    if (start == stop) {
00116     return 0.0;
00117    }
00118    else if (stop - start == 1) {
00119      return *start;
00120    } 
00121    else if (stop - start == 2){
00122      return 0.5*(*start + *(start+1));
00123    }
00124 
00125    std::pair<TYPE,TYPE> bestPos = halfSample(start,stop);
00126    return 0.5* (*(bestPos.first) + *(bestPos.second));
00127 }

template<typename TYPE>
std::pair<TYPE,TYPE> ModeFunctions::halfSample ( TYPE  start,
TYPE  stop 
) [inline]

calculate the halfSample value of i for which distance x_i, x_i+h is minimum where h is the half sample

Parameters:
start beginning of sequence
stop end of sequence
Returns:
TYPE iterator for starting position

Definition at line 68 of file ModeFunctions.h.

00068                                                                         {
00069  const unsigned int halfSize = (unsigned int)((stop-start)/2u); 
00070  unsigned int pos = 0u;
00071  unsigned int bestpos = halfSize-1u;
00072  for (TYPE iter = start; iter != stop ; ++iter, ++pos){
00073    if (pos < halfSize){
00074     if (*(iter+halfSize) - *iter < *(start+bestpos+halfSize) - *(start+bestpos) ) { 
00075        bestpos = pos; 
00076      }
00077    }
00078  } //iter1 
00079  return std::make_pair(start+bestpos, start+bestpos+halfSize);
00080 }

template<typename TYPE>
double ModeFunctions::halfSampleWidth ( TYPE  start,
TYPE  stop 
) [inline]

calculate the halfSampleWidth size of the half sample

Parameters:
start beginning of sequence
stop end of sequence
Returns:
TYPE iterator for starting position

Definition at line 83 of file ModeFunctions.h.

00083                                                                  {
00084   // trivial cases
00085   if (start == stop){
00086     return 0.0;
00087   }
00088   else if (stop - start <= 2) {
00089     return 0.5* fabs(*start - *stop); 
00090   }
00091   std::pair<TYPE,TYPE> bestpos = halfSample(start,stop);
00092   return fabs(*bestpos.first - *bestpos.second);
00093 }

template<typename TYPE>
double ModeFunctions::generalizedMean ( TYPE  start,
TYPE  stop,
double  p = -0.5 
) [inline]

Generalized Mean

Parameters:
start beginning of sequence
stop end of sequence
power 
Returns:
double LMS

Definition at line 130 of file ModeFunctions.h.

00130                                                                                {
00131 
00132   double sum = 0.0; unsigned int size = 0u;
00133   for (TYPE iter = start; iter != stop; ++iter, ++size){
00134     if (power > 0.0){
00135       sum += pow(*iter,power);
00136     }
00137     else { 
00138       // we have to be careful if the data is zero
00139       double value = std::max(1e-5,fabs(*iter));
00140       sum +=pow(value,power);      
00141     }
00142   } // iter
00143   return size != 0u ?  pow(sum/double(size),1.0/power) : 0.0;
00144 }

template<typename TYPE>
std::pair<TYPE,TYPE> ModeFunctions::halfSample ( TYPE  start,
TYPE  stop 
) [inline]

calculate the halfSample value of i for which distance x_i, x_i+h is minimum where h is the half sample

Parameters:
start beginning of sequence
stop end of sequence
Returns:
TYPE iterator for starting position

Definition at line 68 of file ModeFunctions.h.

00068                                                                         {
00069  const unsigned int halfSize = (unsigned int)((stop-start)/2u); 
00070  unsigned int pos = 0u;
00071  unsigned int bestpos = halfSize-1u;
00072  for (TYPE iter = start; iter != stop ; ++iter, ++pos){
00073    if (pos < halfSize){
00074     if (*(iter+halfSize) - *iter < *(start+bestpos+halfSize) - *(start+bestpos) ) { 
00075        bestpos = pos; 
00076      }
00077    }
00078  } //iter1 
00079  return std::make_pair(start+bestpos, start+bestpos+halfSize);
00080 }

template<typename TYPE>
double ModeFunctions::halfSampleWidth ( TYPE  start,
TYPE  stop 
) [inline]

calculate the halfSampleWidth size of the half sample

Parameters:
start beginning of sequence
stop end of sequence
Returns:
TYPE iterator for starting position

Definition at line 83 of file ModeFunctions.h.

00083                                                                  {
00084   // trivial cases
00085   if (start == stop){
00086     return 0.0;
00087   }
00088   else if (stop - start <= 2) {
00089     return 0.5* fabs(*start - *stop); 
00090   }
00091   std::pair<TYPE,TYPE> bestpos = halfSample(start,stop);
00092   return fabs(*bestpos.first - *bestpos.second);
00093 }

template<typename TYPE>
double ModeFunctions::shorth ( TYPE  start,
TYPE  stop 
) [inline]

calculate the shorth the mean of the half sample

Parameters:
start beginning of sequence
stop end of sequence
Returns:
double shorth

Definition at line 96 of file ModeFunctions.h.

00096                                                         {
00097    // trivial cases
00098    if (start == stop) {
00099     return 0.0;
00100    }
00101    else if (stop - start == 1) {
00102      return *start;
00103    } 
00104    else if (stop - start == 2){
00105      return (*start + *(start+1))/2u;
00106    }
00107    std::pair<TYPE,TYPE> bestpos = halfSample(start,stop);
00108    const unsigned int halfSize = (unsigned int)((stop-start)/2u); 
00109     return std::accumulate(bestpos.first, bestpos.second,0.0)/double(halfSize);
00110 }

template<typename TYPE>
double ModeFunctions::LMS ( TYPE  start,
TYPE  stop 
) [inline]

calculate the LMS average of the values of the half sample

Parameters:
start beginning of sequence
stop end of sequence
Returns:
double LMS

Definition at line 113 of file ModeFunctions.h.

00113                                                      {
00114    // trivial cases
00115    if (start == stop) {
00116     return 0.0;
00117    }
00118    else if (stop - start == 1) {
00119      return *start;
00120    } 
00121    else if (stop - start == 2){
00122      return 0.5*(*start + *(start+1));
00123    }
00124 
00125    std::pair<TYPE,TYPE> bestPos = halfSample(start,stop);
00126    return 0.5* (*(bestPos.first) + *(bestPos.second));
00127 }

template<typename TYPE>
double ModeFunctions::generalizedMean ( TYPE  start,
TYPE  stop,
double  p = -0.5 
) [inline]

Generalized Mean

Parameters:
start beginning of sequence
stop end of sequence
power 
Returns:
double LMS

Definition at line 130 of file ModeFunctions.h.

00130                                                                                {
00131 
00132   double sum = 0.0; unsigned int size = 0u;
00133   for (TYPE iter = start; iter != stop; ++iter, ++size){
00134     if (power > 0.0){
00135       sum += pow(*iter,power);
00136     }
00137     else { 
00138       // we have to be careful if the data is zero
00139       double value = std::max(1e-5,fabs(*iter));
00140       sum +=pow(value,power);      
00141     }
00142   } // iter
00143   return size != 0u ?  pow(sum/double(size),1.0/power) : 0.0;
00144 }

| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:02:59 2011 for LHCbMath by doxygen 1.4.7