Exemple #1
0
        /// <summary>
        /// Exports an answer matrix to a file.
        /// </summary>
        /// <param name="answerMatrix">Answer matrix</param>
        /// <param name="filename">Output file path</param>
        public static void Export(TLSimilarityMatrix answerMatrix, string filename)
        {
            TextWriter tw = null;

            try
            {
                tw = new StreamWriter(filename);
                foreach (string sourceID in answerMatrix.SourceArtifactsIds)
                {
                    tw.Write(sourceID);
                    foreach (string targetID in answerMatrix.GetSetOfTargetArtifactIdsAboveThresholdForSourceArtifact(sourceID))
                    {
                        tw.Write(" " + targetID);
                    }
                    tw.WriteLine();
                }
                tw.Flush();
                tw.Close();
            }
            catch (Exception e)
            {
                if (tw != null)
                {
                    tw.Close();
                }
                throw new DevelopmentKitException("There was an exception writing to file (" + filename + ")", e);
            }
        }
Exemple #2
0
 internal static void CompareResults(TLSimilarityMatrix oracle, TLSimilarityMatrix results, IEnumerable <string> rawMethods)
 {
     Console.WriteLine("Comparing results...");
     Assert.AreEqual(oracle.Count, results.Count);
     foreach (string oracleMethod in oracle.GetSetOfTargetArtifactIdsAboveThresholdForSourceArtifact("trace"))
     {
         string rawMethod = rawMethods.ElementAt(Convert.ToInt32(oracleMethod) - 1);
         string method    = rawMethod.Substring(0, rawMethod.IndexOf('('));
         //Console.WriteLine(oracleMethod + ": " + method);
         Assert.IsTrue(results.IsLinkAboveThreshold("trace", method));
         Assert.AreEqual(oracle.GetScoreForLink("trace", oracleMethod), results.GetScoreForLink("trace", method), Settings.Default.DoublePrecision);
     }
 }
Exemple #3
0
        public static TLSimilarityMatrix Compute(TLSimilarityMatrix matrix, TLSimilarityMatrix relationships)
        {
            // create pseudo matrix for easy lookup
            // Dictionary<sourceID, Dictionary<targetID, score>>
            Dictionary <string, Dictionary <string, double> > storage = new Dictionary <string, Dictionary <string, double> >();

            foreach (TLSingleLink link in matrix.AllLinks)
            {
                if (!storage.ContainsKey(link.SourceArtifactId))
                {
                    storage.Add(link.SourceArtifactId, new Dictionary <string, double>());
                }
                storage[link.SourceArtifactId].Add(link.TargetArtifactId, link.Score);
            }
#if UseDelta
            // compute delta
            double delta = SharedUtils.ComputeDelta(matrix);
#endif
            // iterate over every (source, target) pair
            TLLinksList links = matrix.AllLinks;
            links.Sort();
            foreach (TLSingleLink link in links)
            {
                // get the set of target artifacts related to link.TargetArtifactId
                // then update the value of (link.SourceArtifactId, relatedArtifact) by delta
                foreach (string relatedArtifact in relationships.GetSetOfTargetArtifactIdsAboveThresholdForSourceArtifact(link.TargetArtifactId))
                {
#if UseDelta
                    storage[link.SourceArtifactId][relatedArtifact] += storage[link.SourceArtifactId][relatedArtifact] * delta;
#else
                    storage[link.SourceArtifactId][relatedArtifact] += storage[link.SourceArtifactId][relatedArtifact] * 0.1;
#endif
                }
            }
            // build new matrix
            TLLinksList newLinks = new TLLinksList();
            foreach (string source in storage.Keys)
            {
                foreach (string target in storage[source].Keys)
                {
                    newLinks.Add(new TLSingleLink(source, target, storage[source][target]));
                }
            }
            newLinks.Sort();
            TLSimilarityMatrix newMatrix = new TLSimilarityMatrix();
            foreach (TLSingleLink link in newLinks)
            {
                newMatrix.AddLink(link.SourceArtifactId, link.TargetArtifactId, link.Score);
            }
            return(newMatrix);
        }