public void TestAnomalyCumulative() { Parameters @params = Parameters.Empty(); @params.SetParameterByKey(Parameters.KEY.ANOMALY_KEY_MODE, Anomaly.Mode.PURE); @params.SetParameterByKey(Parameters.KEY.ANOMALY_KEY_WINDOW_SIZE, 3); @params.SetParameterByKey(Parameters.KEY.ANOMALY_KEY_USE_MOVING_AVG, true); Anomaly anomalyComputer = Anomaly.Create(@params); object[] predicted = { new[] { 1, 2, 6 }, new[] { 1, 2, 6 }, new[] { 1, 2, 6 }, new[] { 1, 2, 6 }, new[] { 1, 2, 6 }, new[] { 1, 2, 6 }, new[] { 1, 2, 6 }, new[] { 1, 2, 6 }, new[] { 1, 2, 6 } }; object[] actual = { new[] { 1, 2, 6 }, new[] { 1, 2, 6 }, new[] { 1, 4, 6 }, new[] { 10, 11, 6 }, new[] { 10, 11, 12 }, new[] { 10, 11, 12 }, new[] { 10, 11, 12 }, new[] { 1, 2, 6 }, new[] { 1, 2, 6 } }; double[] anomalyExpected = { 0.0, 0.0, 1.0 / 9.0, 3.0 / 9.0, 2.0 / 3.0, 8.0 / 9.0, 1.0, 2.0 / 3.0, 1.0 / 3.0 }; for (int i = 0; i < 9; i++) { double score = anomalyComputer.Compute((int[])actual[i], (int[])predicted[i], 0, 0); Assert.AreEqual(anomalyExpected[i], score, 0.01); } }
public void TestComputeAnomalyScoreNoMatch() { Parameters @params = Parameters.Empty(); @params.SetParameterByKey(Parameters.KEY.ANOMALY_KEY_MODE, Anomaly.Mode.PURE); Anomaly anomalyComputer = Anomaly.Create(@params); double score = anomalyComputer.Compute(new[] { 2, 4, 6 }, new[] { 3, 5, 7 }, 0, 0); Assert.AreEqual(1.0, score, 0); }
public void TestComputeAnomalyScoreNoActiveOrPredicted() { Parameters @params = Parameters.Empty(); @params.SetParameterByKey(Parameters.KEY.ANOMALY_KEY_MODE, Anomaly.Mode.PURE); Anomaly anomalyComputer = Anomaly.Create(@params); double score = anomalyComputer.Compute(new int[0], new int[0], 0, 0); Assert.AreEqual(0.0, score, 0); }
public void TestSerializeAnomaly() { Parameters @params = Parameters.Empty(); @params.SetParameterByKey(Parameters.KEY.ANOMALY_KEY_MODE, Anomaly.Mode.PURE); Anomaly anomalyComputer = Anomaly.Create(@params); // Serialize the Anomaly Computer without errors SerialConfig config = new SerialConfig("testSerializeAnomaly1", SerialConfig.SERIAL_TEST_DIR); IPersistenceAPI api = Persistence.Get(config); byte[] bytes = api.Write(anomalyComputer); double score = anomalyComputer.Compute(new int[0], new int[0], 0, 0); score = anomalyComputer.Compute(new int[0], new int[0], 0, 0); Assert.AreEqual(0.0, score, 0); score = anomalyComputer.Compute(new int[0], new int[] { 3, 5 }, 0, 0); Assert.AreEqual(0.0, score, 0); score = anomalyComputer.Compute(new int[] { 3, 5, 7 }, new int[] { 3, 5, 7 }, 0, 0); Assert.AreEqual(0.0, score, 0); score = anomalyComputer.Compute(new int[] { 2, 3, 6 }, new int[] { 3, 5, 7 }, 0, 0); Assert.AreEqual(2.0 / 3.0, score, 0); // Deserialize the Anomaly Computer and make sure its usable (same tests as AnomalyTest.java) Anomaly serializedAnomalyComputer = api.Read <Anomaly>(bytes); score = serializedAnomalyComputer.Compute(new int[0], new int[0], 0, 0); Assert.AreEqual(0.0, score, 0); score = serializedAnomalyComputer.Compute(new int[0], new int[] { 3, 5 }, 0, 0); Assert.AreEqual(0.0, score, 0); score = serializedAnomalyComputer.Compute(new int[] { 3, 5, 7 }, new int[] { 3, 5, 7 }, 0, 0); Assert.AreEqual(0.0, score, 0); score = serializedAnomalyComputer.Compute(new int[] { 2, 3, 6 }, new int[] { 3, 5, 7 }, 0, 0); Assert.AreEqual(2.0 / 3.0, score, 0); }
public void TestSerializeCumulativeAnomaly() { Parameters @params = Parameters.Empty(); @params.SetParameterByKey(Parameters.KEY.ANOMALY_KEY_MODE, Anomaly.Mode.PURE); @params.SetParameterByKey(Parameters.KEY.ANOMALY_KEY_WINDOW_SIZE, 3); @params.SetParameterByKey(Parameters.KEY.ANOMALY_KEY_USE_MOVING_AVG, true); Anomaly anomalyComputer = Anomaly.Create(@params); // Serialize the Anomaly Computer without errors SerialConfig config = new SerialConfig("testSerializeCumulativeAnomaly", SerialConfig.SERIAL_TEST_DIR); IPersistenceAPI api = Persistence.Get(config); byte[] bytes = api.Write(anomalyComputer); // Deserialize the Anomaly Computer and make sure its usable (same tests as AnomalyTest.java) Anomaly serializedAnomalyComputer = api.Read <Anomaly>(bytes); Assert.IsNotNull(serializedAnomalyComputer); Object[] predicted = { new int[] { 1, 2, 6 }, new int[] { 1, 2, 6 }, new int[] { 1, 2, 6 }, new int[] { 1, 2, 6 }, new int[] { 1, 2, 6 }, new int[] { 1, 2, 6 }, new int[] { 1, 2, 6 }, new int[] { 1, 2, 6 }, new int[] { 1, 2, 6 } }; Object[] actual = { new int[] { 1, 2, 6 }, new int[] { 1, 2, 6 }, new int[] { 1, 4, 6 }, new int[] { 10, 11, 6 }, new int[] { 10, 11, 12 }, new int[] { 10, 11, 12 }, new int[] { 10, 11, 12 }, new int[] { 1, 2, 6 }, new int[] { 1, 2, 6 } }; double[] anomalyExpected = { 0.0, 0.0, 1.0 / 9.0, 3.0 / 9.0, 2.0 / 3.0, 8.0 / 9.0, 1.0, 2.0 / 3.0, 1.0 / 3.0 }; for (int i = 0; i < 9; i++) { double score = serializedAnomalyComputer.Compute((int[])actual[i], (int[])predicted[i], 0, 0); Assert.AreEqual(anomalyExpected[i], score, 0.01); } }