12 #include "Deviation.h"
15 * Reorder the identifiers in the identifier table so that the
16 * ones whose data points exhibit the mininal standard deviation
33 averages = (floatish*) xmalloc(nidents * sizeof(floatish));
34 deviations = (floatish*) xmalloc(nidents * sizeof(floatish));
38 for (i = 0; i < nidents; i++) {
42 for (i = 0; i < nidents; i++) {
43 for (ch = identtable[i]->chk; ch; ch = ch->next) {
44 for (j = 0; j < ch->nd; j++) {
45 averages[i] += ch->d[j].value;
50 for (i = 0; i < nidents; i++) {
51 averages[i] /= (floatish) nsamples;
54 /* calculate standard deviation */
56 for (i = 0; i < nidents; i++) {
60 for (i = 0; i < nidents; i++) {
61 for (ch = identtable[i]->chk; ch; ch = ch->next) {
62 for (j = 0; j < ch->nd; j++) {
63 dev = ch->d[j].value - averages[i];
64 deviations[i] += dev * dev;
69 for (i = 0; i < nidents; i++) {
70 deviations[i] = (floatish) sqrt ((doublish) (deviations[i] /
71 (floatish) (nsamples - 1)));
75 /* sort on basis of standard deviation */
77 for (i = 0; i < nidents-1; i++) {
79 for (j = i+1; j < nidents; j++) {
80 if (deviations[ j ] < deviations[min]) {
86 deviations[min] = deviations[i];
90 identtable[min] = identtable[i];
100 int iflag; /* a funny three-way flag ? WDP 95/03 */
107 /* sort on basis of ident string */
109 /* greatest at top i.e. smallest at start */
111 for (i = 0; i < nidents-1; i++) {
113 for (j = i+1; j < nidents; j++) {
114 if (strcmp(identtable[j]->name, identtable[min]->name) < 0) {
120 identtable[min] = identtable[i];
124 /* smallest at top i.e. greatest at start */
126 for (i = 0; i < nidents-1; i++) {
128 for (j = i+1; j < nidents; j++) {
129 if (strcmp(identtable[j]->name, identtable[min]->name) > 0) {
135 identtable[min] = identtable[i];