#include <SMS.h>
Public Types | |
enum | SMSType { None = 0, Interpolate = 1, Iterate = 2, Weighted = 4 } |
Public Member Functions | |
GlobalPoint | location (const std::vector< GlobalPoint > &) const |
GlobalPoint | location (const std::vector< std::pair< GlobalPoint, float > > &) const |
SMS (SMSType tp=(SMSType)(Interpolate|Iterate|Weighted), float q=0.5) | |
Private Attributes | |
float | theRatio |
SMSType | theType |
Class to compute the SMS location estimator The SMS estimator is the mean value of a set of observations with Small Median of Squared distances.
enum SMS::SMSType |
GlobalPoint SMS::location | ( | const std::vector< GlobalPoint > & | data | ) | const |
Definition at line 76 of file SMS.cc.
References PDRates::average, gather_cfg::cout, funct::D, i, Interpolate, Iterate, j, mag2(), python::multivaluedict::sort(), theRatio, theType, tmp, and Weighted.
Referenced by SmsModeFinder3d::operator()().
{ if ( theType & Weighted ) { std::cout << "[SMS] warning: Weighted SMS was asked for, but data are " << "weightless!" << std::endl; }; int nobs=data.size(); int nq=(int) ceil( theRatio*nobs); // cout << "nobs= " << nobs << " nq= " << nq << endl; // Compute distances std::vector<MyPair> pairs; for ( std::vector< GlobalPoint >::const_iterator i=data.begin(); i!=data.end() ; ++i ) { std::vector < float > D; // Compute squared distances to all points for ( std::vector< GlobalPoint >::const_iterator j=data.begin(); j!=data.end() ; ++j ) { D.push_back ( (*j - *i).mag2() ); } // Find q-quantile in each row of the distance matrix sort( D.begin(), D.end() ); MyPair tmp ( D[nq-1], &(*i) ); pairs.push_back ( tmp ); }; // Sort pairs by first element sort( pairs.begin(), pairs.end(), Sorter() ); if ( !(theType & SMS::Interpolate) && !(theType & SMS::Iterate) ) { // we dont interpolate, we dont iterate, so we can stop right here. // cout << "No interpolation, no iteration" << endl; return *(pairs.begin()->second); }; // we dont iterate, or we dont have anything to iterate (anymore?) // so we stop here // cout << "nobs= " << nobs << " nq= " << nq << endl; if (!(theType & SMS::Iterate) || nq<=2) return average ( pairs, nq ); // we iterate (recursively) std::vector < GlobalPoint > data1; std::vector<MyPair>::iterator j; for ( j=pairs.begin(); j-pairs.begin()<nq; ++j) data1.push_back(*(j->second)); return this->location( data1 ); }
GlobalPoint SMS::location | ( | const std::vector< std::pair< GlobalPoint, float > > & | ) | const |
float SMS::theRatio [private] |
Definition at line 36 of file SMS.h.
Referenced by location().
SMSType SMS::theType [private] |
Definition at line 35 of file SMS.h.
Referenced by location().