Skip to content

Commit

Permalink
Merge pull request #121 from pdurham2/diff_order-fix
Browse files Browse the repository at this point in the history
Diff order not passing hardcoded value fix
  • Loading branch information
shahsmit14 authored Nov 23, 2022
2 parents 5f17d20 + 032ab38 commit 72a05d3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion luminaire/model/lad_filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def _scoring(cls, raw_actual=None, synthetic_actual=None, model=None, state_mean
actual_previous_per_diff = [interpolated_actual_previous[-1]] \
if diff_order == 1 else [interpolated_actual_previous[-1], np.diff(interpolated_actual_previous)[0]]
seq_tail = interpolated_actual_previous + [interpolated_actual]
interpolated_actual = np.diff(seq_tail, 2)[-1]
interpolated_actual = np.diff(seq_tail, diff_order)[-1]

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

Expand Down
16 changes: 16 additions & 0 deletions luminaire/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,19 @@ def test_low_freq_window_density_scoring_aggregated(self, window_density_model_d
result = window_density_model_hourly_aggregated.score(data)

assert result[0]['Success'] and isinstance(result[0]['AnomalyProbability'], float)

def test_lad_filtering_scoring_diff_order(self, scoring_test_data, lad_filtering_model):
import numpy as np
# check to see if scoring yields AdjustedActual with correct order of differences
pred_date_normal = scoring_test_data.index[0]
value_normal = scoring_test_data['raw'][0]
output_normal, lad_filtering_model_update = lad_filtering_model.score(value_normal, pred_date_normal)
# collect data
diff_order = output_normal["NonStationarityDiffOrder"]
adj_actual = output_normal["AdjustedActual"]
last_points = lad_filtering_model._params['last_data_points']
last_points.append(value_normal)
# diff with model's diff_order
diff = np.diff(last_points, diff_order)[-1]

assert diff == adj_actual, f"AdjustedActual {adj_actual} does not match diff {diff_order} of last_data_points {last_points}"

0 comments on commit 72a05d3

Please sign in to comment.