@Test public void testDetect_whiteNoiseWithBreakout() throws Exception { val bufferSize = 20; val hyperparams = new EdmxHyperparams() .setBufferSize(bufferSize) .setDelta(6) .setNumPerms(199) .setStrongAlpha(0.01) .setWeakAlpha(0.05); val trusted = true; val detectorUnderTest = new EdmxDetector(UUID.randomUUID(), hyperparams, trusted); val metricDef = TestObjectMother.metricDefinition(); val is = ClassLoader.getSystemResourceAsStream("datasets/white-noise-with-breakout-at-row-600.csv"); val metricFrame = MetricFrameLoader.loadCsv(metricDef, is, false); val metricDataList = metricFrame.getMetricData(); for (int i = 0; i < 700; i++) { val metricData = metricDataList.get(i); val result = (EdmxDetectorResult) detectorUnderTest.detect(metricData); log.trace("row={}: {}", i + 1, result); assertEquals(i < bufferSize - 1, result.isWarmup()); } }
@Override public DetectorResult detect(MetricData metricData) { notNull(metricData, "metricData can't be null"); buffer.add(metricData); val warmup = buffer.remainingCapacity() > 0; val result = new EdmxDetectorResult().setWarmup(warmup); val trusted = isTrusted(); if (warmup) { log.info("EdmxDetector warming up: uuid={}, size={}, toGo={}, metricData={}", uuid, buffer.size(), buffer.remainingCapacity(), metricData); return result; } val mdValues = buffer.stream().mapToDouble(md -> md.getValue()).toArray(); val estimate = EdmxEstimator.estimate( mdValues, hyperparams.getDelta(), hyperparams.getNumPerms()); val mdList = buffer.stream().collect(Collectors.toList()); val location = estimate.getLocation(); if (location == -1) { return result; } val epochSeconds = mdList.get(location).getTimestamp(); val instant = epochSecondToInstant(epochSeconds); val anomalyLevel = calculateAnomalyLevel(estimate); return result .setTimestamp(instant) .setEdmxEstimate(estimate) .setAnomalyLevel(anomalyLevel) .setTrusted(trusted); }
EdmxDetector implements BreakoutDetector { @Override public DetectorResult detect(MetricData metricData) { notNull(metricData, "metricData can't be null"); buffer.add(metricData); val warmup = buffer.remainingCapacity() > 0; val result = new EdmxDetectorResult().setWarmup(warmup); val trusted = isTrusted(); if (warmup) { log.info("EdmxDetector warming up: uuid={}, size={}, toGo={}, metricData={}", uuid, buffer.size(), buffer.remainingCapacity(), metricData); return result; } val mdValues = buffer.stream().mapToDouble(md -> md.getValue()).toArray(); val estimate = EdmxEstimator.estimate( mdValues, hyperparams.getDelta(), hyperparams.getNumPerms()); val mdList = buffer.stream().collect(Collectors.toList()); val location = estimate.getLocation(); if (location == -1) { return result; } val epochSeconds = mdList.get(location).getTimestamp(); val instant = epochSecondToInstant(epochSeconds); val anomalyLevel = calculateAnomalyLevel(estimate); return result .setTimestamp(instant) .setEdmxEstimate(estimate) .setAnomalyLevel(anomalyLevel) .setTrusted(trusted); } }
EdmxDetector implements BreakoutDetector { @Override public DetectorResult detect(MetricData metricData) { notNull(metricData, "metricData can't be null"); buffer.add(metricData); val warmup = buffer.remainingCapacity() > 0; val result = new EdmxDetectorResult().setWarmup(warmup); val trusted = isTrusted(); if (warmup) { log.info("EdmxDetector warming up: uuid={}, size={}, toGo={}, metricData={}", uuid, buffer.size(), buffer.remainingCapacity(), metricData); return result; } val mdValues = buffer.stream().mapToDouble(md -> md.getValue()).toArray(); val estimate = EdmxEstimator.estimate( mdValues, hyperparams.getDelta(), hyperparams.getNumPerms()); val mdList = buffer.stream().collect(Collectors.toList()); val location = estimate.getLocation(); if (location == -1) { return result; } val epochSeconds = mdList.get(location).getTimestamp(); val instant = epochSecondToInstant(epochSeconds); val anomalyLevel = calculateAnomalyLevel(estimate); return result .setTimestamp(instant) .setEdmxEstimate(estimate) .setAnomalyLevel(anomalyLevel) .setTrusted(trusted); } EdmxDetector(UUID uuid, EdmxHyperparams hyperparams, boolean trusted); }
EdmxDetector implements BreakoutDetector { @Override public DetectorResult detect(MetricData metricData) { notNull(metricData, "metricData can't be null"); buffer.add(metricData); val warmup = buffer.remainingCapacity() > 0; val result = new EdmxDetectorResult().setWarmup(warmup); val trusted = isTrusted(); if (warmup) { log.info("EdmxDetector warming up: uuid={}, size={}, toGo={}, metricData={}", uuid, buffer.size(), buffer.remainingCapacity(), metricData); return result; } val mdValues = buffer.stream().mapToDouble(md -> md.getValue()).toArray(); val estimate = EdmxEstimator.estimate( mdValues, hyperparams.getDelta(), hyperparams.getNumPerms()); val mdList = buffer.stream().collect(Collectors.toList()); val location = estimate.getLocation(); if (location == -1) { return result; } val epochSeconds = mdList.get(location).getTimestamp(); val instant = epochSecondToInstant(epochSeconds); val anomalyLevel = calculateAnomalyLevel(estimate); return result .setTimestamp(instant) .setEdmxEstimate(estimate) .setAnomalyLevel(anomalyLevel) .setTrusted(trusted); } EdmxDetector(UUID uuid, EdmxHyperparams hyperparams, boolean trusted); @Override DetectorResult detect(MetricData metricData); @Override String getName(); }
EdmxDetector implements BreakoutDetector { @Override public DetectorResult detect(MetricData metricData) { notNull(metricData, "metricData can't be null"); buffer.add(metricData); val warmup = buffer.remainingCapacity() > 0; val result = new EdmxDetectorResult().setWarmup(warmup); val trusted = isTrusted(); if (warmup) { log.info("EdmxDetector warming up: uuid={}, size={}, toGo={}, metricData={}", uuid, buffer.size(), buffer.remainingCapacity(), metricData); return result; } val mdValues = buffer.stream().mapToDouble(md -> md.getValue()).toArray(); val estimate = EdmxEstimator.estimate( mdValues, hyperparams.getDelta(), hyperparams.getNumPerms()); val mdList = buffer.stream().collect(Collectors.toList()); val location = estimate.getLocation(); if (location == -1) { return result; } val epochSeconds = mdList.get(location).getTimestamp(); val instant = epochSecondToInstant(epochSeconds); val anomalyLevel = calculateAnomalyLevel(estimate); return result .setTimestamp(instant) .setEdmxEstimate(estimate) .setAnomalyLevel(anomalyLevel) .setTrusted(trusted); } EdmxDetector(UUID uuid, EdmxHyperparams hyperparams, boolean trusted); @Override DetectorResult detect(MetricData metricData); @Override String getName();  }