Пример #1
0
        /// <summary>
        /// Merges base dimension of each weight dictionary
        /// </summary>
        /// <param name="results">The results.</param>
        /// <returns></returns>
        public static WeightDictionary MergeDimensions(this List <WeightDictionary> results)
        {
            WeightDictionary output = new WeightDictionary();

            output.nDimensions = results.Count;


            Dictionary <String, Double[]> tempMatrix = new Dictionary <string, double[]>();


            Int32 id = 0;

            foreach (var dict in results)
            {
                output.name += dict.name;

                foreach (var en in dict.index)
                {
                    if (!tempMatrix.ContainsKey(en.Key))
                    {
                        tempMatrix.Add(en.Key, new Double[output.nDimensions]);
                    }
                    tempMatrix[en.Key][id] = en.Value.weight;
                }

                id++;
            }


            foreach (var pair in tempMatrix)
            {
                output.AddEntry(pair.Key, pair.Value, false);
            }

            return(output);
        }
Пример #2
0
        /// <summary>
        /// Constructs the weight dictionary according to stored frequency and score information
        /// </summary>
        /// <returns></returns>
        public WeightDictionary ConstructWeightDictionary()
        {
            WeightDictionary output = new WeightDictionary();

            var tkns = frequencyIndex.GetTokens();

            Int32  maxFrequency = frequencyIndex.GetMaxFrequency();
            Double maxWeight    = scoreIndex.Values.Max();
            Int32  maxDF        = documentIndex.GetMaxFrequency();

            foreach (String token in tkns)
            {
                Double finalWeight = scoreIndex[token].GetRatio(maxWeight);                        //.GetRatio(frequencyIndex.GetTokenFrequency(token));
                Double TF          = frequencyIndex.GetTokenFrequency(token).GetRatio(maxFrequency);
                Double IDF         = Math.Log(maxDF / documentIndex.GetTokenFrequency(token)) + 1; // Math.Log(1 - ( / maxDF));

                finalWeight = finalWeight * (TF * IDF);

                output.AddEntry(token, finalWeight);
            }


            return(output);
        }