42 G_fatal_error(
_(
"Discont algorithm currently not available because of bugs"));
61 max = data[count - 1];
63 step = (max -
min) / (nbreaks + 1);
65 for (i = 0; i < nbreaks; i++)
66 classbreaks[i] = min + (step * (i + 1));
80 nbclass = nbreaks + 1;
82 if (nbclass % 2 == 1) {
87 if (((stats.
mean + stats.
stdev * scale / 2) +
88 (stats.
stdev * scale * (nbclass / 2 - 1)) > stats.
max) ||
90 (stats.
stdev * scale * (nbclass / 2 - 1)) < stats.
min))
97 for (i = 0; i < nbreaks / 2; i++)
100 stats.
stdev * scale * (nbreaks / 2 - (i + 1));
102 for (i = i; i < nbreaks; i++)
105 stats.
stdev * scale * (i - nbreaks / 2);
113 if (((stats.
mean) + (stats.
stdev * scale * (nbclass / 2 - 1)) >
115 ((stats.
mean) - (stats.
stdev * scale * (nbclass / 2 - 1)) <
123 for (i = 0; i <= nbreaks / 2; i++)
125 stats.
mean - stats.
stdev * scale * (nbreaks / 2 - i);
127 for (i = i; i < nbreaks; i++)
129 stats.
mean + stats.
stdev * scale * (i - nbreaks / 2);
139 step = count / (nbreaks + 1);
141 for (i = 0; i < nbreaks; i++)
142 classbreaks[i] = data[step * (i + 1)];
155 nbclass = *nbreaks + 1;
157 lequi =
G_malloc(*nbreaks *
sizeof(
double));
166 else if (nbclass == 3) {
170 else if (nbclass == 4) {
175 else if (nbclass == 5) {
181 else if (nbclass == 6) {
188 else if (nbclass == 7) {
196 else if (nbclass == 8) {
205 else if (nbclass == 9) {
215 else if (nbclass == 10) {
227 G_fatal_error(
_(
"Equiprobable classbreaks currently limited to 10 classes"));
234 for (i = 0; i < *nbreaks; i++) {
235 if ((lequi[i] * stats.
stdev + stats.
mean) >= stats.
min &&
241 if (j < (*nbreaks)) {
242 G_warning(
_(
"There are classbreaks outside the range min-max. Number of " 243 "classes reduced to %i, but using probabilities for %i classes."),
244 j + 1, *nbreaks + 1);
245 G_realloc(classbreaks, j *
sizeof(
double));
246 for (i = 0; i < j; i++)
251 for (i = 0; i < *nbreaks; i++) {
252 if ((lequi[i] * stats.
stdev + stats.
mean) >= stats.
min &&
254 classbreaks[j] = lequi[i] * stats.
stdev + stats.
mean;
271 double *no, *zz, *nz, *xn, *co;
274 double min = 0,
max = 0, rangemax = 0;
276 double rangemin = 0, xlim = 0;
277 double dmax = 0.0, d2 = 0.0, dd = 0.0, p = 0.0;
278 int nf = 0, nmax = 0;
281 double den = 0, d = 0;
284 int nff = 0, jj = 0, no1 = 0, no2 = 0;
285 double f = 0, xt1 = 0, xt2 = 0, chi2 = 1000.0, xnj_1 = 0, xj_1 = 0;
291 nbclass = nbreaks + 1;
293 num =
G_malloc((nbclass + 1) *
sizeof(
int));
294 no =
G_malloc((nbclass + 1) *
sizeof(
double));
295 zz =
G_malloc((nbclass + 1) *
sizeof(
double));
297 xn =
G_malloc((n + 1) *
sizeof(
double));
298 co =
G_malloc((nbclass + 1) *
sizeof(
double));
301 x =
G_malloc((n + 1) *
sizeof(
double));
306 max = data[count - 1];
307 for (i = 1; i <= n; i++)
313 for (i = 2; i <= n; i++) {
314 if (x[i] != x[i - 1] && x[i] - x[i - 1] < rangemin)
315 rangemin = x[i] - x[i - 1];
321 for (i = 1; i <= n; i++) {
322 x[i] = (x[i] -
min) / rangemax;
323 xn[i] = i / (double)n;
325 xlim = rangemin / rangemax;
326 rangemin = rangemin / 2.0;
333 for (i = 1; i <= nbclass; i++) {
340 for (j = 1; j <= i; j++) {
345 den = sqrt(pow(abc[1], 2) + 1.0);
348 for (k = nd; k <= nf; k++) {
350 d = fabs((-1.0 * abc[1] * x[k]) + xn[k] - abc[0]) / den;
352 d = fabs(x[k] - abc[2]);
354 if (x[k] - x[nd] < xlim)
356 if (x[nf] - x[k] < xlim)
364 if (x[nf] != x[nd]) {
366 co[j] = (xn[nf] - xn[nd]) / (x[nf] - x[nd]);
368 co[j] = (xn[nf]) / (x[nf]);
374 for (j = 1; j <= i; j++) {
376 zz[j] = x[num[j]] * rangemax +
min;
379 if (co[j] > co[j + 1]) {
380 zz[j] = zz[j] + rangemin;
383 zz[j] = zz[j] - rangemin;
388 for (j = 1; j <= im; j++) {
390 no[ji] -= no[ji - 1];
398 for (j = 1; j <= i; j++) {
400 if (num[jj - 1] < nmax) {
405 num[jj] = num[jj - 1];
416 xnj_1 = xn[num[jj - 1]];
417 xj_1 = x[num[jj - 1]];
419 no1 = (xn[num[jj]] - xnj_1) * n;
420 no2 = (xn[num[jj + 1]] - xn[num[jj]]) * n;
421 f = (xn[num[jj + 1]] - xnj_1) / (x[num[jj + 1]] - xj_1);
423 xt1 = (x[num[jj]] - xj_1) * f;
424 xt2 = (x[num[jj + 1]] - x[num[jj]]) * f;
426 xt2 = rangemin / 2.0 / rangemax * f;
429 else if (xt1 * xt2 == 0) {
430 xt1 = rangemin / 2.0 / rangemax * f;
435 if (chi2 > pow((
double)((no1 - no2) - (xt1 - xt2)), 2) / (xt1 + xt2))
436 chi2 = pow((
double)((no1 - no2) - (xt1 - xt2)), 2) / (xt1 + xt2);
441 for (j = 0; j <= (i - 1); j++)
442 classbreaks[j] = zz[j + 1];
448 double *classbreaks,
int *frequencies)
454 max = data[count - 1];
457 for (j = 0; j < nbreaks; j++) {
458 while (data[i] <= classbreaks[j]) {
465 for (i = i; i <
count; i++) {
466 frequencies[nbreaks]++;
double AS_class_apply_algorithm(int algo, double *data, int nrec, int *nbreaks, double *classbreaks)
int AS_class_equiprob(double *data, int count, int *nbreaks, double *classbreaks)
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
int AS_class_interval(double *data, int count, int nbreaks, double *classbreaks)
int AS_option_to_algorithm(const struct Option *option)
void G_free(void *)
Free allocated memory.
void AS_eqdrt(double[], double[], int, int, double *)
int int G_strcasecmp(const char *, const char *)
String compare ignoring case (upper or lower)
double AS_class_discont(double *data, int count, int nbreaks, double *classbreaks)
int AS_class_frequencies(double *data, int count, int nbreaks, double *classbreaks, int *frequencies)
double AS_class_stdev(double *data, int count, int nbreaks, double *classbreaks)
void G_warning(const char *,...) __attribute__((format(printf
Structure that stores option information.
void AS_basic_stats(double *, int, struct GASTATS *)
int AS_class_quant(double *data, int count, int nbreaks, double *classbreaks)