Ejemplo n.º 1
0
        /// <summary>
        /// Returns links for the desired recall level.
        /// </summary>
        /// <param name="matrix">Candidate matrix</param>
        /// <param name="answerMatrix">Answer matrix</param>
        /// <param name="level">Desired recall level</param>
        /// <returns>List of links at desired recall</returns>
        public static TLLinksList GetLinksAtRecall(TLSimilarityMatrix matrix, TLSimilarityMatrix answerMatrix, double level)
        {
            if (level <= 0.0 || level > 1.0)
            {
                throw new DevelopmentKitException("Recall level must be between 0 and 1.");
            }
            double      totalCorrect = answerMatrix.Count * level;
            int         numCorrect   = 0;
            TLLinksList links        = matrix.AllLinks;

            links.Sort();
            TLLinksList newLinks = new TLLinksList();

            while (links.Count > 0 && numCorrect < totalCorrect)
            {
                TLSingleLink link = links[0];
                if (answerMatrix.IsLinkAboveThreshold(link.SourceArtifactId, link.TargetArtifactId))
                {
                    numCorrect++;
                }
                newLinks.Add(link);
                links.RemoveAt(0);
            }
            return(newLinks);
        }
Ejemplo n.º 2
0
 public static int GetLinkPos(TLSimilarityMatrix sims, TLSingleLink link)
 {
     TLLinksList list = sims.AllLinks;
     list.Sort();
     int pos = 1;
     foreach (TLSingleLink query in list)
     {
         if (query.SourceArtifactId.Equals(link.SourceArtifactId) && query.TargetArtifactId.Equals(link.TargetArtifactId))
             return pos;
         pos++;
     }
     return -1;
 }
Ejemplo n.º 3
0
        public static int GetLinkPos(TLSimilarityMatrix sims, TLSingleLink link)
        {
            TLLinksList list = sims.AllLinks;

            list.Sort();
            int pos = 1;

            foreach (TLSingleLink query in list)
            {
                if (query.SourceArtifactId.Equals(link.SourceArtifactId) && query.TargetArtifactId.Equals(link.TargetArtifactId))
                {
                    return(pos);
                }
                pos++;
            }
            return(-1);
        }
Ejemplo n.º 4
0
        public static TLSimilarityMatrix Compute(TLSimilarityMatrix sims, TLSimilarityMatrix relationships, TLSimilarityMatrix feedback)
        {
            // new matrix
            TLSimilarityMatrix newMatrix = new TLSimilarityMatrix();

#if UseDelta
            // compute delta
            double delta = SharedUtils.ComputeDelta(sims);
#endif
            // make sure the entire list is sorted
            TLLinksList links = sims.AllLinks;
            links.Sort();
            // end condition
            int correct = 0;
            // iterate over each source-target pair
            while (links.Count > 0 && correct < feedback.Count)
            {
                // get link at top of list
                TLSingleLink link = links[0];
                // check feedback
                if (feedback.IsLinkAboveThreshold(link.SourceArtifactId, link.TargetArtifactId))
                {
                    correct++;
                    // update related links
                    for (int i = 1; i < links.Count; i++)
                    {
                        if (link.SourceArtifactId.Equals(links[i].SourceArtifactId) &&
                            relationships.IsLinkAboveThreshold(link.TargetArtifactId, links[i].TargetArtifactId))
                        {
#if UseDelta
                            links[i].Score += links[i].Score * delta;
#else
                            links[i].Score += links[i].Score * 0.1;
#endif
                        }
                    }
                }
                // remove link
                newMatrix.AddLink(link.SourceArtifactId, link.TargetArtifactId, link.Score);
                links.RemoveAt(0);
                // reorder links
                links.Sort();
            }
            return(newMatrix);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Removes a percentage of links from the bottom of the list.
        /// </summary>
        /// <param name="links">Ranklist</param>
        /// <param name="percent">Percentage to remove</param>
        /// <returns>Trimmed ranklist</returns>
        public static TLLinksList RemoveBottomPercentage(TLLinksList links, double percent)
        {
            if (percent <= 0.0 || percent >= 1.0)
            {
                throw new DevelopmentKitException("Percentage level must be between 0 and 1.");
            }
            TLLinksList remaining = new TLLinksList();

            links.Sort();
            int endIndex = Convert.ToInt32(Math.Floor(links.Count * (1 - percent))) - 1;

            for (int i = 0; i < endIndex; i++)
            {
                TLSingleLink link = links[i];
                remaining.Add(new TLSingleLink(link.SourceArtifactId, link.TargetArtifactId, link.Score));
            }
            return(remaining);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
 private static KeyValuePair<int, TLSingleLink> FindLink(TLLinksList list, TLSingleLink source)
 {
     int index;
     for (index = 0; index < list.Count; index++)
     {
         TLSingleLink link = list[index];
         if (link.SourceArtifactId == source.SourceArtifactId
             && link.TargetArtifactId == source.TargetArtifactId)
         {
             break;
         }
     }
     if (index == list.Count)
     {
         return new KeyValuePair<int, TLSingleLink>(-1, new TLSingleLink(source.SourceArtifactId, source.TargetArtifactId, -1));
     }
     else
     {
         return new KeyValuePair<int, TLSingleLink>(index, list[index]);
     }
 }
Ejemplo n.º 8
0
        private static KeyValuePair <int, TLSingleLink> FindLink(TLLinksList list, TLSingleLink source)
        {
            int index;

            for (index = 0; index < list.Count; index++)
            {
                TLSingleLink link = list[index];
                if (link.SourceArtifactId == source.SourceArtifactId &&
                    link.TargetArtifactId == source.TargetArtifactId)
                {
                    break;
                }
            }
            if (index == list.Count)
            {
                return(new KeyValuePair <int, TLSingleLink>(-1, new TLSingleLink(source.SourceArtifactId, source.TargetArtifactId, -1)));
            }
            else
            {
                return(new KeyValuePair <int, TLSingleLink>(index, list[index]));
            }
        }