/** * Gets the array of densities, one density for each bin. * A density for one bin equals the fraction of values in that bin. * @return array[nbin] of densities, where nbin is the number of bins. */ public float[] getDensities() { int nbin = getBinCount(); float[] d = new float[nbin]; double s = 1.0/_nin; for (int ibin=0; ibin<nbin; ++ibin) d[ibin] = (float)(s*_h[ibin]); return d; }
/** * Constructs a histogram for the specified array of values. * Counts and bins all values. * @param v the array of values. * @param nbin the number of bins. */ public Histogram(float[] v, int nbin) { initMinMax(v); init(v,nbin); }
double dbin = 1.0f; double fbin = vmin+0.5*dbin; Histogram h = new Histogram(v); assertEquals(vmin,h.getMinValue()); assertEquals(vmax,h.getMaxValue()); assertEquals(nbin,h.getBinCount()); assertEquals(dbin,h.getBinDelta()); assertEquals(fbin,h.getBinFirst()); assertEquals(0,h.getLowCount()); assertEquals(n,h.getInCount()); assertEquals(0,h.getHighCount()); dbin = 1.0; fbin = vmin+0.5*dbin; h = new Histogram(v,nbin); assertEquals(vmin,h.getMinValue()); assertEquals(vmax,h.getMaxValue()); assertEquals(nbin,h.getBinCount()); assertEquals(dbin,h.getBinDelta()); assertEquals(fbin,h.getBinFirst()); assertEquals(0,h.getLowCount()); assertEquals(n,h.getInCount()); assertEquals(0,h.getHighCount()); dbin = vmax-vmin; fbin = 0.5*(vmin+vmax); h = new Histogram(v,vmin,vmax); assertEquals(vmin,h.getMinValue()); assertEquals(vmax,h.getMaxValue());
public void testRamp() { int n = 1001; float[] v = rampfloat(0.0f,1.0f,n); float vmin = min(v); float vmax = max(v); int nbin = 10; double dbin = (vmax-vmin)/nbin; double fbin = vmin+0.5*dbin; Histogram h = new Histogram(v,nbin); assertEquals(nbin,h.getBinCount()); assertEquals(dbin,h.getBinDelta()); assertEquals(fbin,h.getBinFirst()); assertEquals(n,h.getInCount()); assertEquals(0,h.getLowCount()); assertEquals(0,h.getHighCount()); }
/** * Constructs a histogram for the specified array of values. * Computes the number of bins to obtain a robust estimate of the density * function. Counts and bins all values. * @param v the array of values. */ public Histogram(float[] v) { initMinMax(v); init(v,0); }
/** * Constructs a histogram for the specified array of values. * Counts and bins only those values in [vmin,vmax]. * @param v the array of values. * @param vmin the minimum value. * @param vmax the maximum value. * @param nbin the number of bins. */ public Histogram(float[] v, float vmin, float vmax, int nbin) { Check.argument(vmin<=vmax,"vmin<=vmax"); initMinMax(vmin,vmax); init(v,nbin); }
/** * Constructs a histogram for the specified array of values. * Computes the number of bins to obtain a robust estimate of the density * function. Counts and bins only those values in [vmin,vmax]. * @param v the array of values. * @param vmin the minimum value. * @param vmax the maximum value. */ public Histogram(float[] v, float vmin, float vmax) { Check.argument(vmin<=vmax,"vmin<=vmax"); initMinMax(vmin,vmax); init(v,0); }