CosineTransform implements IVectorTransform { @Override public double[] transform(final double[] input) { double n = input.length; double[] cosinusTransform = new double[input.length]; for (int k = 0; k < n; k++) { double sum = 0; for (int i = 0; i < n; i++) { sum += input[i] * Math.cos((Math.PI / n) * (i + 0.5) * k); } cosinusTransform[k] = sum; } return cosinusTransform; }  @Override double[] transform(final double[] input);  }
@Test public void testCorrectnessForTransformation() { double[] timeSeries = { 1, 2, 3, 4, 5 }; double[] expectation = { 15, -4.97979657, 0, -0.4490279766, 0 }; CosineTransform cosineTransform = new CosineTransform(); double[] transformed = cosineTransform.transform(timeSeries); assertArrayEquals(expectation, transformed, 0.0001); }