/// <summary> /// this function parses resource csv file in order to set list of CorrelatedFeatures. /// </summary> void learnNormal() { // read CorrelatedFeatures from resource csv using (var stream = Assembly .GetExecutingAssembly() .GetManifestResourceStream("LinearRegressionDLL.regFlightModelCsv.resources")) using (StreamReader csvReader = new StreamReader(stream)) { // skip the first row, where the columns names are mentioned. string currLine = csvReader.ReadLine(); string[] columns = { }; List <string> lineData = new List <string>(); char colSeparator = ','; // for each row in the csv file while ((currLine = csvReader.ReadLine()) != null) { lineData = currLine.Split(colSeparator).Select(x => x.ToString()).ToList(); // if the new line is empty if (lineData[0] == "" || lineData.Count != 6) { break; } // parse the row into a CorrelatedFeatures object CorrelatedFeatures corrFeature = new CorrelatedFeatures(); corrFeature.feature1 = lineData[0]; corrFeature.feature2 = lineData[1]; corrFeature.corrlation = double.Parse(lineData[2]); corrFeature.threshold = double.Parse(lineData[3]); corrFeature.regression_line = new Line(double.Parse(lineData[4]), double.Parse(lineData[5])); this.cf.Add(corrFeature); } } }
/// <summary> /// this function checks if there is a significant deviation between the given point and the regression line of the correalted feature. /// </summary> /// <param name="corrFeature"> a correlated feature </param> /// <param name="p"> a point </param> /// <returns> true - if there is a significant deviation, false if not. </returns> bool detectedDev(CorrelatedFeatures corrFeature, Point p) { double detected_dev = AnomalyDetectionUtil.dev(p, corrFeature.regression_line); return(detected_dev > corrFeature.threshold); }