All problems
Integrated Autocorrelation Time
Problem
Estimate the integrated autocorrelation time as tau = 1 + 2 * sum over lags 1..max_lag of the sample autocorrelation at that lag. Each autocorrelation is the sum over i of (x[i] - mean) * (x[i + lag] - mean) divided by the total sum of squared deviations. Return 1.0 for fewer than two samples, max_lag < 1, or a constant sequence.
Hint
Positive autocorrelation inflates the variance of the sample mean, so tau exceeds 1.
Test cases
case 1
in: [[1,2,3,4,5],1]
expected: 1.8
case 2
in: [[1,2,3,4,5],2]
expected: 1.6
case 3
in: [[2,2,2],3]
expected: 1
case 4
in: [[5],4]
expected: 1
case 5
in: [[1,3,2,4,3],2]
expected: 1.046153846153846
Starter codePython
def integrated_autocorrelation_time(samples, max_lag):
# Your code here
pass5 test cases · run your code against them in the editor