コード例 #1
0
        private static void SerializeAlgorithm(AnomalyDetectionAlgorithm algorithm)
        {
            Stream          algorithmStream = File.Create(algorithmSerializedFile);
            BinaryFormatter sr = new BinaryFormatter();

            sr.Serialize(algorithmStream, algorithm);
            algorithmStream.Close();
        }
コード例 #2
0
        public void AnomalyDetectionAlgorithmAccuracy()
        {
            var algObject = new AnomalyDetectionAlgorithm();

            algObject.SetAccuracy(null);

            Assert.AreEqual(algObject.GetAccuracy(), null);
        }
コード例 #3
0
        private static AnomalyDetectionAlgorithm DeserializeAlgorithm()
        {
            Stream                    algorithmStream = File.OpenRead(algorithmSerializedFile);
            BinaryFormatter           deserializer    = new BinaryFormatter();
            AnomalyDetectionAlgorithm algorithm       = (AnomalyDetectionAlgorithm)deserializer.Deserialize(algorithmStream);

            algorithmStream.Close();
            return(algorithm);
        }
コード例 #4
0
        private static AnomalyDetectionAlgorithm CreateDetectionAlgorithm()
        {
            AnomalyDetectionAlgorithm algorithm = null;

            if (File.Exists(algorithmSerializedFile))
            {
                algorithm        = DeserializeAlgorithm();
                timeWindowNumber = algorithm.timeWindowNumber;
            }
            else
            {
                algorithm = new AnomalyDetectionAlgorithm(locations, timeWindowNumber);
            }

            return(algorithm);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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])));
        }
コード例 #7
0
        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);
        }