Esempio n. 1
0
 public static string RecallString(RecallLevel level)
 {
     switch (level)
         {
             case RecallLevel.Recall10:
                 return "Recall 10%";
             case RecallLevel.Recall20:
                 return "Recall 20%";
             case RecallLevel.Recall30:
                 return "Recall 30%";
             case RecallLevel.Recall40:
                 return "Recall 40%";
             case RecallLevel.Recall50:
                 return "Recall 50%";
             case RecallLevel.Recall60:
                 return "Recall 60%";
             case RecallLevel.Recall70:
                 return "Recall 70%";
             case RecallLevel.Recall80:
                 return "Recall 80%";
             case RecallLevel.Recall90:
                 return "Recall 90%";
             case RecallLevel.Recall100:
                 return "Recall 100%";
             default:
                 return "Unknown";
         }
 }
Esempio n. 2
0
 public static double RecallValue(RecallLevel level)
 {
     switch (level)
         {
             case RecallLevel.Recall10:
                 return 0.1;
             case RecallLevel.Recall20:
                 return 0.2;
             case RecallLevel.Recall30:
                 return 0.3;
             case RecallLevel.Recall40:
                 return 0.4;
             case RecallLevel.Recall50:
                 return 0.5;
             case RecallLevel.Recall60:
                 return 0.6;
             case RecallLevel.Recall70:
                 return 0.7;
             case RecallLevel.Recall80:
                 return 0.8;
             case RecallLevel.Recall90:
                 return 0.9;
             case RecallLevel.Recall100:
                 return 1.0;
             default:
                 return 0.0;
         }
 }
 public static string ShortRecallString(RecallLevel level)
 {
     switch (level)
     {
         case RecallLevel.Recall10:
             return "R10";
         case RecallLevel.Recall20:
             return "R20";
         case RecallLevel.Recall30:
             return "R30";
         case RecallLevel.Recall40:
             return "R40";
         case RecallLevel.Recall50:
             return "R50";
         case RecallLevel.Recall60:
             return "R60";
         case RecallLevel.Recall70:
             return "R70";
         case RecallLevel.Recall80:
             return "R80";
         case RecallLevel.Recall90:
             return "R90";
         case RecallLevel.Recall100:
             return "R100";
         default:
             return "Unknown";
     }
 }
 public static void ComputeMetrics(TLSimilarityMatrix sims, TLSimilarityMatrix oracle, RecallLevel level,
     out TLKeyValuePairsList precision, out TLKeyValuePairsList recall, out TLKeyValuePairsList avgPrecision, out TLKeyValuePairsList meanAvgPrecision)
 {
     TLLinksList links = MetricsUtil.GetLinksAtRecall(sims, oracle, level);
     int numCorrect = 0;
     int totalRead = 0;
     double totalAvgPrecision = 0.0;
     foreach (TLSingleLink link in links)
     {
         totalRead++;
         if (oracle.IsLinkAboveThreshold(link.SourceArtifactId, link.TargetArtifactId))
         {
             numCorrect++;
             totalAvgPrecision += numCorrect / (double) totalRead;
         }
     }
     // temporary
     precision = new TLKeyValuePairsList();
     precision.Add(new KeyValuePair<string, double>("#TOTAL", numCorrect / Convert.ToDouble(links.Count)));
     recall = new TLKeyValuePairsList();
     recall.Add(new KeyValuePair<string, double>("#TOTAL", Math.Ceiling(oracle.Count * RecallLevelUtil.RecallValue(level)) / oracle.Count));
     avgPrecision = new TLKeyValuePairsList();
     avgPrecision.Add(new KeyValuePair<string, double>("#TOTAL", totalAvgPrecision / oracle.Count));
     meanAvgPrecision = new TLKeyValuePairsList();
     meanAvgPrecision.Add(new KeyValuePair<string,double>("#TOTAL", MeanAveragePrecision.Compute(Similarities.CreateMatrix(links), oracle)));
 }
        public static DataSetPairs Compute(TLSimilarityMatrix sims, TLSimilarityMatrix oracle, RecallLevel recall)
        {
            TLSimilarityMatrix matrix = Similarities.CreateMatrix(MetricsUtil.GetLinksAtRecall(sims, oracle, recall));
            matrix.Threshold = double.MinValue;
            DataSetPairs pairs = new DataSetPairs();

            foreach (string sourceArtifact in oracle.SourceArtifactsIds)
            {
                TLLinksList links = matrix.GetLinksAboveThresholdForSourceArtifact(sourceArtifact);
                links.Sort();
                int totalCorrect = oracle.GetLinksAboveThresholdForSourceArtifact(sourceArtifact).Count;
                int numCorrect = 0;
                int totalRead = 0;
                double totalAvgPrecision = 0.0;
                foreach (TLSingleLink link in links)
                {
                    totalRead++;
                    if (oracle.IsLinkAboveThreshold(link.SourceArtifactId, link.TargetArtifactId))
                    {
                        numCorrect++;
                        totalAvgPrecision += numCorrect / (double)totalRead;
                    }
                }
                pairs.PrecisionData.Add(new KeyValuePair<string, double>(sourceArtifact, numCorrect / Convert.ToDouble(links.Count)));
                pairs.RecallData.Add(new KeyValuePair<string, double>(sourceArtifact, Convert.ToDouble(numCorrect) / totalCorrect));
                pairs.AveragePrecisionData.Add(new KeyValuePair<string, double>(sourceArtifact, totalAvgPrecision / totalCorrect));
            }

            pairs.MeanAveragePrecisionData.Add(new KeyValuePair<string, double>("#TOTAL", DataSetPairsCollection.CalculateAverage(pairs.AveragePrecisionData)));
            return pairs;
        }
 public static DataSetPairs Compute(TLSimilarityMatrix sims, TLSimilarityMatrix oracle, RecallLevel level)
 {
     TLKeyValuePairsList precision;
     TLKeyValuePairsList recall;
     TLKeyValuePairsList avgPrecision;
     TLKeyValuePairsList meanAvgPrecision;
     ComputeMetrics(sims, oracle, level, out precision, out recall, out avgPrecision, out meanAvgPrecision);
     return new DataSetPairs
     {
         Name = RecallLevelUtil.ShortRecallString(level),
         PrecisionData = precision,
         RecallData = recall,
         AveragePrecisionData = avgPrecision,
         MeanAveragePrecisionData = meanAvgPrecision,
     };
 }
