### Question:
DoubleVertexSamples extends Samples<DoubleTensor> { public DoubleTensor getAutocorrelation(long... index) { TensorShapeValidation.checkIndexIsValid(sampleShape, index); long[] indexToGet = getCorrectIndexIfScalar(index); double[] sampleValuesAtIndex = samples.stream() .mapToDouble(x -> x.getValue(indexToGet)) .toArray(); double[] autocorr = Autocorrelation.calculate(sampleValuesAtIndex); return DoubleTensor.create(autocorr); } DoubleVertexSamples(List<DoubleTensor> samples); DoubleTensor getAverages(); DoubleTensor getVariances(); DoubleTensor getAutocorrelation(long... index); @Override DoubleTensor asTensor();  }### Answer:
@Test public void doesCalculateAutocorrelation() { List<DoubleTensor> expectedAutocorrelations = ImmutableList.of( DoubleTensor.create(new double[]{1, -0.15, -0.3, -0.05}, new long[]{1, 4}), DoubleTensor.create(new double[]{1., -0.27380952, -0.30952381, 0.08333333}, new long[]{1, 4}), DoubleTensor.create(new double[]{1., -0.02272727, -0.40909091, -0.06818182}, new long[]{1, 4}) ); for (int i = 0; i < expectedAutocorrelations.size(); i++) { assertThat(samples.getAutocorrelation(0, i), allCloseTo(1e-8, expectedAutocorrelations.get(i))); } }
@Test public void canGetAutocorrelationOnScalarSample() { List<DoubleTensor> sampleValues = ImmutableList.of( DoubleTensor.create(0, Tensor.SCALAR_SHAPE), DoubleTensor.create(-4, Tensor.SCALAR_SHAPE), DoubleTensor.create(8, Tensor.SCALAR_SHAPE), DoubleTensor.create(4, Tensor.SCALAR_SHAPE) ); DoubleVertexSamples scalarSamples = new DoubleVertexSamples(sampleValues); DoubleTensor expectedAutocorrelation = DoubleTensor.create(new double[]{1, -0.15, -0.3, -0.05}, new long[]{1, 4}); assertThat(scalarSamples.getAutocorrelation(), allCloseTo(1e-8, expectedAutocorrelation)); }