ComplexityInvariantDistance implements IDistanceMetric { @Override public double distance(final double[] a, final double[] b) { double complexityA = this.complexityMeasure.complexity(a); double complexityB = this.complexityMeasure.complexity(b); double complexityCorrectionFactor = Math.max(complexityA, complexityB) / Math.min(complexityA, complexityB); return this.distanceMeasure.distance(a, b) * complexityCorrectionFactor; } ComplexityInvariantDistance(final IDistanceMetric distanceMeasure, final ITimeSeriesComplexity complexityMeasure); @Override double distance(final double[] a, final double[] b);  }
@Test public void testCorrectnessForDistanceCalculation() { double[] timeSeries1 = { 1, 1, 1, 1, 1, 1 }; double[] timeSeries2 = { .0, Math.sqrt(8), .0, Math.sqrt(8), .0, Math.sqrt(8) }; double expectation = euclideanDistance.distance(timeSeries1, timeSeries2) * (15 / 5); ComplexityInvariantDistance cid = new ComplexityInvariantDistance(euclideanDistance, stretchingComplexity); double distance = cid.distance(timeSeries1, timeSeries2); assertEquals(expectation, distance, 0.001); }