All problems
CUSUM Statistic
Problem
Compute the cumulative sum control chart values for a series around a target: S[t] = sum over i <= t of (x[i] - target).
Return the running sums as a list; an empty series gives an empty list.
Hint
A drift in the CUSUM away from zero signals a change in level.
Test cases
case 1
in: [[1,2,3,4],2]
expected: [-1,-1,0,2]
case 2
in: [[5,5,5],5]
expected: [0,0,0]
case 3
in: [[1,2,3],0]
expected: [1,3,6]
case 4
in: [[],1]
expected: []
Starter codePython
def cusum(series, target):
# Your code here
pass4 test cases · run your code against them in the editor