Coverage for pybreakpoints/ewma_.py : 92%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
""" Exponentially Weighted Moving Average (EWMA) """
#: np.ndarray: Expected value of the sample range of ``n`` normally # distributed variables. Index on ``n - 1`` to retrieve the # value of ``d2(n)`` 2.847, 2.970, 3.078, 3.173, 3.258, 3.336, 3.407, 3.472, 3.532, 3.588, 3.640, 3.689, 3.735, 3.778, 3.819, 3.858, 3.895, 3.931])
def _rolling_window(a, window): """ Return a rolling window using NumPy strides
Reference --------- http://www.rigtorp.se/2011/01/01/rolling-statistics-numpy.html """
# np.ptp not supported by jit yet """ Moving range estimate of standard deviation
Parameters ---------- y : np.ndarray Data k : int Number of observations included in moving range
Returns ------- float Estimated standard deviation """
def _c4(n): """ Bias correction factor for normal distribution
Reference --------- https://en.wikipedia.org/wiki/Unbiased_estimation_of_standard_deviation#Results_for_the_normal_distribution """ np.exp(lgamma(n / 2) - lgamma((n - 1) / 2)))
def _sd_sample(x): """ Sample standard deviation """
""" Calculate control chart boundaries for a given process
Parameters ---------- x : np.ndarray Observations stddev : float Standard deviation of the observations crit : float Critical threshold for boundary, given as a scalar multiplier of the standard deviation lambda_ : float "Memory" parameter, bound [0, 1]
Returns ------- tuple[np.ndarray, np.ndarray] Upper and lower boundaries of process """ (lambda_ / (2 - lambda_)) * (1 - (1 - lambda_) ** (2 * x)))
else: _center = 0.0 sd = std_type else:
# Guard 0 sd sd = 1
idx = idx.min() score = process[idx] signif = True else:
""" Exponentially Weighted Moving Average test
Parameters ---------- y : array like Time series to test. Should be sorted chronologically lambda_ : float "Memory" parameter, bound [0, 1] crit : float Critical threshold for boundary, given as a scalar multiplier of the standard deviation center : bool Center time series before calculating EWMA std_type : {'MR', 'SD', 'MAD'} Method for calculating process standard deviation. Calculated using:
* ``MR`` for an estimate based on the "moving range" of the scaled mean * ``SD`` for the sample standard deviation * ``MAD`` for the Median Absolute Deviation estimate of standard deviation
Returns ------- StructuralBreakResult A named tuple include the the test name, change point (index of ``y``), the test ``score``, and a boolean testing if the EWMA score is significant at the given ``crit`` """
lambda_=lambda_, crit=crit, center=center, std_type=std_type)
process=process, boundary=boundary, index=idx, pvalue=None, score=score, signif=signif) |