37 long bins,
double sigmasRequired) {
38 long binned, iMaximum, i;
39 static long maxBins = 0;
40 static double *histogram = NULL;
41 double min, max, midpoint, maxHistogram, meanBinned;
42 double lower, upper, delta;
45 bins = DEFAULT_BINFACTOR * points;
46 if (sigmasRequired <= 0)
47 sigmasRequired = DEFAULT_SIGMAS;
52 histogram =
tmalloc(
sizeof(*histogram) * (maxBins = bins));
59 midpoint = (min + max) / 2;
63 delta = (midpoint - min) / (bins - 1);
64 lower = min - delta / 2;
65 upper = midpoint + delta / 2;
66 if ((binned =
make_histogram(histogram, bins, lower, upper, data, points, 1))) {
69 for (i = 0; i < bins; i++) {
70 if (maxHistogram < histogram[i]) {
72 maxHistogram = histogram[i];
75 meanBinned = ((double)binned) / bins;
76 if ((maxHistogram > 1) && (maxHistogram > (meanBinned + sigmasRequired * sqrt(meanBinned))))
77 *base = lower + (iMaximum + 0.5) * ((upper - lower) / bins);
80 delta = (max - midpoint) / (bins - 1);
81 lower = midpoint - delta / 2;
82 upper = max + delta / 2;
83 if ((binned =
make_histogram(histogram, bins, lower, upper, data, points, 1))) {
86 for (i = 0; i < bins; i++) {
87 if (maxHistogram < histogram[i]) {
89 maxHistogram = histogram[i];
92 meanBinned = ((double)binned) / bins;
93 if ((maxHistogram > 1) && (maxHistogram > (meanBinned + sigmasRequired * sqrt(meanBinned))))
94 *top = lower + (iMaximum + 0.5) * ((upper - lower) / bins);
118int64_t
findCrossingPoint(int64_t start,
double *data, int64_t points,
double level,
long direction,
119 double *indepData,
double *location) {
122 long transitionPossible;
124 if (start < 0 || start > (points - 1))
126 transitionPossible = 0;
127 for (i = start; i < points; i++) {
128 diff = direction * (data[i] - level);
130 transitionPossible = 1;
131 if (diff > 0 && transitionPossible)
136 if (!indepData || !location)
138 if (i == 0 || data[i] == data[i - 1]) {
139 *location = indepData[i];
142 *location = indepData[i - 1] + (indepData[i] - indepData[i - 1]) / (data[i] - data[i - 1]) * (level - data[i - 1]);
int find_min_max(double *min, double *max, double *list, int64_t n)
Finds the minimum and maximum values in a list of doubles.
long make_histogram(double *hist, long n_bins, double lo, double hi, double *data, int64_t n_pts, long new_start)
Compiles a histogram from data points.
long findTopBaseLevels(double *top, double *base, double *data, int64_t points, long bins, double sigmasRequired)
Finds the top-level and base-level of a dataset.
int64_t findCrossingPoint(int64_t start, double *data, int64_t points, double level, long direction, double *indepData, double *location)
Finds the crossing point in the data where the data crosses a specified level.