Пример #1
0
        public WeightDictionaryEntry GetElementFactorEntry(string term, SpaceModel space, SpaceLabel label = null)
        {
            WeightDictionaryEntry output = new WeightDictionaryEntry(term, 0);

            switch (resultType)
            {
            case FunctionResultTypeEnum.numeric:
                output = new WeightDictionaryEntry(term, GetElementFactor(term, space, label));
                break;

            case FunctionResultTypeEnum.numericVectorForMultiClass:
                Double[] vec = new double[space.labels.Count];
                Int32    c   = 0;
                foreach (SpaceLabel lb in space.labels)
                {
                    vec[c] = GetElementFactor(term, space, lb);
                    c++;
                }
                output = new WeightDictionaryEntry(term, vec);
                //                    output.AddEntry(term, vec);
                break;
            }

            if (!DistinctReturns.ContainsKey(output.weight))
            {
                DistinctReturns.Add(output.weight, term);
            }

            return(output);
        }
        public WeightDictionaryEntry GetElementFactorEntry(string term, SpaceModel space, SpaceLabel label = null)
        {
            Double score = GetElementFactor(term, space, label);
            WeightDictionaryEntry entry = new WeightDictionaryEntry(term, score);

            return(entry);
        }
        /// <summary>
        /// Gets the weights.
        /// </summary>
        /// <param name="termWhiteList">The term white list.</param>
        /// <param name="document">The document.</param>
        /// <param name="space">The space.</param>
        /// <param name="label">The label.</param>
        /// <returns></returns>
        public WeightDictionary GetWeights(List <String> termWhiteList, SpaceDocumentModel document, SpaceModel space, SpaceLabel label = null)
        {
            WeightDictionary output = new WeightDictionary();

            output.name        = GetSignature() + "_" + document.name;
            output.description = "Feature weight table constructed by [" + GetSignature() + "] for features [" + termWhiteList.Count + "] in document [" + document.name + "]";
            output.nDimensions = nDimensions;

            if (KERNELOPTION_USE_WHITELISTTERMS)
            {
                foreach (String term in termWhiteList)
                {
                    if (document.terms.Contains(term))
                    {
                        throw new NotImplementedException();
                        //output.entries.Add(entry);
                    }
                }
            }
            else
            {
                List <String> terms = document.terms.GetTokens();

                for (int i = 0; i < document.terms.Count; i++)
                {
                    String term = terms[i];

                    WeightDictionaryEntry entry = new WeightDictionaryEntry(term, 0);


                    if (DoUseLocalFunction)
                    {
                        entry = LocalFunction.GetElementFactorEntry(term, document);
                    }

                    foreach (FeatureWeightFactor gf in GlobalFactors)
                    {
                        entry = entry * (gf.GlobalFunction.GetElementFactorEntry(term, space, label) * gf.weight);
                    }

                    if (document.weight != 1)
                    {
                        entry = entry * document.weight;
                    }

                    output.Merge(entry);
                    //output.AddEntry(term, entry.dimensions, false);
                }
            }

            return(output);
        }
        public WeightDictionaryEntry GetCompositeEntry(String term, SpaceDocumentModel document, SpaceModel space)
        {
            WeightDictionaryEntry output     = new WeightDictionaryEntry(term, 0);
            List <Double>         dimensions = new List <double>();

            dimensions.Add(LocalFunction.GetElementFactor(term, document));

            foreach (var gf in GlobalFactors)
            {
                dimensions.Add(gf.GlobalFunction.GetElementFactor(term, space) * gf.weight);
            }

            output.dimensions = dimensions.ToArray();

            return(output);
        }
        /// <summary>
        /// Constructs global weight fictionary using global elements
        /// </summary>
        /// <param name="terms">The terms.</param>
        /// <param name="space">The space.</param>
        /// <param name="label">The label.</param>
        /// <returns></returns>
        public WeightDictionary GetElementFactors(IEnumerable <string> terms, SpaceModel space, SpaceLabel label = null)
        {
            var output = new WeightDictionary();


            output.name = GetSignature() + "_globalOnly";

            foreach (String term in terms)
            {
                Double score = GetElementFactor(term, space, label);
                WeightDictionaryEntry entry = new WeightDictionaryEntry(term, score);

                output.AddEntry(entry, true);
            }

            output.description = "Global weights for [" + output.Count + "] terms.";

            return(output);
        }