26 int *nbreaks,
double classbreaks[])
66 step = (
max -
min) / (nbreaks + 1);
68 for (i = 0; i < nbreaks; i++)
69 classbreaks[i] =
min + (step * (i + 1));
84 nbclass = nbreaks + 1;
92 if (((stats.
mean + stats.
stdev * scale / 2) +
93 (stats.
stdev * scale * (nbclass / 2 - 1)) >
96 (stats.
stdev * scale * (nbclass / 2 - 1)) <
104 for (i = 0; i < nbreaks / 2; i++)
105 classbreaks[i] = (stats.
mean - stats.
stdev * scale / 2) -
106 stats.
stdev * scale * (nbreaks / 2 - (i + 1));
108 for (; i < nbreaks; i++)
109 classbreaks[i] = (stats.
mean + stats.
stdev * scale / 2) +
110 stats.
stdev * scale * (i - nbreaks / 2);
117 if (((stats.
mean) + (stats.
stdev * scale * (nbclass / 2 - 1)) >
119 ((stats.
mean) - (stats.
stdev * scale * (nbclass / 2 - 1)) <
127 for (i = 0; i <= nbreaks / 2; i++)
129 stats.
mean - stats.
stdev * scale * (nbreaks / 2 - i);
131 for (; i < nbreaks; i++)
133 stats.
mean + stats.
stdev * scale * (i - nbreaks / 2);
140 double classbreaks[])
144 step =
count / (nbreaks + 1);
146 for (i = 0; i < nbreaks; i++)
147 classbreaks[i] = data[step * (i + 1)];
153 double classbreaks[])
161 nbclass = *nbreaks + 1;
163 lequi =
G_malloc(*nbreaks *
sizeof(
double));
172 else if (nbclass == 3) {
176 else if (nbclass == 4) {
181 else if (nbclass == 5) {
187 else if (nbclass == 6) {
194 else if (nbclass == 7) {
202 else if (nbclass == 8) {
211 else if (nbclass == 9) {
221 else if (nbclass == 10) {
234 _(
"Equiprobable classbreaks currently limited to 10 classes"));
242 for (i = 0; i < *nbreaks; i++) {
243 if ((lequi[i] * stats.
stdev + stats.
mean) >= stats.
min &&
249 if (j < (*nbreaks)) {
251 _(
"There are classbreaks outside the range min-max. Number of "
252 "classes reduced to %i, but using probabilities for %i classes."),
253 j + 1, *nbreaks + 1);
254 for (i = 0; i < j; i++)
255 classbreaks[i] = 0.0;
259 for (i = 0; i < *nbreaks; i++) {
260 if ((lequi[i] * stats.
stdev + stats.
mean) >= stats.
min &&
262 classbreaks[j] = lequi[i] * stats.
stdev + stats.
mean;
273 double classbreaks[])
276 double chi2 = 1000.0;
281 int nbclass = nbreaks + 1;
283 int *num =
G_calloc((nbclass + 2),
sizeof(
int));
284 int *no =
G_calloc((nbclass + 1),
sizeof(
int));
285 double *zz =
G_malloc((nbclass + 1) *
sizeof(
double));
286 double *xn =
G_malloc((n + 1) *
sizeof(
double));
287 double *co =
G_malloc((nbclass + 1) *
sizeof(
double));
291 double *
x =
G_malloc((n + 1) *
sizeof(
double));
295 double min = data[0];
297 for (i = 1; i <= n; i++)
300 double rangemax =
max -
min;
301 double rangemin = rangemax;
303 for (i = 2; i <= n; i++) {
304 if (
x[i] !=
x[i - 1] &&
x[i] -
x[i - 1] < rangemin)
305 rangemin =
x[i] -
x[i - 1];
311 for (i = 1; i <= n; i++) {
312 x[i] = (
x[i] -
min) / rangemax;
313 xn[i] = i / (double)n;
315 double xlim = rangemin / rangemax;
316 rangemin = rangemin / 2.0;
321 for (i = 1; i <= nbclass; i++) {
327 for (j = 1; j <= i; j++) {
328 double a = 0.0,
b = 0.0, c = 0.0, d = 0.0;
334 double den = sqrt(pow(
b, 2) + 1.0);
337 for (
int k = nd; k <= nf; k++) {
341 d = fabs((-1.0 *
b *
x[k]) + xn[k] - a) / den;
343 if (
x[k] -
x[nd] < xlim)
345 if (
x[nf] -
x[k] < xlim)
354 co[j] = (xn[nf] - xn[nd]) / (
x[nf] -
x[nd]);
356 for (j = 1; j <= i; j++) {
358 zz[j] =
x[num[j]] * rangemax +
min;
361 if (co[j] > co[j + 1]) {
362 zz[j] = zz[j] + rangemin;
366 zz[j] = zz[j] - rangemin;
372 for (j = 1; j <= im; j++) {
374 no[ji] -= no[ji - 1];
383 bool do_reset =
true;
384 for (j = 1; j <= i; j++) {
386 if (num[jj - 1] < nmax) {
391 num[jj] = num[jj - 1];
397 int no1 = (int)((xn[num[jj]] - xn[num[jj - 1]]) * n);
398 int no2 = (int)((xn[num[jj + 1]] - xn[num[jj]]) * n);
399 double f = (xn[num[jj + 1]] - xn[num[jj - 1]]) /
400 (
x[num[jj + 1]] -
x[num[jj - 1]]);
402 double xt1 = (
x[num[jj]] -
x[num[jj - 1]]) * f;
403 double xt2 = (
x[num[jj + 1]] -
x[num[jj]]) * f;
406 xt2 = rangemin / 2.0 / rangemax * f;
410 xt1 = rangemin / 2.0 / rangemax * f;
418 double ch = pow((
double)((no1 - no2) - (xt1 - xt2)), 2) / (xt1 + xt2);
424 for (j = 1; j < nbclass; j++)
425 classbreaks[j - 1] = zz[j];
438 double classbreaks[],
int frequencies[])
446 for (j = 0; j < nbreaks; j++) {
447 while (data[i] <= classbreaks[j]) {
454 for (; i <
count; i++) {
455 frequencies[nbreaks]++;
double AS_class_discont(const double data[], int count, int nbreaks, double classbreaks[])
double AS_class_apply_algorithm(int algo, const double data[], int nrec, int *nbreaks, double classbreaks[])
int AS_class_quant(const double data[], int count, int nbreaks, double classbreaks[])
int AS_class_frequencies(const double data[], int count, int nbreaks, double classbreaks[], int frequencies[])
int AS_class_equiprob(const double data[], int count, int *nbreaks, double classbreaks[])
int AS_class_interval(const double data[], int count, int nbreaks, double classbreaks[])
int AS_option_to_algorithm(const struct Option *option)
double AS_class_stdev(const double data[], int count, int nbreaks, double classbreaks[])
void AS_eqdrt(double[], double[], int, int, double *, double *, double *)
void AS_basic_stats(const double[], int, struct GASTATS *)
void G_free(void *)
Free allocated memory.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void G_warning(const char *,...) __attribute__((format(printf
int int G_strcasecmp(const char *, const char *)
String compare ignoring case (upper or lower)
GRASS_INTERPFL_EXPORT int count
Structure that stores option information.