Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # test input
- _x = [1,1,2,4,2,4,6,8,9,1,2,3,1,2,1,5]
- _mu = 3
- # define function to handle CUSUM
- def add_by_one(input_array, my_mu):
- # initialize new array that we will return with cumulative sum values
- new_array = []
- # S0 = 0 by definition
- new_array.append(0)
- # loop through the input array values, arrays start at 0
- for index in range(len(input_array)):
- # calc cumulative value, store in temp value
- cumulative_value = new_array[index] + input_array[index] - my_mu
- # take max of cumulative value and zero
- max_value = max(0, cumulative_value)
- # append to the the array
- new_array.append(max_value)
- # return new array, first 0 is S0 that we set to 0 by default
- # you can optionally pop this off before return if you need to
- return new_array
- # print result with test array
- print(add_by_one(_x, _mu))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement