예제 #1
0
    public bool isAnomalous(correlatedFeatures cf, Point point)
    {
        float correlation = adu.dev(point, cf.lin_reg);

        if (correlation > cf.threshold)
        {
            return(true);
        }
        return(false);
    }
예제 #2
0
    public void learnNormal(Timeseries ts)
    {
        anomaly_detection_util             adu   = new anomaly_detection_util();
        Dictionary <string, List <float> > tsMap = ts.table;
        List <string> tsFeaturesVector           = ts.features;
        int           featuresVectorSize         = tsFeaturesVector.Count();
        int           valueVectorSize            = tsMap[tsFeaturesVector[0]].Count();

        for (int i = 0; i < featuresVectorSize; ++i)
        {
            string             fiName     = tsFeaturesVector[i];
            float[]            fiData     = tsMap[fiName].ToArray();
            float              maxPearson = 0;
            correlatedFeatures currentCF  = new correlatedFeatures();
            currentCF.feature1 = fiName;
            for (int j = i + 1; j < featuresVectorSize; ++j)
            {
                string  fjName         = tsFeaturesVector[j];
                float[] fjData         = tsMap[fjName].ToArray();
                float   currentPearson = Math.Abs(adu.pearson(fiData, fjData, valueVectorSize));
                if (currentPearson > maxPearson)
                {
                    maxPearson         = currentPearson;
                    currentCF.feature2 = fjName;
                }
            }
            if (maxPearson > this.threshold)
            {
                currentCF.corrlation = maxPearson;
                Point[] points = new Point[valueVectorSize];
                for (int j = 0; j < valueVectorSize; ++j)
                {
                    points[j] = new Point(tsMap[currentCF.feature1][j], tsMap[currentCF.feature2][j]);
                }
                currentCF.lin_reg   = adu.linear_reg(points, valueVectorSize);
                currentCF.threshold = 0;
                for (int j = 0; j < valueVectorSize; ++j)
                {
                    currentCF.threshold = Math.Max(currentCF.threshold, Math.Abs(adu.dev(points[j], currentCF.lin_reg)));
                }
                currentCF.threshold *= (float)1.1;
                cf.Add(currentCF);
            }
        }
    }