Esempio n. 7
0
 public static TLLinksList GetLinksAtRecall(TLSimilarityMatrix sims, TLSimilarityMatrix oracle, RecallLevel level)
 {
     double totalCorrect = oracle.Count * RecallLevelUtil.RecallValue(level);
     int numCorrect = 0;
     TLLinksList list = new TLLinksList();
     TLLinksList links = sims.AllLinks;
     links.Sort();
     while (links.Count > 0 && numCorrect < totalCorrect)
     {
         TLSingleLink link = links[0];
         if (oracle.IsLinkAboveThreshold(link.SourceArtifactId, link.TargetArtifactId))
         {
             numCorrect++;
         }
         list.Add(link);
         links.RemoveAt(0);
     }
     return list;
 }
Esempio n. 8
0
        public static int RecallLevelToIndex(RecallLevel rLevel)
        {
            if (recallLevelToIndexMap == null)
            {
                recallLevelToIndexMap = new Dictionary <RecallLevel, int>();
                recallLevelToIndexMap[RecallLevel.Default] = 0;
                recallLevelToIndexMap[RecallLevel.Recall1] = 1;
                recallLevelToIndexMap[RecallLevel.Recall2] = 2;
                recallLevelToIndexMap[RecallLevel.Recall3] = 3;
            }

            int index = 0;

            if (recallLevelToIndexMap.ContainsKey(rLevel))
            {
                index = recallLevelToIndexMap[rLevel];
            }

            return(index);
        }
Esempio n. 9
0
        public static string ShortRecallString(RecallLevel level)
        {
            switch (level)
            {
            case RecallLevel.Recall10:
                return("R10");

            case RecallLevel.Recall20:
                return("R20");

            case RecallLevel.Recall30:
                return("R30");

            case RecallLevel.Recall40:
                return("R40");

            case RecallLevel.Recall50:
                return("R50");

            case RecallLevel.Recall60:
                return("R60");

            case RecallLevel.Recall70:
                return("R70");

            case RecallLevel.Recall80:
                return("R80");

            case RecallLevel.Recall90:
                return("R90");

            case RecallLevel.Recall100:
                return("R100");

            default:
                return("Unknown");
            }
        }
Esempio n. 10
0
        public static string RecallString(RecallLevel level)
        {
            switch (level)
            {
            case RecallLevel.Recall10:
                return("Recall 10%");

            case RecallLevel.Recall20:
                return("Recall 20%");

            case RecallLevel.Recall30:
                return("Recall 30%");

            case RecallLevel.Recall40:
                return("Recall 40%");

            case RecallLevel.Recall50:
                return("Recall 50%");

            case RecallLevel.Recall60:
                return("Recall 60%");

            case RecallLevel.Recall70:
                return("Recall 70%");

            case RecallLevel.Recall80:
                return("Recall 80%");

            case RecallLevel.Recall90:
                return("Recall 90%");

            case RecallLevel.Recall100:
                return("Recall 100%");

            default:
                return("Unknown");
            }
        }
Esempio n. 11
0
        public static double RecallValue(RecallLevel level)
        {
            switch (level)
            {
            case RecallLevel.Recall10:
                return(0.1);

            case RecallLevel.Recall20:
                return(0.2);

            case RecallLevel.Recall30:
                return(0.3);

            case RecallLevel.Recall40:
                return(0.4);

            case RecallLevel.Recall50:
                return(0.5);

            case RecallLevel.Recall60:
                return(0.6);

            case RecallLevel.Recall70:
                return(0.7);

            case RecallLevel.Recall80:
                return(0.8);

            case RecallLevel.Recall90:
                return(0.9);

            case RecallLevel.Recall100:
                return(1.0);

            default:
                return(0.0);
            }
        }
