@Test public void testSmooth() { Histogram h = new Histogram(20.0, 40.0, 2.0); h.add(21.0); h.add(21.0); h.add(21.0); h.smooth(6.0); assertEquals(1.0, h.getFrequency(0), EPSILON); assertEquals(1.0, h.getFrequency(1), EPSILON); assertEquals(0.0, h.getFrequency(2), EPSILON); }
public void smooth(double windowLength) { int size = (int) Math.round(windowLength / resolution) / 2; double sum = 0.0; for (int i = 0; i <= size; i++) { sum += frequencies[i]; } double[] newFrequencies = new double[frequencies.length]; for (int i = 0; i < size; i++) { newFrequencies[i] = sum / (2 * size + 1); sum += frequencies[i + size + 1]; } for (int i = size; i < frequencies.length - size - 1; i++) { newFrequencies[i] = sum / (2 * size + 1); sum += frequencies[i + size + 1]; sum -= frequencies[i - size]; } for (int i = frequencies.length - size - 1; i < frequencies.length; i++) { newFrequencies[i] = sum / (2 * size + 1); sum -= frequencies[i - size]; } frequencies = newFrequencies; }
Histogram implements Iterable<Histogram.Bin> { public void smooth(double windowLength) { int size = (int) Math.round(windowLength / resolution) / 2; double sum = 0.0; for (int i = 0; i <= size; i++) { sum += frequencies[i]; } double[] newFrequencies = new double[frequencies.length]; for (int i = 0; i < size; i++) { newFrequencies[i] = sum / (2 * size + 1); sum += frequencies[i + size + 1]; } for (int i = size; i < frequencies.length - size - 1; i++) { newFrequencies[i] = sum / (2 * size + 1); sum += frequencies[i + size + 1]; sum -= frequencies[i - size]; } for (int i = frequencies.length - size - 1; i < frequencies.length; i++) { newFrequencies[i] = sum / (2 * size + 1); sum -= frequencies[i - size]; } frequencies = newFrequencies; } }
Histogram implements Iterable<Histogram.Bin> { public void smooth(double windowLength) { int size = (int) Math.round(windowLength / resolution) / 2; double sum = 0.0; for (int i = 0; i <= size; i++) { sum += frequencies[i]; } double[] newFrequencies = new double[frequencies.length]; for (int i = 0; i < size; i++) { newFrequencies[i] = sum / (2 * size + 1); sum += frequencies[i + size + 1]; } for (int i = size; i < frequencies.length - size - 1; i++) { newFrequencies[i] = sum / (2 * size + 1); sum += frequencies[i + size + 1]; sum -= frequencies[i - size]; } for (int i = frequencies.length - size - 1; i < frequencies.length; i++) { newFrequencies[i] = sum / (2 * size + 1); sum -= frequencies[i - size]; } frequencies = newFrequencies; } Histogram(double minValue, double maxValue, double resolution); }
Histogram implements Iterable<Histogram.Bin> { public void smooth(double windowLength) { int size = (int) Math.round(windowLength / resolution) / 2; double sum = 0.0; for (int i = 0; i <= size; i++) { sum += frequencies[i]; } double[] newFrequencies = new double[frequencies.length]; for (int i = 0; i < size; i++) { newFrequencies[i] = sum / (2 * size + 1); sum += frequencies[i + size + 1]; } for (int i = size; i < frequencies.length - size - 1; i++) { newFrequencies[i] = sum / (2 * size + 1); sum += frequencies[i + size + 1]; sum -= frequencies[i - size]; } for (int i = frequencies.length - size - 1; i < frequencies.length; i++) { newFrequencies[i] = sum / (2 * size + 1); sum -= frequencies[i - size]; } frequencies = newFrequencies; } Histogram(double minValue, double maxValue, double resolution); void smooth(double windowLength); void circularSmooth(double windowLength); void kernelSmooth(double[] kernel); void circularKernelSmooth(double[] kernel); double[] createGaussianKernel(double length, double stdDeviation); void circularGaussianSmooth(double windowLength, double stdDeviation); void gaussianSmooth(double windowLength, double stdDeviation); void add(double value); int getSize(); double getFrequency(int index); double getPeakValue(); static Histogram fromValues(Collection<Double> samples, double resolution); @Override Iterator<Bin> iterator(); }
Histogram implements Iterable<Histogram.Bin> { public void smooth(double windowLength) { int size = (int) Math.round(windowLength / resolution) / 2; double sum = 0.0; for (int i = 0; i <= size; i++) { sum += frequencies[i]; } double[] newFrequencies = new double[frequencies.length]; for (int i = 0; i < size; i++) { newFrequencies[i] = sum / (2 * size + 1); sum += frequencies[i + size + 1]; } for (int i = size; i < frequencies.length - size - 1; i++) { newFrequencies[i] = sum / (2 * size + 1); sum += frequencies[i + size + 1]; sum -= frequencies[i - size]; } for (int i = frequencies.length - size - 1; i < frequencies.length; i++) { newFrequencies[i] = sum / (2 * size + 1); sum -= frequencies[i - size]; } frequencies = newFrequencies; } Histogram(double minValue, double maxValue, double resolution); void smooth(double windowLength); void circularSmooth(double windowLength); void kernelSmooth(double[] kernel); void circularKernelSmooth(double[] kernel); double[] createGaussianKernel(double length, double stdDeviation); void circularGaussianSmooth(double windowLength, double stdDeviation); void gaussianSmooth(double windowLength, double stdDeviation); void add(double value); int getSize(); double getFrequency(int index); double getPeakValue(); static Histogram fromValues(Collection<Double> samples, double resolution); @Override Iterator<Bin> iterator();  }