Skip to content

Commit

Permalink
Merge pull request #19 from niva-sag/patch-2
Browse files Browse the repository at this point in the history
Update BasicAnomalyDetection.mon
  • Loading branch information
ck-c8y authored Mar 19, 2024
2 parents 84d2bc7 + af6f0e3 commit d692f78
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions repository/blocks/BasicAnomalyDetection.mon
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ event BasicAnomalyDetection {

/** Called once at block start up. */
action $init() {
alpha := $alpha;
numStdDevs := $numStdDevs;
alpha := $parameters.alpha;
numStdDevs := $parameters.numStdDevs;
}

/**
Expand All @@ -98,12 +98,12 @@ event BasicAnomalyDetection {
$blockState.n := 1;
$blockState.stateInitialized := true;
} else {
float prediction := alpha * $input_value + (1 - alpha) * $blockState.lastValue;
float prediction := alpha * $input_value + (1.0 - alpha) * $blockState.lastValue;
float predictionError := $input_value - prediction;
$blockState.variance := alpha * predictionError * predictionError + (1 - alpha) * $blockState.variance;
$blockState.variance := alpha * predictionError * predictionError + (1.0 - alpha) * $blockState.variance;
$blockState.mean := $blockState.mean + ( $input_value - $blockState.mean)/$blockState.n;
$blockState.lastValue := prediction;
$blockState.n = $blockState.n + 1;
$blockState.n := $blockState.n + 1;

// Flag the value as an anomaly if it is outside the threshold
boolean isAnomaly := (predictionError.abs() > numStdDevs * $blockState.variance.sqrt());
Expand Down

0 comments on commit d692f78

Please sign in to comment.