22 namespace illumina {
namespace interop {
namespace util
35 template<
class T,
typename R,
typename P1=parameter_none_type>
65 const float ret =
static_cast<float>(
operator()(obj));
66 if(std::isnan(ret))
return val;
77 const double ret =
static_cast<double>(
operator()(obj));
78 if(std::isnan(ret))
return val;
89 return (obj.*m_function)(m_param1);
95 R (
T::*m_function )(P1)
const;
100 template<
class T,
typename R>
119 const F ret =
static_cast<F
>(
operator()(obj));
130 const float ret =
static_cast<float>(
operator()(obj));
131 if(std::isnan(ret))
return val;
142 const double ret =
static_cast<double>(
operator()(obj));
143 if(std::isnan(ret))
return val;
154 return (obj.*m_function)();
158 R (
T::*m_function )()
const;
163 template<
class T,
typename R,
typename P1=parameter_none_type>
181 return m_func(lhs) < m_func(rhs);
196 template<
class T,
typename R,
typename P2,
typename P1>
207 template<
class T,
typename R>
220 template<
class T,
typename R>
232 template<
class T,
typename R,
typename P2,
typename P1>
243 template<
class T,
typename R>
259 template<
typename F,
typename T>
262 return static_cast<F
>(val1 + val2);
279 template<
typename UnaryOp>
297 return !std::isnan(m_op(obj));
312 template<
typename I,
typename O,
typename F>
315 for (; beg != end; ++beg)
333 template<
typename I,
typename O,
typename F>
336 if (end == beg)
return;
337 for (--end; beg != end; --end)
346 if (beg == end)
return;
368 const size_t n =
static_cast<size_t>(std::distance(beg, end));
369 const size_t nth_index =
static_cast<size_t>(std::ceil(percentile * n / 100.0) - 1);
370 I nth_element_iterator = beg + nth_index;
371 std::nth_element(beg, nth_element_iterator, end);
372 return nth_element_iterator;
388 template<
typename I,
typename Compare>
392 const size_t n =
static_cast<size_t>(std::distance(beg, end));
393 const size_t nth_index =
static_cast<size_t>(std::ceil(percentile * n / 100.0) - 1);
394 I nth_element_iterator = beg + nth_index;
395 std::nth_element(beg, nth_element_iterator, end, comp);
396 return nth_element_iterator;
411 return y1 + (y2 - y1) / (x2 - x1) * (xt - x1);
421 template<
typename F,
typename I>
426 const size_t n =
static_cast<size_t>(std::distance(beg, end));
427 if (n == 0)
return std::numeric_limits<F>::quiet_NaN();
428 size_t nth_index = percentile * n / 100;
429 if ((n * percentile / 100.0f - nth_index) < 0.5f)
431 if (nth_index == 0)
return *beg;
434 if (nth_index >= (n - 1))
return *(end - 1);
435 const F y1 = *(beg + nth_index);
436 const F y2 = *(beg + nth_index + 1);
437 const F x1 = 100.0f * (nth_index + 0.5f) / n;
438 const F x2 = 100.0f * (nth_index + 0.5f + 1) / n;
449 template<
typename F,
typename I,
typename Op>
454 const size_t n =
static_cast<size_t>(std::distance(beg, end));
455 if (n == 0)
return std::numeric_limits<F>::quiet_NaN();
456 size_t nth_index = percentile * n / 100;
457 if ((n * percentile / 100.0f - nth_index) < 0.5f)
459 if (nth_index == 0)
return op(*beg);
462 if (nth_index >= (n - 1))
return op(*(end - 1));
463 const F y1 = op(*(beg + nth_index));
464 const F y2 = op(*(beg + nth_index + 1));
465 const F x1 = 100.0f * (nth_index + 0.5f) / n;
466 const F x2 = 100.0f * (nth_index + 0.5f + 1) / n;
478 template<
typename I,
typename UnaryOp>
507 template<
typename I,
typename Compare>
520 template<
typename F,
typename I>
523 std::stable_sort(beg, end);
524 return percentile_sorted<F>(beg, end, 50);
535 template<
typename F,
typename I,
typename Compare>
538 std::stable_sort(beg, end, comp);
539 return percentile_sorted<F>(beg, end, 50);
551 template<
typename F,
typename I,
typename Compare,
typename Op>
554 std::stable_sort(beg, end, comp);
555 return percentile_sorted<F>(beg, end, 50, op);
574 template<
typename R,
typename I,
typename BinaryOp>
579 for (; beg != end; ++beg)
582 if (std::isnan(val))
continue;
586 if (n == 0)
return std::numeric_limits<R>::quiet_NaN();
604 template<
typename R,
typename I,
typename BinaryOp>
610 for (; beg != end; ++beg)
612 const R val = op(*beg) - mean_val;
613 if (std::isnan(val))
continue;
618 if (n <= 1)
return std::numeric_limits<R>::quiet_NaN();
619 return (sum2 - sum3 * sum3 / n) / (n - 1);
635 template<
typename R,
typename I,
typename BinaryOp>
638 const R mean_val = nan_mean<R>(beg, end, op);
639 return nan_variance_with_mean<R>(beg, end, mean_val, op);
653 template<
typename R,
typename I,
typename BinaryOp>
654 R
mean(I beg, I end, BinaryOp op)
656 ptrdiff_t n = std::distance(beg, end);
657 if (n == 0)
return 0;
658 return std::accumulate(beg, end, R(0), op) / R(n);
673 template<
typename R,
typename I,
typename BinaryOp>
676 ptrdiff_t n = std::distance(beg, end);
679 for (; beg != end; ++beg)
681 const R val = op(*beg) - mean_val;
685 if (n <= 1)
return 0;
686 return (sum2 - sum3 * sum3 / n) / (n - 1);
700 template<
typename R,
typename I,
typename BinaryOp>
703 const R mean_val = mean<R>(beg, end, op);
704 return variance_with_mean<R>(beg, end, mean_val, op);
718 template<
typename R,
typename I>
734 template<
typename R,
typename I>
751 template<
typename R,
typename I>
Definition: enum_description.h:15
size_t operator()(const T &obj) const
Definition: statistics.h:295
double operator()(const double val, const T &obj) const
Definition: statistics.h:140
Definition: statistics.h:280
void outliers_upper(I beg, I end, const F bound, O out)
Definition: statistics.h:334
F operator()(const F val, const T &obj) const
Definition: statistics.h:117
nan_check(const UnaryOp &op)
Definition: statistics.h:286
void outliers_lower(I beg, I end, const F bound, O out)
Definition: statistics.h:313
Definition: statistics.h:164
double operator()(const double val, const T &obj) const
Definition: statistics.h:75
Definition: statistics.h:29
bool operator()(const T &lhs, const T &rhs) const
Definition: statistics.h:179
float operator()(const float val, const T &obj) const
Definition: statistics.h:63
F percentile_sorted(I beg, I end, const size_t percentile)
Definition: statistics.h:422
const_member_function_less_w< T, R, P1 > const_member_function_less(const P2 ¶m1, R(T::*func)(P1) const)
Definition: statistics.h:233
F operator()(const F val, const T &obj) const
Definition: statistics.h:53
float operator()(const float val, const T &obj) const
Definition: statistics.h:128
#define INTEROP_ASSERT(TST)
Definition: assert.h:21
const_member_function_w< T, R, P1 > const_member_function(const P2 ¶m1, R(T::*func)(P1) const)
Definition: statistics.h:197
I percentile(I beg, I end, const size_t percentile)
Definition: statistics.h:365
R variance(I beg, I end, BinaryOp op)
Definition: statistics.h:701
F median_interpolated(I beg, I end)
Definition: statistics.h:521
const_member_function_w(R(T::*func)() const)
Definition: statistics.h:107
I median(I beg, I end)
Definition: statistics.h:493
R operator()(const T &obj) const
Definition: statistics.h:87
F interpolate_linear(const F y1, const F y2, const F x1, const F x2, const F xt)
Definition: statistics.h:409
const T & operator()(const T &val)
Definition: statistics.h:271
dummy_arg()
Definition: statistics.h:188
R variance_with_mean(I beg, I end, const R mean_val, BinaryOp op)
Definition: statistics.h:674
const_member_function_less_w(const const_member_function_w< T, R, P1 > &func)
Definition: statistics.h:170
F operator()(const F val1, const T &val2)
Definition: statistics.h:260
R nan_variance_with_mean(I beg, I end, const R mean_val, BinaryOp op)
Definition: statistics.h:605
R mean(I beg, I end, BinaryOp op)
Definition: statistics.h:654
I remove_nan(I beg, I end, UnaryOp op)
Definition: statistics.h:479
const_member_function_w(P1 param1, R(T::*func)(P1) const)
Definition: statistics.h:43
Definition: statistics.h:188
R nan_variance(I beg, I end, BinaryOp op)
Definition: statistics.h:636
Definition: statistics.h:251
R operator()(const T &obj) const
Definition: statistics.h:152
R nan_mean(I beg, I end, BinaryOp op)
Definition: statistics.h:575
Definition: statistics.h:36