#ifndef pz_histogram_H #define pz_histogram_H /* Tools for generating histograms */ /* Last edited on 2008-02-08 12:39:06 by stolfi */ #include typedef struct pz_histogram_t { double lo; double hi; /* Values beyond this range are clipped. */ unsigned m; /* Number of bins. */ double_vec_t *c; /* The bins. */ double wxSum; double wSum; double wxxSum; } pz_histogram_t; /* A histogram with "m" equal-width bins. The entry "c[k]", for "k" in "[0..m-1]", is centered at "lo + k*(hi-lo)/(m-1)". */ pz_histogram_t *pz_histogram_new(double lo, double hi, unsigned m); /* A new histgram with "m" bins covering the range "[lo..hi]". */ void pz_histogram_add(pz_histogram_t *h, double x, double w); /* Adds observation "x" with weight "w" to the histogram "h". The old default for {w} was 1. */ void pz_histogram_output(FILE *wr, pz_histogram_t *h); /* Prints the histogram "h" to "wr", in four columns: lower limit of bin, center of bin, higher limit of bin, and bin count. Note that the two end bins actually extend to infinity, but their printed ranges have the same width at the other bins. */ double pz_histogram_avg(pz_histogram_t *h); double pz_histogram_var(pz_histogram_t *h); double pz_histogram_dev(pz_histogram_t *h); /* Average, variance, and standard deviation of the observations added to "h". */ #endif