/* * Copyright 1986 David W. Scott */ #include #include #include #include #include #include #define true 1 #define false 0 #ifndef iabs #define iabs(x) ((x) >= 0 ? (x) : -(x)) #endif #ifndef MIN #define MIN(x,y) ((x)<(y)?(x):(y)) #endif #ifndef MAX #define MAX(x,y) ((x)>(y)?(x):(y)) #endif /* functions */ #ifdef __cplusplus extern "C" { #endif gint bin1 (gfloat *, gint, gfloat *, gint, gint *); gint ash1 (gint, gint *, gint, gfloat *, gfloat *, gfloat *, gfloat *, gfloat *); gint do_ash1d (gfloat *vals, gint nvals, gint nbins, gint n_ashes, gfloat *ashed_vals, gfloat *lims_min, gfloat *lims_max, gfloat *mean); #ifdef __cplusplus } #endif /* */ gint do_ash1d (gfloat *vals, gint nvals, gint nbins, gint n_ashes, gfloat *ashed_vals, gfloat *lims_min, gfloat *lims_max, gfloat *mean) { gint i, k, icheck; gint *bins; gfloat min, max, ab[2]; gfloat sum; /* for computing nicerange -- extending the range */ gfloat del, beta = 0.2; /* for ash1 */ gint ash_return; gfloat *f, *t, *w; /* w = weights */ gfloat kopt[] = {2.0, 2.0}; /* S function default values for kernel options */ gfloat binwidth; /* for generating the interpolated values to plot */ gfloat ti; bins = (gint *) g_malloc (nbins * sizeof (gint)); min = max = vals[0]; for (i=1; i= 1 && k <= nbin) nc[k] += 1 ; else nskip += 1; } return nskip; } /* c April 8, 1986 c c Computer ASH density estimate; Quartic (biweight) kernel c Average of "m" shifted histograms c c Bin counts in array "nc(nbin)" - from routine "bin1" c "nbin" bins are formed over the interval [a,b) c c ASH estimates returned in array "f(nbin)" c c FP-ASH plotted at a+d/2 ... b-d/2 where d = (b-a)/nbin c c Note: If "nskip" was nonzero, ASH estimates incorrect near boundary c Note: Should leave "m" empty bins on each end of array "nc" so f OK c ##### Copyright 1986 David W. Scott */ gint ash1 (gint m, gint *nc, gint nbin, gfloat *ab, gfloat *kopt, gfloat *t, gfloat *f, gfloat *w ) { /* nc(nbin), ab(2), t(nbin), f(nbin), w(m), kopt(2) */ gfloat a, b, delta, cons, c, h; gint i, k, n; gint ier = 0 ; a = ab[0] ; b = ab[1] ; n = 0 ; /* * compute weights cons * ( 1-abs((i/m))^kopt1)^kopt2 * -- should sum to "m" 5-8-91 * w-array shifted by 1 */ /* * cons = sum of weights from -(m-1) to (m-1) = 1 + 2 (sum from 1 to m-1) */ w[0] = 1.0 ; cons = 1.0 ; for (i=1; i 0) { ier = 1 ; } } /* * compute ash(m) estimate */ delta = (b-a) / (gfloat) nbin ; h = (gfloat) m * delta ; for (i=0; i