def _set_scores(self):
anom_scores = {}<EOL>for i, (timestamp, value) in enumerate(self.time_series.items()):<EOL><INDENT>baseline_value = self.baseline_time_series[i]<EOL>if baseline_value > <NUM_LIT:0>:<EOL><INDENT>diff_percent = <NUM_LIT:100> * (value - baseline_value) / baseline_value<EOL><DEDENT>elif value > <NUM_LIT:0>:<EOL><INDENT>diff_percent = <NUM_LIT><EOL><DEDENT>else:<EOL><INDENT>diff_percent = <NUM_LIT:0.0><EOL><DEDENT>anom_scores[timestamp] = <NUM_LIT:0.0><EOL>if self.percent_threshold_upper and diff_percent > <NUM_LIT:0> and diff_percent > self.percent_threshold_upper:<EOL><INDENT>anom_scores[timestamp] = diff_percent<EOL><DEDENT>if self.percent_threshold_lower and diff_percent < <NUM_LIT:0> and diff_percent < self.percent_threshold_lower:<EOL><INDENT>anom_scores[timestamp] = -<NUM_LIT:1> * diff_percent<EOL><DEDENT><DEDENT>self.anom_scores = TimeSeries(self._denoise_scores(anom_scores))<EOL>
Compute anomaly scores for the time series
This algorithm just takes the diff of threshold with current value as anomaly score