@Test public void testCircularSmooth() { Histogram h = new Histogram(0.0, 10.0, 1.0); h.add(0.5); h.circularSmooth(5.0); assertEquals(0.2, h.getFrequency(0), EPSILON); assertEquals(0.2, h.getFrequency(1), EPSILON); assertEquals(0.2, h.getFrequency(2), EPSILON); assertEquals(0.0, h.getFrequency(3), EPSILON); assertEquals(0.0, h.getFrequency(4), EPSILON); assertEquals(0.0, h.getFrequency(5), EPSILON); assertEquals(0.0, h.getFrequency(6), EPSILON); assertEquals(0.0, h.getFrequency(7), EPSILON); assertEquals(0.2, h.getFrequency(8), EPSILON); assertEquals(0.2, h.getFrequency(9), EPSILON); }
public void circularSmooth(double windowLength) { int size = (int) Math.round(windowLength / resolution) / 2; double sum = frequencies[0]; for (int i = 1; i <= size; i++) { sum += frequencies[i] + frequencies[frequencies.length - i]; } double[] newFrequencies = new double[frequencies.length]; for (int i = 0; i < frequencies.length; i++) { newFrequencies[i] = sum / (2 * size + 1); sum += frequencies[i + size + 1 < frequencies.length ? i + size + 1 : i + size + 1 - frequencies.length]; sum -= frequencies[i - size < 0 ? frequencies.length + i - size : i - size]; } frequencies = newFrequencies; }
Histogram implements Iterable<Histogram.Bin> { public void circularSmooth(double windowLength) { int size = (int) Math.round(windowLength / resolution) / 2; double sum = frequencies[0]; for (int i = 1; i <= size; i++) { sum += frequencies[i] + frequencies[frequencies.length - i]; } double[] newFrequencies = new double[frequencies.length]; for (int i = 0; i < frequencies.length; i++) { newFrequencies[i] = sum / (2 * size + 1); sum += frequencies[i + size + 1 < frequencies.length ? i + size + 1 : i + size + 1 - frequencies.length]; sum -= frequencies[i - size < 0 ? frequencies.length + i - size : i - size]; } frequencies = newFrequencies; } }
Histogram implements Iterable<Histogram.Bin> { public void circularSmooth(double windowLength) { int size = (int) Math.round(windowLength / resolution) / 2; double sum = frequencies[0]; for (int i = 1; i <= size; i++) { sum += frequencies[i] + frequencies[frequencies.length - i]; } double[] newFrequencies = new double[frequencies.length]; for (int i = 0; i < frequencies.length; i++) { newFrequencies[i] = sum / (2 * size + 1); sum += frequencies[i + size + 1 < frequencies.length ? i + size + 1 : i + size + 1 - frequencies.length]; sum -= frequencies[i - size < 0 ? frequencies.length + i - size : i - size]; } frequencies = newFrequencies; } Histogram(double minValue, double maxValue, double resolution); }
Histogram implements Iterable<Histogram.Bin> { public void circularSmooth(double windowLength) { int size = (int) Math.round(windowLength / resolution) / 2; double sum = frequencies[0]; for (int i = 1; i <= size; i++) { sum += frequencies[i] + frequencies[frequencies.length - i]; } double[] newFrequencies = new double[frequencies.length]; for (int i = 0; i < frequencies.length; i++) { newFrequencies[i] = sum / (2 * size + 1); sum += frequencies[i + size + 1 < frequencies.length ? i + size + 1 : i + size + 1 - frequencies.length]; sum -= frequencies[i - size < 0 ? frequencies.length + i - size : 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 circularSmooth(double windowLength) { int size = (int) Math.round(windowLength / resolution) / 2; double sum = frequencies[0]; for (int i = 1; i <= size; i++) { sum += frequencies[i] + frequencies[frequencies.length - i]; } double[] newFrequencies = new double[frequencies.length]; for (int i = 0; i < frequencies.length; i++) { newFrequencies[i] = sum / (2 * size + 1); sum += frequencies[i + size + 1 < frequencies.length ? i + size + 1 : i + size + 1 - frequencies.length]; sum -= frequencies[i - size < 0 ? frequencies.length + i - size : 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();  }