Esempio n. 1
0
        /// <summary>
        /// pagerank score for each tag equation 4 in the paper
        /// </summary>
        /// <param name="neighbours"></param>
        private void ComputeTagSignificance(List<Question> neighbours)
        {
            var restartprob = Vector.Build.Dense(candidates.Count);
            TranslationMatrix = new DenseMatrix(candidates.Count, candidates.Count);

            foreach (var neighbour in neighbours)
            {
                foreach (var tag in neighbour.RelatedTags)
                {
                    if (tagFrequency.ContainsKey(tag))
                        tagFrequency[tag]++;
                    else
                        tagFrequency.Add(tag, 1);
                }
            }

            int i = 0;
            foreach (var candidate in candidates)
            {
                restartprob[i++] = tagFrequency[candidate.Key];
            }
            restartprob = restartprob.Normalize(1);

            i = 0;
            for (int rowindex = 0; rowindex < TranslationMatrix.RowCount; rowindex++)
                for (int columnindex = 0; columnindex < TranslationMatrix.ColumnCount; columnindex++)
                {
                    TranslationMatrix[rowindex, columnindex] += tagSim[rowindex, columnindex];
                }

            TranslationMatrix = DenseMatrix.OfMatrix(TranslationMatrix.NormalizeColumns(1));
            tagsignificance = Utils.PageRank(TranslationMatrix, restartprob);
        }