コード例 #1
0
        private TopicProbability[][] CalculateDensityOfTopicsInDocsSorted(int max_topics_to_retain)
        {
            try
            {
                TopicProbability[][] local_density_of_topics_in_docs_sorted = new TopicProbability[lda.NUM_DOCS][];

                // How many topics will we remember for each doc?
                int topics_to_retain = max_topics_to_retain;
                if (topics_to_retain <= 0)
                {
                    topics_to_retain = lda.NUM_TOPICS;
                }
                else if (topics_to_retain > lda.NUM_TOPICS)
                {
                    topics_to_retain = lda.NUM_TOPICS;
                }

                // Calculate the density
                float[,] densityoftopicsindocuments = DensityOfTopicsInDocuments;
                Parallel.For(0, lda.NUM_DOCS, (doc) =>
                             //for (int doc = 0; doc < lda.NUM_DOCS; ++doc)
                {
                    TopicProbability[] density_of_topics_in_doc = new TopicProbability[lda.NUM_TOPICS];

                    for (int topic = 0; topic < lda.NUM_TOPICS; ++topic)
                    {
                        density_of_topics_in_doc[topic] = new TopicProbability(densityoftopicsindocuments[doc, topic], topic);
                    }
                    Array.Sort(density_of_topics_in_doc);

                    // Copy the correct number of items to retain
                    if (topics_to_retain == lda.NUM_TOPICS)
                    {
                        local_density_of_topics_in_docs_sorted[doc] = density_of_topics_in_doc;
                    }
                    else
                    {
                        local_density_of_topics_in_docs_sorted[doc] = new TopicProbability[topics_to_retain];
                        Array.Copy(density_of_topics_in_doc, local_density_of_topics_in_docs_sorted[doc], topics_to_retain);
                    }
                });

                return(local_density_of_topics_in_docs_sorted);
            }
            catch (Exception ex)
            {
                Logging.Error(ex, "Internal LDAAnalysis error.");

                // terminate app
                throw;
            }
        }
コード例 #2
0
        public int CompareTo(object other_obj)
        {
            TopicProbability other = other_obj as TopicProbability;

            return(-prob.CompareTo(other.prob));
        }