/************************************************************ * * * Permission is hereby granted to any individual or * * institution for use, copying, or redistribution of * * this code and associated documentation, provided * * that such code and documentation are not sold for * * profit and the following copyright notice is retained * * in the code and documentation: * * Copyright (c) 1997 Sigbert Klinke * * * * All Rights Reserved. * * * ************************************************************/ #include #include #include #include "xincludes.h" #include "xgobitypes.h" #include "xgobivars.h" #include "xgobiexterns.h" #define malloc(x) XtMalloc((Cardinal) x) #define free(x) XtFree((char *) x) double *xsort; int *gsort; int indexsort (const void *left, const void *right) { if (xsort[*((int *) left)]>xsort[*((int *) right)]) return (1); if (xsort[*((int *) left)]gsort[*((int *)right)]) return (1); if (gsort[*((int *)left)]1.0) return 0.0; return (0.9375*(1-x2)*(1-x2)); } void nadaraya_watson (int n, double *x, double *y, int *group, double bandwidth, double *yest, int *index) { int i, j, k, maxgroup, start; double diff, kern, *yup, *ydn; yup = (double *) malloc(n*sizeof(double)); ydn = (double *) malloc(n*sizeof(double)); maxgroup = -1; for (i=0; imaxgroup) maxgroup = group[i]; ydn[i] = quartic(0); /* K(0) */ yup[i] = y[i]*quartic(0); /* Y_i K(0) */ } xsort = x; qsort ((char *) index, n, sizeof(int), indexsort); for (k=0; k<=maxgroup; k++) { for (start=i=0; i