SketchyMovingMAD implements OutlierAlgorithm { public SketchyMovingMAD() { } SketchyMovingMAD();  SketchyMovingMAD(OutlierConfig config); SketchyMovingMAD withConfig(OutlierConfig config); Map<String, Distribution.Context> getMedianDistributions(); OutlierConfig getConfig(); Map<String, Distribution.Context> getValueDistributions(); @Override Outlier analyze(DataPoint dp); @Override void configure(OutlierConfig config); static final double ZSCORE; static final String ZSCORE_CUTOFFS_CONF; static final String MIN_AMOUNT_TO_PREDICT; static final String MIN_ZSCORE_PERCENTILE; static final String RESERVOIR_SIZE; static final String DECAY; static final String SMOOTH; }
@Test public void testSketchyMovingMAD() throws IOException { Random r = new Random(0); List<DataPoint> points = new ArrayList<>(); DescriptiveStatistics stats = new DescriptiveStatistics(); DescriptiveStatistics medianStats = new DescriptiveStatistics(); OutlierConfig config = JSONUtil.INSTANCE.load(madConfig, OutlierConfig.class); SketchyMovingMAD madAlgo = ((SketchyMovingMAD)config.getSketchyOutlierAlgorithm()).withConfig(config); int i = 0; for(i = 0; i < 10000;++i) { double val = r.nextDouble() * 1000 - 10000; stats.addValue(val); DataPoint dp = (new DataPoint(i, val, null, "foo")); madAlgo.analyze(dp); points.add(dp); } for(DataPoint dp : points) { medianStats.addValue(Math.abs(dp.getValue() - stats.getPercentile(50))); } double mad = medianStats.getPercentile(50); double median = stats.getPercentile(50); { double val = getValAtModifiedZScore(3.6, mad, median); System.out.println("MODERATE => " + val); DataPoint dp = (new DataPoint(i++, val, null, "foo")); Severity s = madAlgo.analyze(dp).getSeverity(); Assert.assertTrue(s == Severity.MODERATE_OUTLIER ); } { double val = getValAtModifiedZScore(6, mad, median); System.out.println("SEVERE => " + val); DataPoint dp = (new DataPoint(i++, val, null, "foo")); Severity s = madAlgo.analyze(dp).getSeverity(); Assert.assertTrue(s == Severity.SEVERE_OUTLIER ); } Assert.assertTrue(madAlgo.getMedianDistributions().get("foo").getAmount() <= 110); Assert.assertTrue(madAlgo.getMedianDistributions().get("foo").getChunks().size() <= 12); }