Changeset 500


Ignore:
Timestamp:
Jan 28, 2006, 5:41:54 PM (17 years ago)
Author:
Peter
Message:

implemented median function for gslapi::vector

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

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/classifier/ConsensusInputRanker.cc

    r485 r500  
    4343        ranks[j]=input_rankers_[j].rank(i);
    4444      }
    45       medians[i].first = statistics::median(ranks);
     45      medians[i].first = statistics::median_TMP(ranks);
    4646      medians[i].second = i;
    4747    }
  • trunk/lib/statistics/WilcoxonFoldChange.cc

    r488 r500  
    3535    }
    3636    if (absolute_)
    37       return fabs(median(distance));
    38     return median(distance);
     37      return fabs(median_TMP(distance));
     38    return median_TMP(distance);
    3939  }
    4040
  • trunk/lib/statistics/utility.cc

    r464 r500  
    55
    66#include <gsl/gsl_randist.h>
    7 
     7#include <gsl/gsl_statistics_double.h>
    88
    99namespace theplu {
     
    1818  }
    1919
     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
    2034}} // of namespace statistics and namespace theplu
  • trunk/lib/statistics/utility.h

    r464 r500  
    33#ifndef _theplu_statistics_utility_
    44#define _theplu_statistics_utility_
     5
     6#include <c++_tools/gslapi/vector.h>
    57
    68#include <algorithm>
     
    3537  /// @return \a p'th percentile
    3638  ///
     39  /// @note interface will change
     40  ///
    3741  template <class T>
    38   double percentile(std::vector<T>& vec, double p)
     42  double percentile_TMP(std::vector<T>& vec, double p)
    3943  {
    4044    if (p==100)
     
    5256  /// values. @return median
    5357  ///
     58  /// @note interface will change
     59  ///
    5460  template <class T>
    55   inline double median(std::vector<T>& v) { return percentile(v,50.0); }
     61  inline double median_TMP(std::vector<T>& v) { return percentile_TMP(v,50.0); }
    5662
    57  
     63  ///
     64  /// Median is defined to be value in the middle. If number of values
     65  /// is even median is the average of the two middle values. If @a
     66  /// sorted is true, the function assumes vector @a vec to be
     67  /// sorted. If @a sorted is false, the vector is copied, the copy
     68  /// is sorted, and then used to calculate the median.
     69  ///
     70  /// @return median
     71  ///
     72  double median(const gslapi::vector& vec, const bool sorted=true);
     73
    5874}} // of namespace statistics and namespace theplu
    5975
  • trunk/test/statistics_test.cc

    r301 r500  
    1515  for (unsigned int i=0; i<10; i++)
    1616    data.push_back(static_cast<double>(i));
    17   double m=theplu::statistics::median(data);
     17  double m=theplu::statistics::median_TMP(data);
    1818  if (m!=4.5)
    1919    return -1;
Note: See TracChangeset for help on using the changeset viewer.