private double[] ExtractData(string name, DataSetPairsType type, DataSetPairsCollection dspc) { foreach (DataSetPairs pairs in dspc) { if (pairs.Name == name) { if (pairs.Name == "VSM") { pairs.Name = "VSM"; } switch (type) { case DataSetPairsType.Precision: return(ExtractDataArray(pairs.PrecisionData)); case DataSetPairsType.Recall: return(ExtractDataArray(pairs.RecallData)); case DataSetPairsType.AveragePrecision: return(ExtractDataArray(pairs.AveragePrecisionData)); default: throw new ArgumentException("Unknown DataSetPairsType: " + type); } } } throw new ArgumentException("Model not found - " + name); }
public override void Compute() { DataSetPairsCollection dspc = (DataSetPairsCollection)Workspace.Load("DataSetPairsCollection"); List <DatasetResults> listOfDatasetResults = new List <DatasetResults>(); List <Metric> ds1 = new List <Metric>(); // tab 1 - base precision List <SummaryData> ds1_tab1 = new List <SummaryData>(); ds1_tab1.Add(new SummaryData("VSM", ExtractData("VSM", DataSetPairsType.AveragePrecision, dspc))); ds1_tab1.Add(new SummaryData("JS", ExtractData("JS", DataSetPairsType.AveragePrecision, dspc))); ds1_tab1.Add(new SummaryData("RTM", ExtractData("RTM", DataSetPairsType.AveragePrecision, dspc))); ds1.Add(new AveragePrecisionMetric(ds1_tab1, 0.0, ""));//, "Base - Precision")); // tab 2 - combined precision List <SummaryData> ds1_tab2 = new List <SummaryData>(); ds1_tab2.Add(new SummaryData("VSM_JS", ExtractData("VSM_JS", DataSetPairsType.AveragePrecision, dspc))); ds1_tab2.Add(new SummaryData("VSM_RTM", ExtractData("VSM_RTM", DataSetPairsType.AveragePrecision, dspc))); ds1_tab2.Add(new SummaryData("JS_RTM", ExtractData("JS_RTM", DataSetPairsType.AveragePrecision, dspc))); ds1.Add(new AveragePrecisionMetric(ds1_tab2, 0.0, ""));//, "Combined - Precision")); // tab 3 - combined PCA precision List <SummaryData> ds1_tab3 = new List <SummaryData>(); ds1_tab3.Add(new SummaryData("VSM_JS_PCA", ExtractData("VSM_JS_PCA", DataSetPairsType.AveragePrecision, dspc))); ds1_tab3.Add(new SummaryData("VSM_RTM_PCA", ExtractData("VSM_RTM_PCA", DataSetPairsType.AveragePrecision, dspc))); ds1_tab3.Add(new SummaryData("JS_RTM_PCA", ExtractData("JS_RTM_PCA", DataSetPairsType.AveragePrecision, dspc))); ds1.Add(new AveragePrecisionMetric(ds1_tab3, 0.0, ""));//, "Combined (PCA) - Precision")); listOfDatasetResults.Add(new DatasetResults("Dataset", ds1)); Workspace.Store("ListOfDatasetResults", listOfDatasetResults); }
private double[] ExtractData(string name, DataSetPairsType type, DataSetPairsCollection dspc) { foreach (DataSetPairs pairs in dspc) { if (pairs.Name == name) { if (pairs.Name == "VSM") { pairs.Name = "VSM"; } switch (type) { case DataSetPairsType.Precision: return ExtractDataArray(pairs.PrecisionData); case DataSetPairsType.Recall: return ExtractDataArray(pairs.RecallData); case DataSetPairsType.AveragePrecision: return ExtractDataArray(pairs.AveragePrecisionData); default: throw new ArgumentException("Unknown DataSetPairsType: " + type); } } } throw new ArgumentException("Model not found - " + name); }
public static DataSetPairsCollection ComputeAll(TLSimilarityMatrix sims, TLSimilarityMatrix oracle) { DataSetPairsCollection dspc = new DataSetPairsCollection(); foreach (RecallLevel level in Enum.GetValues(typeof(RecallLevel))) { dspc.Add(Compute(sims, oracle, level)); } return dspc; }
public static DataSetPairsCollection ComputeAll(TLSimilarityMatrix sims, TLSimilarityMatrix oracle) { DataSetPairsCollection dspc = new DataSetPairsCollection(); foreach (RecallLevel level in Enum.GetValues(typeof(RecallLevel))) { dspc.Add(Compute(sims, oracle, level)); } return(dspc); }
private static void MyMetrics(ref Info info, string output, TLSimilarityMatrix matrix, TLSimilarityMatrix oracle) { DataSetPairsCollection metrics = OverallMetricsComputation.ComputeAll(matrix, oracle); TextWriter dataFile = File.CreateText(output); for (int i = 0, j = 10; i < metrics.Count; i++, j += 10) { dataFile.WriteLine("{0} {1}", j, metrics[i].PrecisionData[0].Value); } dataFile.Flush(); dataFile.Close(); }
public static void Run(ref Info info) { TLSimilarityMatrix vsm = Similarities.Import(info.ResultsDirectory + @"\CSMRTools\RoccoResults\EasyClinic UC-CC.VSM.sims"); TLSimilarityMatrix oracle = Oracle.Import(info.ResultsDirectory + @"\CSMRTools\RoccoResults\EasyClinic UC-CC.oracle"); TLSimilarityMatrix usage = Oracle.Import(info.ResultsDirectory + @"\CSMRTools\RoccoResults\EasyClinic UC-CC.relationships"); TLSimilarityMatrix udcsti = UDCSTI.Compute(vsm, usage, oracle); Similarities.Export(udcsti, info.ResultsDirectory + @"\CSMRTools\RoccoResults\EasyClinic UC-CC.VSM_UDCSTI.MYsims"); DataSetPairsCollection metrics = OverallMetricsComputation.ComputeAll(udcsti, oracle); TextWriter dataFile = File.CreateText(info.ResultsDirectory + @"\CSMRTools\RoccoResults\EasyClinic UC-CC.VSM_UDCSTI.MYsims.metrics"); for (int i = 0, j = 10; i < metrics.Count; i++, j += 10) { dataFile.WriteLine("{0} {1}", j, metrics[i].PrecisionData[0].Value); } dataFile.Flush(); dataFile.Close(); }
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); }