Changeset 1926


Ignore:
Timestamp:
Apr 30, 2009, 4:02:14 PM (12 years ago)
Author:
Peter
Message:

Ignoring zero weights in Percentiler so algorithm works also when {value=nan, weight=0}

Location:
branches/0.5-stable
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/0.5-stable/test/statistics_test.cc

    r1797 r1926  
    66  Copyright (C) 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér
    77  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
     8  Copyright (C) 2009 Peter Johansson
    89
    910  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    3334#include <cstdlib>
    3435#include <iostream>
     36#include <limits>
    3537#include <map>
    3638#include <vector>
     
    3840using namespace theplu::yat;
    3941void test_percentiler(test::Suite&);
     42void test_percentiler_nan(test::Suite&);
    4043
    4144template<typename RandomAccessIterator>
     
    7174  // testing percentile2
    7275  test_percentiler(suite);
     76
     77  // test weighted percentiler with NaNs
     78  test_percentiler_nan(suite);
    7379
    7480  double skewness_gsl=statistics::skewness(gsl_vec);
     
    144150}
    145151
     152void test_percentiler_nan(test::Suite& suite)
     153{
     154  using utility::DataWeight;
     155  std::vector<double> v;
     156  v.push_back(1);
     157  v.push_back(10);
     158  v.push_back(4);
     159  v.push_back(2);
     160  std::vector<DataWeight> wv(5);
     161  wv[0] = DataWeight(v[0]);
     162  wv[1] = DataWeight(v[1]);
     163  wv[2] = DataWeight(std::numeric_limits<double>::quiet_NaN(), 0.0);
     164  wv[3] = DataWeight(v[2]);
     165  wv[4] = DataWeight(v[3]);
     166
     167  cmp_percentiler(suite, v.begin(), v.end(), wv.begin(), wv.end());
     168}
     169
    146170template<typename RandomAccessIterator>
    147171void test_percentiler(test::Suite& suite,
  • branches/0.5-stable/yat/statistics/Percentiler.h

    r1797 r1926  
    66/*
    77  Copyright (C) 2008 Jari Häkkinen, Peter Johansson
     8  Copyright (C) 2009 Peter Johansson
    89
    910  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    184185    std::vector<utility::DataWeight> v_copy;
    185186    v_copy.reserve(last-first);
    186     std::copy(first, last, std::back_inserter(v_copy));
     187    utility::iterator_traits<RandomAccessIterator> traits;
     188    for ( ; first!=last; ++first)
     189      if (traits.weight(first)) // ignore zero weights
     190        v_copy.push_back(*first);
    187191    std::sort(v_copy.begin(), v_copy.end());
    188192    return calculate(v_copy.begin(), v_copy.end(), true, tag);
Note: See TracChangeset for help on using the changeset viewer.