52 #ifndef __PCL_RobustChauvenetRejection_h
53 #define __PCL_RobustChauvenetRejection_h
58 #include <pcl/Diagnostics.h>
124 return m_rejectionLimit;
133 PCL_PRECONDITION( r > 0 && r < 1 )
134 m_rejectionLimit =
Range( r, 0.0F, 1.0F );
154 return m_largeSampleSize;
163 m_largeSampleSize =
Max( 1, n );
216 template <
class C,
typename I>
221 j = I( data.Length() );
223 for (
int phase = 0; phase < 3; ++phase )
229 mean =
Median( data.At( i ), data.At( j ) );
230 sigma = LineFitDeviation( data, i, j, mean );
233 mean =
Median( data.At( i ), data.At( j ) );
234 sigma = SampleDeviation( data, i, j, mean );
237 mean =
Mean( data.At( i ), data.At( j ) );
238 sigma =
StdDev( data.At( i ), data.At( j ), mean );
242 if ( 1 + sigma == 1 )
249 if ( n <= I( m_largeSampleSize ) + I( m_largeSampleSize >> 1 ) )
254 double d0 = n*QF( (mean - data[i])/sigma );
255 double d1 = n*QF( (data[j-1] - mean)/sigma );
256 if ( d0 >= m_rejectionLimit )
257 if ( d1 >= m_rejectionLimit )
269 int nc =
RoundInt(
double( n )/m_largeSampleSize );
271 for (
int it = 0; it < nc && n*QF( (mean - data[i])/sigma ) < m_rejectionLimit; ++i, ++c, ++it ) {}
272 for (
int it = 0; it < nc && n*QF( (data[j-1] - mean)/sigma ) < m_rejectionLimit; --j, ++c, ++it ) {}
287 template <
class C,
typename I>
288 void operator()( I& i, I& j,
double& mean,
double& sigma, C& data )
const
290 return PerformRejection( i, j, mean, sigma, data );
295 float m_rejectionLimit = 0.5;
296 int m_largeSampleSize = 20000;
302 static double QF(
double x )
311 template <
typename I>
312 static double FN( I N )
314 return 1/(1 - 2.9442*
Pow(
double( N ), -1.073 ));
320 template <
class C,
typename I>
321 static double SampleDeviation(
const C& R, I i, I j,
double m )
323 int N = int( j - i );
327 for (
int k = 0; i < j; ++i, ++k )
328 D[k] =
Abs(
double( R[i] ) - m );
336 template <
class C,
typename I>
337 static double LineFitDeviation(
const C& R, I i, I j,
double m )
339 int N = int( j - i );
340 int n = int( 0.683*N + 0.317 );
342 return SampleDeviation( R, i, j, m );
346 for ( I ii = i; ii < j; ++ii, ++k )
347 y[k] =
Abs(
double( R[ii] ) - m );
349 y =
Vector( y.Begin(), n );
352 for (
int i = 0; i < n; ++i )
358 s = FN( N ) * f( 1.0 );
360 s = SampleDeviation( R, i, j, m );
Fundamental numeric constants.
static constexpr T sqrt2()
Robust Chauvenet outlier rejection algorithm.
RobustChauvenetRejection(const RobustChauvenetRejection &)=default
virtual ~RobustChauvenetRejection()
void SetLargeSampleSize(int n)
void PerformRejection(I &i, I &j, double &mean, double &sigma, C &data) const
void SetRejectionLimit(float r)
RobustChauvenetRejection()=default
float RejectionLimit() const
int LargeSampleSize() const
void operator()(I &i, I &j, double &mean, double &sigma, C &data) const
64-bit floating point real vector.
Complex< T1 > Pow(const Complex< T1 > &c, T2 x) noexcept
T Abs(const Complex< T > &c) noexcept
constexpr T ErfInv(T x) noexcept
constexpr T Erf(T x) noexcept
int RoundInt(T x) noexcept
int TruncInt(T x) noexcept
RI Select(RI i, RI j, distance_type k)
double StdDev(const T *__restrict__ i, const T *__restrict__ j, double center) noexcept
double Mean(const T *__restrict__ i, const T *__restrict__ j) noexcept
double Median(const T *__restrict__ i, const T *__restrict__ j)
constexpr const T & Range(const T &x, const T &a, const T &b) noexcept
constexpr const T & Max(const T &a, const T &b) noexcept