public virtual bool isAnomaly(Timeseries ts, correlatedFeatures cf, int timeStep) { List <float> Column1 = ts.GetColumn(cf.feature1); List <float> Column2 = ts.GetColumn(cf.feature2); Point currPoint = new Point(Column1[timeStep], Column2[timeStep]); float currDev = Anomaly_Detection_Util.dev(currPoint, cf.lin_reg); return(currDev > cf.threshold * 1.1); }
public float getMaxDev(List <Point> points, Line lin_reg) { float maxDev = 0; for (int i = 0; i < points.Count; i++) { float currDev = Anomaly_Detection_Util.dev(points[i], lin_reg); if (currDev > maxDev) { maxDev = currDev; } } return(maxDev); }
public virtual void addCorrelation(Timeseries ts, string feat1, string feat2, float pearson) { if (pearson > linThreshold) { correlatedFeatures correlation = new correlatedFeatures(); correlation.feature1 = feat1; correlation.feature2 = feat2; correlation.corrlation = pearson; var Column1 = ts.GetColumn(feat1); var Column2 = ts.GetColumn(feat2); correlation.lin_reg = Anomaly_Detection_Util.LinReg(Column1, Column2); correlation.threshold = getMaxDev(Timeseries.CombineColumns(Column1, Column2), correlation.lin_reg); cf.Add(correlation); } }
public void LearnNormal(Timeseries ts) { for (int i = 0; i < ts.NumOfColumns - 1; i++) { List <float> Column1 = ts.GetColumn(i); float max = 0; int maxIndex = -1; for (int j = i + 1; j < ts.NumOfColumns; j++) { List <float> Column2 = ts.GetColumn(j); float correlativity = (float)Math.Abs(Anomaly_Detection_Util.Pearson(Column1, Column2)); if (correlativity > max) { max = correlativity; maxIndex = j; } } if (maxIndex >= 0) { addCorrelation(ts, ts.GetColumnName(i), ts.GetColumnName(maxIndex), max); } } }