34 double *hist,
long n_bins,
double lo,
double hi,
double *data,
35 int64_t n_pts,
long new_start) {
38 static double bin_size, dbin;
41 bin_size = (hi - lo) / n_bins;
42 for (i = 0; i < n_bins; i++)
46 for (i = 0; i < n_pts; i++) {
47 bin = (dbin = (data[i] - lo) / bin_size);
50 if (bin < 0 || bin >= n_bins)
55 for (i = bin = 0; i < n_bins; i++)
75 double *hist,
long n_bins,
double lo,
double hi,
double *data,
76 long n_pts,
long new_start,
double *weight) {
77 static long bin, i, count;
78 static double bin_size, dbin;
82 bin_size = (hi - lo) / n_bins;
83 for (i = 0; i < n_bins; i++)
87 for (i = 0; i < n_pts; i++) {
88 bin = (dbin = (data[i] - lo) / bin_size);
91 if (bin < 0 || bin >= n_bins)
93 hist[bin] += weight[i];
115long computeMode(
double *result,
double *data,
long pts,
double binSize,
long bins) {
120 if ((binSize <= 0 && bins <= 2) || (binSize > 0 && bins > 2))
137 bins = (max - min) / binSize + 0.5;
139 binSize = (max - min) / bins;
143 binSize = (max - min) / bins;
145 if (!(histogram = malloc(
sizeof(*histogram) * bins)))
146 bomb(
"memory allocation failure (computeMode)", NULL);
150 *result = (imax + 0.5) * binSize + min;
115long computeMode(
double *result,
double *data,
long pts,
double binSize,
long bins) {
…}
void bomb(char *error, char *usage)
Reports error messages to the terminal and aborts the program.
int index_min_max(int64_t *imin, int64_t *imax, double *list, int64_t n)
Finds the indices of the minimum and maximum values in a list of doubles.
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_weighted(double *hist, long n_bins, double lo, double hi, double *data, long n_pts, long new_start, double *weight)
Compiles a weighted histogram from data points.
long computeMode(double *result, double *data, long pts, double binSize, long bins)
Computes the mode of a dataset using histogram binning.
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.