private static void SerializeAlgorithm(AnomalyDetectionAlgorithm algorithm) { Stream algorithmStream = File.Create(algorithmSerializedFile); BinaryFormatter sr = new BinaryFormatter(); sr.Serialize(algorithmStream, algorithm); algorithmStream.Close(); }
public void AnomalyDetectionAlgorithmAccuracy() { var algObject = new AnomalyDetectionAlgorithm(); algObject.SetAccuracy(null); Assert.AreEqual(algObject.GetAccuracy(), null); }
private static AnomalyDetectionAlgorithm DeserializeAlgorithm() { Stream algorithmStream = File.OpenRead(algorithmSerializedFile); BinaryFormatter deserializer = new BinaryFormatter(); AnomalyDetectionAlgorithm algorithm = (AnomalyDetectionAlgorithm)deserializer.Deserialize(algorithmStream); algorithmStream.Close(); return(algorithm); }
private static AnomalyDetectionAlgorithm CreateDetectionAlgorithm() { AnomalyDetectionAlgorithm algorithm = null; if (File.Exists(algorithmSerializedFile)) { algorithm = DeserializeAlgorithm(); timeWindowNumber = algorithm.timeWindowNumber; } else { algorithm = new AnomalyDetectionAlgorithm(locations, timeWindowNumber); } return(algorithm); }
public void AnomalyDetectionAlgorithmTrainingTest() { var listOfStudents = this.GetStudentListForPMI43(); var normal = new[] { "2", "13", "6" }; var anomalies = new[] { "8", "10" }; var trainingSets = TrainingSetsCreator.GenerateTrainingSets(listOfStudents, normal, anomalies); var algirithmResults = AnomalyDetectionAlgorithm.RunAlg( listOfStudents, trainingSets[0], trainingSets[1], trainingSets[2]); Assert.AreEqual(algirithmResults.First(x => x.Key.Key.OpenId == "2").Value, false); Assert.AreEqual(algirithmResults.First(x => x.Key.Key.OpenId == "6").Value, false); Assert.AreEqual(algirithmResults.First(x => x.Key.Key.OpenId == "13").Value, false); Assert.AreEqual(algirithmResults.First(x => x.Key.Key.OpenId == "8").Value, true); Assert.AreEqual(algirithmResults.First(x => x.Key.Key.OpenId == "10").Value, true); }
public ActionResult TrainAlg(string[] tsNormal, string[] tsAnomalies) { int topicId = (int)HttpContext.Session["TopicId"]; var studentsAndMarks = _Storage.GetAllStudentListForTraining(topicId); TrainingSet[] tr; try { tr = TrainingSetsCreator.generateTrainingSets(studentsAndMarks, tsNormal, tsAnomalies); } catch (Exception ex) { HttpContext.Session["ShowError"] = true; return(RedirectToAction("TrainTopic", "AnomalyDetection", new { id = (int)HttpContext.Session["TopicId"] })); } return(View(AnomalyDetectionAlgorithm.runAlg(studentsAndMarks, tr[0], tr[1], tr[2]))); }
static void Main(string[] args) { Parameters parameters = ReadParameters(); AnomalyDetectionAlgorithm algorithm = null; CreateLocations(); if (parameters.restart.Equals("yes")) { DataManager.CleanUpOutput(@".\Output\"); DataManager.CompressZediAccessData(); if (locations.Count > 0) { DataManager.CreateHistorianDatabase(locations); } else { Console.WriteLine("Locations are not defined!"); return; } } algorithm = CreateDetectionAlgorithm(); foreach (string location in locations) { /*bool isThereDataThisTimeWindow =*/ DataManager.RetrieveLastTimewindowData(location, timeWindowNumber, physicalQuantityToMonitor, parameters); algorithm.Detect(parameters, location); } ++algorithm.timeWindowNumber; SerializeAlgorithm(algorithm); string[] linesInFile = File.ReadAllLines(@".\Input\Parameters.txt"); linesInFile[0] = "restart\tno"; File.WriteAllLines(@".\Input\Parameters.txt", linesInFile); }