Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions changepy/costs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np

def normal_mean(data, variance):
def normal_mean(data):
""" Creates a segment cost function for a time series with a
Normal distribution with changing mean

Expand All @@ -16,12 +16,13 @@ def normal_mean(data, variance):
if not isinstance(data, np.ndarray):
data = np.array(data)

i_variance_2 = 1 / (variance ** 2)
#i_variance_2 = 1 / (variance ** 2)
cmm = [0.0]
cmm.extend(np.cumsum(data))

cmm2 = [0.0]
cmm2.extend(np.cumsum(np.abs(data)))
#cmm2.extend(np.cumsum(np.abs(data))) Modified
cmm2.extend(np.cumsum(np.power(data,2)))

def cost(start, end):
""" Cost function for normal distribution with variable mean
Expand All @@ -35,8 +36,9 @@ def cost(start, end):
cmm2_diff = cmm2[end] - cmm2[start]
cmm_diff = pow(cmm[end] - cmm[start], 2)
i_diff = end - start
diff = cmm2_diff - cmm_diff
return (diff/i_diff) * i_variance_2
diff = cmm2_diff - cmm_diff/i_diff #modified
#return (diff/i_diff) * i_variance_2
return diff

return cost

Expand Down
2 changes: 1 addition & 1 deletion changepy/pelt.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def pelt(cost, length, pen=None):
(:obj:`list` of int): List with the indexes of changepoints
"""
if pen is None:
pen = np.log(length)
pen = 2*np.log(length) # modified

F = np.zeros(length + 1)
R = np.array([0], dtype=np.int)
Expand Down