source: trunk/lib/statistics/utility.cc @ 500

Last change on this file since 500 was 500, checked in by Peter, 16 years ago

implemented median function for gslapi::vector

changed sister function for std::vector to be named median_TMP because
the interface should be changed

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 899 bytes
Line 
1// $Id: utility.cc 500 2006-01-28 16:41:54Z peter $
2
3
4#include <c++_tools/statistics/utility.h>
5
6#include <gsl/gsl_randist.h>
7#include <gsl/gsl_statistics_double.h>
8
9namespace theplu {
10namespace statistics { 
11
12  double cdf_hypergeometric_P(u_int k, u_int n1, u_int n2, u_int t)
13  {
14    double p=0;
15    for (u_int i=0; i<=k; i++)
16      p+= gsl_ran_hypergeometric_pdf(i, n1, n2, t);
17    return p;
18  }
19
20  double median(const gslapi::vector& vec, const bool sorted)
21  {
22    if (!sorted){
23      gslapi::vector vec_copy(vec);
24      vec_copy.sort();
25      return gsl_stats_median_from_sorted_data (vec_copy.gsl_vector_p()->data, 
26                                                vec_copy.gsl_vector_p()->stride,
27                                                vec_copy.gsl_vector_p()->size);
28    }
29    return gsl_stats_median_from_sorted_data (vec.gsl_vector_p()->data, 
30                                              vec.gsl_vector_p()->stride,
31                                              vec.gsl_vector_p()->size);
32  }
33
34}} // of namespace statistics and namespace theplu
Note: See TracBrowser for help on using the repository browser.