private void LearnHelper(IDictionary <string, List <float> > table, float maxCore, string f1, string f2) { CorrelatedFeatures cfs = new CorrelatedFeatures(); cfs.Feature1 = f1; cfs.Feature2 = f2; cfs.Corr = maxCore; cfs.Lin_Reg = AnomalyUtils.LinearReg(table[f1], table[f2]); cfs.Threshold = FindThreshold(table[f1], table[f2], cfs.Lin_Reg) * 1.1f; this.cf.Add(cfs); }
//sends each x y pair to dev and returns the highest public float HighestDev(List <float> x, List <float> y, Line line) { float maxDev = 0; for (int i = 0; i < x.Count; i++) { Point p = new Point(x[i], y[i]); float newDev = AnomalyUtils.Dev(p, line); if (newDev > maxDev) { maxDev = newDev; } } return(maxDev); }
private float FindThreshold(List <float> l1, List <float> l2, Line lin_reg) { float max = 0; int size = l1.Count; for (int i = 0; i < size; i++) { Point point = new Point(l1[i], l2[i]); float distance = AnomalyUtils.Dev(point, lin_reg); if (distance > max) { max = distance; } } return(max); }
public List <AnomalyReport> detect(IDictionary <string, List <float> > table) { List <AnomalyReport> anomalyReport = new List <AnomalyReport>(); foreach (CorrelatedFeatures correlatedFeature in cf) { for (int i = 0; i < table[correlatedFeature.Feature1].Count; i++) { Point p = new Point(table[correlatedFeature.Feature1].ElementAt(i), table[correlatedFeature.Feature1].ElementAt(i)); if (AnomalyUtils.Dev(p, correlatedFeature.Lin_Reg) > correlatedFeature.Threshold) { anomalyReport.Add(new AnomalyReport(correlatedFeature.Feature1 + "-" + correlatedFeature.Feature2, i)); } } } return(anomalyReport); }
public void LearnNormal(IDictionary <string, List <float> > table) { int columnSize = table.ElementAt(0).Value.Count; //table.Keys.ElementAt(0) int rowSize = table.Count; for (int i = 0; i < table.Count; i++) { CorrelatedFeatures cfs = new CorrelatedFeatures(); cfs.Corr = -1; cfs.Feature1 = table.ElementAt(i).Key; for (int j = i + 1; j < table.Count; j++) { float correlation = AnomalyUtils.Pearson(table.ElementAt(i).Value, table.ElementAt(j).Value); if (correlation > correlationThreshold) { if (correlation > cfs.Corr) { cfs.Feature2 = table.ElementAt(j).Key; cfs.Corr = correlation; cfs.Lin_Reg = AnomalyUtils.LinearReg(table.ElementAt(i).Value, table.ElementAt(j).Value); cfs.Threshold = HighestDev(table.ElementAt(i).Value, table.ElementAt(j).Value, cfs.Lin_Reg); List <Point> pointsList = new List <Point>(); for (int k = 1; k < columnSize; k++) { pointsList.Add(new Point(table[cfs.Feature1].ElementAt(k), table[cfs.Feature2].ElementAt(k))); } cfs.CircleThreshold = MinCircle.FindMinCircle(pointsList); cfs.CircleThreshold.radius *= 1.1; } } } if (cfs.Corr > -1) { cf.Add(cfs); } } }
public void LearnNormal(IDictionary <string, List <float> > table) { int size = table.Count; for (int i = 0; i < size; i++) { string f1 = table.ElementAt(i).Key; float maxCore = 0; int maxIndex = 0; for (int j = i + 1; j < size; j++) { float cor = Math.Abs(AnomalyUtils.Pearson(table.ElementAt(i).Value, table.ElementAt(j).Value)); if (cor > maxCore) { maxCore = cor; maxIndex = j; } } string fMostCore = table.ElementAt(maxIndex).Key; LearnHelper(table, maxCore, f1, fMostCore); } }
public Line CorrLinReg(string fName, string corrName) { this.linReg = AnomalyUtils.LinearReg(table[fName], table[corrName]); return(this.linReg); }