MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JonnyTools.h File Reference
#include <stdlib.h>

Go to the source code of this file.

Functions

int qsort_cmp (const void *x, const void *y)
 
double getPercentile (const double *array, size_t nel, double perc)
 

Function Documentation

double getPercentile ( const double *  array,
size_t  nel,
double  perc 
)

Definition at line 45 of file JonnyTools.h.

46 {
47  size_t lower_ind = floor(perc * (nel - 1));
48  size_t upper_ind = ceil(perc * (nel - 1));
49  double lambda = (perc * (nel - 1)) - lower_ind;
50  double lower_x = array[lower_ind];
51  double upper_x = array[upper_ind];
52  double percentile = (1 - lambda) * lower_x + lambda * upper_x;
53  // fprintf(stderr, "nel %d perc %f lower_ind %d upper_ind %d lambda %f lower_x %f upper_x %f percentile %f\n",
54  // nel, perc, lower_ind, upper_ind, lambda, lower_x, upper_x, percentile);
55  return percentile;
56 }
int qsort_cmp ( const void *  x,
const void *  y 
)

Definition at line 32 of file JonnyTools.h.

33 {
34  double xx = *(double*) x, yy = *(double*) y;
35  if (xx < yy) return -1;
36  if (xx > yy) return 1;
37  return 0;
38 }