Skip to content

Commit 72a05d3

Browse files
authored
Merge pull request #121 from pdurham2/diff_order-fix
Diff order not passing hardcoded value fix
2 parents 5f17d20 + 032ab38 commit 72a05d3

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

luminaire/model/lad_filtering.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ def _scoring(cls, raw_actual=None, synthetic_actual=None, model=None, state_mean
297297
actual_previous_per_diff = [interpolated_actual_previous[-1]] \
298298
if diff_order == 1 else [interpolated_actual_previous[-1], np.diff(interpolated_actual_previous)[0]]
299299
seq_tail = interpolated_actual_previous + [interpolated_actual]
300-
interpolated_actual = np.diff(seq_tail, 2)[-1]
300+
interpolated_actual = np.diff(seq_tail, diff_order)[-1]
301301

302302
post_pred = prior_pred + kalman_gain[0][0] * (interpolated_actual - (observation_matrix[0][0] * prior_pred))
303303

luminaire/tests/test_models.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,19 @@ def test_low_freq_window_density_scoring_aggregated(self, window_density_model_d
193193
result = window_density_model_hourly_aggregated.score(data)
194194

195195
assert result[0]['Success'] and isinstance(result[0]['AnomalyProbability'], float)
196+
197+
def test_lad_filtering_scoring_diff_order(self, scoring_test_data, lad_filtering_model):
198+
import numpy as np
199+
# check to see if scoring yields AdjustedActual with correct order of differences
200+
pred_date_normal = scoring_test_data.index[0]
201+
value_normal = scoring_test_data['raw'][0]
202+
output_normal, lad_filtering_model_update = lad_filtering_model.score(value_normal, pred_date_normal)
203+
# collect data
204+
diff_order = output_normal["NonStationarityDiffOrder"]
205+
adj_actual = output_normal["AdjustedActual"]
206+
last_points = lad_filtering_model._params['last_data_points']
207+
last_points.append(value_normal)
208+
# diff with model's diff_order
209+
diff = np.diff(last_points, diff_order)[-1]
210+
211+
assert diff == adj_actual, f"AdjustedActual {adj_actual} does not match diff {diff_order} of last_data_points {last_points}"

0 commit comments

Comments
 (0)