Esempio n. 12
0
        public static void ComputeMetrics(TLSimilarityMatrix sims, TLSimilarityMatrix oracle, RecallLevel level,
                                          out TLKeyValuePairsList precision, out TLKeyValuePairsList recall, out TLKeyValuePairsList avgPrecision, out TLKeyValuePairsList meanAvgPrecision)
        {
            TLLinksList links             = MetricsUtil.GetLinksAtRecall(sims, oracle, level);
            int         numCorrect        = 0;
            int         totalRead         = 0;
            double      totalAvgPrecision = 0.0;

            foreach (TLSingleLink link in links)
            {
                totalRead++;
                if (oracle.IsLinkAboveThreshold(link.SourceArtifactId, link.TargetArtifactId))
                {
                    numCorrect++;
                    totalAvgPrecision += numCorrect / (double)totalRead;
                }
            }
            // temporary
            precision = new TLKeyValuePairsList();
            precision.Add(new KeyValuePair <string, double>("#TOTAL", numCorrect / Convert.ToDouble(links.Count)));
            recall = new TLKeyValuePairsList();
            recall.Add(new KeyValuePair <string, double>("#TOTAL", Math.Ceiling(oracle.Count * RecallLevelUtil.RecallValue(level)) / oracle.Count));
            avgPrecision = new TLKeyValuePairsList();
            avgPrecision.Add(new KeyValuePair <string, double>("#TOTAL", totalAvgPrecision / oracle.Count));
            meanAvgPrecision = new TLKeyValuePairsList();
            meanAvgPrecision.Add(new KeyValuePair <string, double>("#TOTAL", MeanAveragePrecision.Compute(Similarities.CreateMatrix(links), oracle)));
        }
Esempio n. 13
0
        public static DataSetPairs Compute(TLSimilarityMatrix sims, TLSimilarityMatrix oracle, RecallLevel level)
        {
            TLKeyValuePairsList precision;
            TLKeyValuePairsList recall;
            TLKeyValuePairsList avgPrecision;
            TLKeyValuePairsList meanAvgPrecision;

            ComputeMetrics(sims, oracle, level, out precision, out recall, out avgPrecision, out meanAvgPrecision);
            return(new DataSetPairs
            {
                Name = RecallLevelUtil.ShortRecallString(level),
                PrecisionData = precision,
                RecallData = recall,
                AveragePrecisionData = avgPrecision,
                MeanAveragePrecisionData = meanAvgPrecision,
            });
        }
Esempio n. 14
0
 public AlgorithmDesc()
 {
     AType  = AlgorithmType.Texture3;
     RLevel = RecallLevel.Default;
 }
Esempio n. 15
0
        public static DataSetPairs Compute(TLSimilarityMatrix sims, TLSimilarityMatrix oracle, RecallLevel recall)
        {
            TLSimilarityMatrix matrix = Similarities.CreateMatrix(MetricsUtil.GetLinksAtRecall(sims, oracle, recall));

            matrix.Threshold = double.MinValue;
            DataSetPairs pairs = new DataSetPairs();

            foreach (string sourceArtifact in oracle.SourceArtifactsIds)
            {
                TLLinksList links = matrix.GetLinksAboveThresholdForSourceArtifact(sourceArtifact);
                links.Sort();
                int    totalCorrect      = oracle.GetLinksAboveThresholdForSourceArtifact(sourceArtifact).Count;
                int    numCorrect        = 0;
                int    totalRead         = 0;
                double totalAvgPrecision = 0.0;
                foreach (TLSingleLink link in links)
                {
                    totalRead++;
                    if (oracle.IsLinkAboveThreshold(link.SourceArtifactId, link.TargetArtifactId))
                    {
                        numCorrect++;
                        totalAvgPrecision += numCorrect / (double)totalRead;
                    }
                }
                pairs.PrecisionData.Add(new KeyValuePair <string, double>(sourceArtifact, numCorrect / Convert.ToDouble(links.Count)));
                pairs.RecallData.Add(new KeyValuePair <string, double>(sourceArtifact, Convert.ToDouble(numCorrect) / totalCorrect));
                pairs.AveragePrecisionData.Add(new KeyValuePair <string, double>(sourceArtifact, totalAvgPrecision / totalCorrect));
            }

            pairs.MeanAveragePrecisionData.Add(new KeyValuePair <string, double>("#TOTAL", DataSetPairsCollection.CalculateAverage(pairs.AveragePrecisionData)));
            return(pairs);
        }
Esempio n. 16
0
        public static TLLinksList GetLinksAtRecall(TLSimilarityMatrix sims, TLSimilarityMatrix oracle, RecallLevel level)
        {
            double      totalCorrect = oracle.Count * RecallLevelUtil.RecallValue(level);
            int         numCorrect   = 0;
            TLLinksList list         = new TLLinksList();
            TLLinksList links        = sims.AllLinks;

            links.Sort();
            while (links.Count > 0 && numCorrect < totalCorrect)
            {
                TLSingleLink link = links[0];
                if (oracle.IsLinkAboveThreshold(link.SourceArtifactId, link.TargetArtifactId))
                {
                    numCorrect++;
                }
                list.Add(link);
                links.RemoveAt(0);
            }
            return(list);
        }