Debian Codegraph @

hmmer/easel/esl_histogram.h

raw symbols SCIP
1 /* Collection and display of score histograms.
2 *
3 * SRE, Fri Jul 1 13:22:45 2005 [St. Louis]
4 */
5 #ifndef eslHISTOGRAM_INCLUDED
6 #define eslHISTOGRAM_INCLUDED
7 #include <esl_config.h>
8
9 #include <math.h> /* floor() is in one of the macros */
10
11
12 /* Structure: ESL_HISTOGRAM
13 *
14 * Keeps a score histogram, in which scores are counted into bins of
15 * size (width) w.
16 * histogram starts at bmin < floor(xmin/w) * w
17 * histogram ends at bmax >= ceil(xmax/w)*w
18 * nb = (bmax-bmin)/w
19 * each score x is counted into bin b = nb - (int) (bmax-x)/w
20 * each bin b contains scores bw+bmin < x <= (b+1)w + bmin
21 *
22 * Anything having to do with the counts themselves (obs, n, etc)
23 * is a uint64_t, with range 0..2^64-1 (up to 2e19).
24 */
25 typedef struct {
26 /* The histogram is kept as counts in fixed-width bins.
27 */
28 uint64_t *obs; /* observed counts in bin b, 0..nb-1 (dynamic) */
29 int nb; /* number of bins */
30 double w; /* fixed width of each bin */
31 double bmin, bmax; /* histogram bounds: all x satisfy bmin < x <= bmax */
32 int imin, imax; /* smallest, largest bin that contain obs[i] > 0 */
33
34 /* Optionally, in a "full" h, we can also keep all the raw samples in x.
35 */
36 double xmin, xmax; /* smallest, largest sample value x observed */
37 uint64_t n; /* total number of raw data samples */
38 double *x; /* optional: raw sample values x[0..n-1] */
39 uint64_t nalloc; /* current allocated size of x */
40
41 /* The binned data might be censored (either truly, or virtually).
42 * This information has to be made available to a binned/censored
43 * parameter fitting function, and to goodness-of-fit tests.
44 */
45 double phi; /* censoring value; all x_i > phi */
46 int cmin; /* smallest bin index that contains uncensored data */
47 uint64_t z; /* # of censored values <= phi */
48 uint64_t Nc; /* # samples in complete data (including unobs) */
49 uint64_t No; /* # of samples in observed data */
50
51 /* Expected binned counts are set by SetExpect() or SetExpectedTail().
52 */
53 double *expect; /* expected counts in bin b, 0..nb-1 (not resized) */
54 int emin; /* smallest bin index that contains expected counts */
55 double tailbase; /* for tail fits: fitted x > tailbase */
56 double tailmass; /* for tail fits: fractional prob in the tail */
57
58 /* Some status flags
59 */
60 int is_full; /* TRUE when we're keeping raw data in x */
61 int is_done; /* TRUE if we prevent more Add()'s */
62 int is_sorted; /* TRUE if x is sorted smallest-to-largest */
63 int is_tailfit; /* TRUE if expected dist only describes tail */
64 int is_rounded; /* TRUE if values aren't more accurate than bins */
65 enum { COMPLETE, VIRTUAL_CENSORED, TRUE_CENSORED } dataset_is;
66
67 } ESL_HISTOGRAM;
68
69 #define esl_histogram_Bin2LBound(h,b) ((h)->w*(b) + (h)->bmin)
70 #define esl_histogram_Bin2UBound(h,b) ((h)->w*((b)+1) + (h)->bmin)
71
72 /* Creating/destroying histograms and collecting data:
73 */
74 extern ESL_HISTOGRAM *esl_histogram_Create (double bmin, double bmax, double w);
75 extern ESL_HISTOGRAM *esl_histogram_CreateFull(double bmin, double bmax, double w);
76 extern void esl_histogram_Destroy (ESL_HISTOGRAM *h);
77 extern int esl_histogram_Score2Bin(ESL_HISTOGRAM *h, double x, int *ret_b);
78 extern int esl_histogram_Add (ESL_HISTOGRAM *h, double x);
79
80 /* Declarations about the binned data before parameter fitting:
81 */
82 extern int esl_histogram_DeclareCensoring(ESL_HISTOGRAM *h, int z, double phi);
83 extern int esl_histogram_DeclareRounding (ESL_HISTOGRAM *h);
84 extern int esl_histogram_SetTail (ESL_HISTOGRAM *h, double phi,
85 double *ret_newmass);
86 extern int esl_histogram_SetTailByMass (ESL_HISTOGRAM *h, double pmass,
87 double *ret_newmass);
88
89 /* Accessing data samples in a full histogram:
90 */
91 extern int esl_histogram_GetRank(ESL_HISTOGRAM *h, int rank, double *ret_x);
92 extern int esl_histogram_GetData(ESL_HISTOGRAM *h, double **ret_x, int *ret_n);
93 extern int esl_histogram_GetTail(ESL_HISTOGRAM *h, double phi, double **ret_x,
94 int *ret_n, int *ret_z);
95 extern int esl_histogram_GetTailByMass(ESL_HISTOGRAM *h, double pmass,
96 double **ret_x, int *ret_n, int *ret_z);
97
98
99 /* Setting expected binned counts:
100 */
101 extern int esl_histogram_SetExpect(ESL_HISTOGRAM *h,
102 double (*cdf)(double x, void *params),
103 void *params);
104 extern int esl_histogram_SetExpectedTail(ESL_HISTOGRAM *h, double base_val,
105 double pmass,
106 double (*cdf)(double x, void *params),
107 void *params);
108
109 /* Output/display of binned data:
110 */
111 extern int esl_histogram_Write (FILE *fp, ESL_HISTOGRAM *h);
112 extern int esl_histogram_Plot (FILE *fp, ESL_HISTOGRAM *h);
113 extern int esl_histogram_PlotSurvival(FILE *fp, ESL_HISTOGRAM *h);
114 extern int esl_histogram_PlotQQ (FILE *fp, ESL_HISTOGRAM *h,
115 double (*invcdf)(double, void *), void *params);
116
117 /* Goodness of fit testing
118 */
119 extern int esl_histogram_Goodness(ESL_HISTOGRAM *h, int nfitted,
120 int *ret_nbins,
121 double *ret_G, double *ret_Gp,
122 double *ret_X2, double *ret_X2p);
123
124
125
126 #endif /*eslHISTOGRAM_INCLUDED*/