13 #include "Deviation.h"
16 * Reorder the identifiers in the identifier table so that the
17 * ones whose data points exhibit the mininal standard deviation
34 averages = (floatish*) xmalloc(nidents * sizeof(floatish));
35 deviations = (floatish*) xmalloc(nidents * sizeof(floatish));
39 for (i = 0; i < nidents; i++) {
43 for (i = 0; i < nidents; i++) {
44 for (ch = identtable[i]->chk; ch; ch = ch->next) {
45 for (j = 0; j < ch->nd; j++) {
46 averages[i] += ch->d[j].value;
51 for (i = 0; i < nidents; i++) {
52 averages[i] /= (floatish) nsamples;
55 /* calculate standard deviation */
57 for (i = 0; i < nidents; i++) {
61 for (i = 0; i < nidents; i++) {
62 for (ch = identtable[i]->chk; ch; ch = ch->next) {
63 for (j = 0; j < ch->nd; j++) {
64 dev = ch->d[j].value - averages[i];
65 deviations[i] += dev * dev;
70 for (i = 0; i < nidents; i++) {
71 deviations[i] = (floatish) sqrt ((doublish) (deviations[i] /
72 (floatish) (nsamples - 1)));
76 /* sort on basis of standard deviation */
78 for (i = 0; i < nidents-1; i++) {
80 for (j = i+1; j < nidents; j++) {
81 if (deviations[ j ] < deviations[min]) {
87 deviations[min] = deviations[i];
91 identtable[min] = identtable[i];
101 int iflag; /* a funny three-way flag ? WDP 95/03 */
108 /* sort on basis of ident string */
110 /* greatest at top i.e. smallest at start */
112 for (i = 0; i < nidents-1; i++) {
114 for (j = i+1; j < nidents; j++) {
115 if (strcmp(identtable[j]->name, identtable[min]->name) < 0) {
121 identtable[min] = identtable[i];
125 /* smallest at top i.e. greatest at start */
127 for (i = 0; i < nidents-1; i++) {
129 for (j = i+1; j < nidents; j++) {
130 if (strcmp(identtable[j]->name, identtable[min]->name) > 0) {
136 identtable[min] = identtable[i];