@Test public void testUpperThresholds() { val thresholds = new AnomalyThresholds(100.0, 50.0, null, null); Assert.assertEquals(AnomalyLevel.NORMAL, classifierUnderTest_leftTailed.classify(thresholds, 150.0)); assertEquals(AnomalyLevel.NORMAL, classifierUnderTest_leftTailed.classify(thresholds, 75.0)); assertEquals(AnomalyLevel.NORMAL, classifierUnderTest_leftTailed.classify(thresholds, 25.0)); assertEquals(AnomalyLevel.STRONG, classifierUnderTest_rightTailed.classify(thresholds, 150.0)); assertEquals(AnomalyLevel.WEAK, classifierUnderTest_rightTailed.classify(thresholds, 100.0)); assertEquals(AnomalyLevel.WEAK, classifierUnderTest_rightTailed.classify(thresholds, 75.0)); assertEquals(AnomalyLevel.NORMAL, classifierUnderTest_rightTailed.classify(thresholds, 50.0)); assertEquals(AnomalyLevel.NORMAL, classifierUnderTest_rightTailed.classify(thresholds, 25.0)); assertEquals(AnomalyLevel.STRONG, classifierUnderTest_twoTailed.classify(thresholds, 150.0)); assertEquals(AnomalyLevel.WEAK, classifierUnderTest_twoTailed.classify(thresholds, 100.0)); assertEquals(AnomalyLevel.WEAK, classifierUnderTest_twoTailed.classify(thresholds, 75.0)); assertEquals(AnomalyLevel.NORMAL, classifierUnderTest_twoTailed.classify(thresholds, 50.0)); assertEquals(AnomalyLevel.NORMAL, classifierUnderTest_twoTailed.classify(thresholds, 25.0)); }
public AnomalyLevel classify(AnomalyThresholds thresholds, double observed) { notNull(thresholds, "thresholds can't be null"); val checkUpper = (anomalyType == AnomalyType.RIGHT_TAILED || anomalyType == AnomalyType.TWO_TAILED); val checkLower = (anomalyType == AnomalyType.LEFT_TAILED || anomalyType == AnomalyType.TWO_TAILED); val upperStrong = thresholds.getUpperStrong(); val upperWeak = thresholds.getUpperWeak(); val lowerWeak = thresholds.getLowerWeak(); val lowerStrong = thresholds.getLowerStrong(); if (checkUpper) { if (upperStrong != null && observed > upperStrong) { return AnomalyLevel.STRONG; } else if (upperWeak != null && observed > upperWeak) { return AnomalyLevel.WEAK; } } if (checkLower) { if (lowerStrong != null && observed < lowerStrong) { return AnomalyLevel.STRONG; } else if (lowerWeak != null && observed < lowerWeak) { return AnomalyLevel.WEAK; } } return AnomalyLevel.NORMAL; }
AnomalyClassifier { public AnomalyLevel classify(AnomalyThresholds thresholds, double observed) { notNull(thresholds, "thresholds can't be null"); val checkUpper = (anomalyType == AnomalyType.RIGHT_TAILED || anomalyType == AnomalyType.TWO_TAILED); val checkLower = (anomalyType == AnomalyType.LEFT_TAILED || anomalyType == AnomalyType.TWO_TAILED); val upperStrong = thresholds.getUpperStrong(); val upperWeak = thresholds.getUpperWeak(); val lowerWeak = thresholds.getLowerWeak(); val lowerStrong = thresholds.getLowerStrong(); if (checkUpper) { if (upperStrong != null && observed > upperStrong) { return AnomalyLevel.STRONG; } else if (upperWeak != null && observed > upperWeak) { return AnomalyLevel.WEAK; } } if (checkLower) { if (lowerStrong != null && observed < lowerStrong) { return AnomalyLevel.STRONG; } else if (lowerWeak != null && observed < lowerWeak) { return AnomalyLevel.WEAK; } } return AnomalyLevel.NORMAL; } }
AnomalyClassifier { public AnomalyLevel classify(AnomalyThresholds thresholds, double observed) { notNull(thresholds, "thresholds can't be null"); val checkUpper = (anomalyType == AnomalyType.RIGHT_TAILED || anomalyType == AnomalyType.TWO_TAILED); val checkLower = (anomalyType == AnomalyType.LEFT_TAILED || anomalyType == AnomalyType.TWO_TAILED); val upperStrong = thresholds.getUpperStrong(); val upperWeak = thresholds.getUpperWeak(); val lowerWeak = thresholds.getLowerWeak(); val lowerStrong = thresholds.getLowerStrong(); if (checkUpper) { if (upperStrong != null && observed > upperStrong) { return AnomalyLevel.STRONG; } else if (upperWeak != null && observed > upperWeak) { return AnomalyLevel.WEAK; } } if (checkLower) { if (lowerStrong != null && observed < lowerStrong) { return AnomalyLevel.STRONG; } else if (lowerWeak != null && observed < lowerWeak) { return AnomalyLevel.WEAK; } } return AnomalyLevel.NORMAL; }  }
AnomalyClassifier { public AnomalyLevel classify(AnomalyThresholds thresholds, double observed) { notNull(thresholds, "thresholds can't be null"); val checkUpper = (anomalyType == AnomalyType.RIGHT_TAILED || anomalyType == AnomalyType.TWO_TAILED); val checkLower = (anomalyType == AnomalyType.LEFT_TAILED || anomalyType == AnomalyType.TWO_TAILED); val upperStrong = thresholds.getUpperStrong(); val upperWeak = thresholds.getUpperWeak(); val lowerWeak = thresholds.getLowerWeak(); val lowerStrong = thresholds.getLowerStrong(); if (checkUpper) { if (upperStrong != null && observed > upperStrong) { return AnomalyLevel.STRONG; } else if (upperWeak != null && observed > upperWeak) { return AnomalyLevel.WEAK; } } if (checkLower) { if (lowerStrong != null && observed < lowerStrong) { return AnomalyLevel.STRONG; } else if (lowerWeak != null && observed < lowerWeak) { return AnomalyLevel.WEAK; } } return AnomalyLevel.NORMAL; }  AnomalyLevel classify(AnomalyThresholds thresholds, double observed); }
AnomalyClassifier { public AnomalyLevel classify(AnomalyThresholds thresholds, double observed) { notNull(thresholds, "thresholds can't be null"); val checkUpper = (anomalyType == AnomalyType.RIGHT_TAILED || anomalyType == AnomalyType.TWO_TAILED); val checkLower = (anomalyType == AnomalyType.LEFT_TAILED || anomalyType == AnomalyType.TWO_TAILED); val upperStrong = thresholds.getUpperStrong(); val upperWeak = thresholds.getUpperWeak(); val lowerWeak = thresholds.getLowerWeak(); val lowerStrong = thresholds.getLowerStrong(); if (checkUpper) { if (upperStrong != null && observed > upperStrong) { return AnomalyLevel.STRONG; } else if (upperWeak != null && observed > upperWeak) { return AnomalyLevel.WEAK; } } if (checkLower) { if (lowerStrong != null && observed < lowerStrong) { return AnomalyLevel.STRONG; } else if (lowerWeak != null && observed < lowerWeak) { return AnomalyLevel.WEAK; } } return AnomalyLevel.NORMAL; }  AnomalyLevel classify(AnomalyThresholds thresholds, double observed);  }