/* kernel.c */ /************************************************************ * * * 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) 1994 Sigbert Klinke * * * * All Rights Reserved. * * * ************************************************************/ #include #include #include "xincludes.h" #include "xgobitypes.h" #include "xgobivars.h" #include "xgobiexterns.h" static int *bin, *sort; /*static float window_width_const = 3.12;*/ void alloc_bin_fts(int n) { bin = (int *) XtMalloc((Cardinal) (2 * n * sizeof(int))); sort = (int *) XtMalloc((Cardinal) (n * sizeof(int))); } void free_bin_fts() { XtFree((XtPointer) bin); XtFree((XtPointer) sort); } #define BINWIDTH 0.01 int compare1(const void *val1, const void *val2) { register int *left = (int *) val1; register int *right = (int *) val2; if (*(bin+2* *left)<*(bin+2* *right)) return (-1); if (*(bin+2* *left)>*(bin+2* *right)) return (1); return (0); } float bin_fts_index(float **proj_data, int n, int *rows_in_plot, float bandwidth) /* Calculation of \sum_{i=1}^{n} \sum{j=1}^{i-1} K_h((x_i - x_j)/h, (y_i-y_j)/h) */ { float indx_val, tmpf, hf; int i, j, m, start, ki, kj; long dist, tmpl, h; /* float window_width3; */ /* Binning */ for (i=0; ih) start++; else { ki++; kj++; tmpl = *(bin+ki) - *(bin+kj); dist += tmpl*tmpl; if (dist < h) { tmpf = 1-hf*(float)dist; indx_val += tmpf*tmpf*tmpf; } } } } indx_val = n + 2.0*indx_val; indx_val *= (4.0 / (M_PI*n*n*bandwidth*bandwidth)); return (indx_val); } void bin_fts_deriv (float **data, float **proj_data, float *alpha, float *beta, float **derivs, int n, int *rows_in_plot, int p, int nactive, int *active_vars, float bandwidth) /* Calculation of \sum_{i=1}^{n} \sum{j=1}^{i-1} dK_h((x_i - x_j)/h, (y_i-y_j)/h) (xo_{i,m} - xo_{j,m})^2 replace alpha_m by beta_m for derivation of beta */ { float indx_val, tmpf, dm, hf;/* window_width3;*/ int i, j, m, start, k, ki, kj; long dist, tmplx, h, tmply; /* Initialize derivatives */ for (i=0; i<2; i++) for (k=0; kh) start++; else { ki++; kj++; tmply = *(bin+ki) - *(bin+kj); dist += tmply*tmply; if (dist < h) { tmpf = 1-hf*dist; ki = rows_in_plot[sort[i]]; kj = rows_in_plot[sort[j]]; for (k=0; kh) start++; else { ki++; kj++; tmpl = *(bin+ki) - *(bin+kj); dist += tmpl*tmpl; if (dist < h) { tmpf = 1-hf*dist; tmpf = tmpf*tmpf*tmpf; *(dens+i) += tmpf; *(dens+j) += tmpf; } } } } indx_val = 0; for (i=0; ih) start++; else { ki++; kj++; tmpl = *(bin+ki) - *(bin+kj); dist += tmpl*tmpl; if (dist < h) { tmpf = 1-hf*dist; tmpf = tmpf*tmpf*tmpf; *(deno+i) += tmpf; *(deno+j) += tmpf; } } } } /* calculate true denominator */ for (i=0; ih) start++; else { ki++; kj++; tmply = *(bin+ki) - *(bin+kj); dist += tmply*tmply; if (dist < h) { tmpf = 1-hf*dist; ki = rows_in_plot[sort[i]]; kj = rows_in_plot[sort[j]]; for (k=0; k