From 0fca838aca986cde7933f72723540851f8ded28a Mon Sep 17 00:00:00 2001 From: JIN CHEN Date: Mon, 11 Dec 2017 21:19:05 +0800 Subject: [PATCH] change the expression of cost for normal mean and double the penalty --- changepy/costs.py | 12 +++++++----- changepy/pelt.py | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/changepy/costs.py b/changepy/costs.py index dd1238d..5889f63 100644 --- a/changepy/costs.py +++ b/changepy/costs.py @@ -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 @@ -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 @@ -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 diff --git a/changepy/pelt.py b/changepy/pelt.py index 0b97ab6..b84d44d 100644 --- a/changepy/pelt.py +++ b/changepy/pelt.py @@ -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)