Skip to content

Commit b177a08

Browse files
committed
Add savgol weighted regression tests
1 parent 59aa42e commit b177a08

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

_delphi_utils_python/tests/test_smooth.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,23 @@ def test_causal_savgol_smoother(self):
8888
smoothed_X = smoother.smooth(X)
8989
assert np.allclose(X[window_length - 1 :], smoothed_X[window_length - 1 :])
9090

91+
# The savgol method should match the linear regression method on the first
92+
# window_length-many values of the signal, if the savgol_weighting is set to true,
93+
# and the polynomial fit degree is set to 1.
94+
window_length = 20
95+
signal = np.arange(window_length) + np.random.randn(window_length)
96+
smoother = Smoother(method_name="local_linear")
97+
smoothed_signal1 = smoother.smooth(signal)
98+
smoother = Smoother(
99+
method_name="savgol",
100+
window_length=window_length,
101+
savgol_weighted=True,
102+
poly_fit_degree=1,
103+
)
104+
smoothed_signal2 = smoother.smooth(signal)
105+
106+
assert np.allclose(smoothed_signal1, smoothed_signal2)
107+
91108
def test_impute_with_savgol(self):
92109
# should impute the next value in a linear progression with M>=1
93110
X = np.hstack([np.arange(10), [np.nan], np.arange(10)])

0 commit comments

Comments
 (0)