示例#1
0
        public void Merge(FeatureInteractions interactions)
        {
            foreach (KeyValuePair <string, FeatureInteraction> fi in interactions)
            {
                if (!ContainsKey(fi.Key))
                {
                    Add(fi.Key, fi.Value);
                }
                else
                {
                    this[fi.Key].Gain                 += fi.Value.Gain;
                    this[fi.Key].Cover                += fi.Value.Cover;
                    this[fi.Key].FScore               += fi.Value.FScore;
                    this[fi.Key].FScoreWeighted       += fi.Value.FScoreWeighted;
                    this[fi.Key].AverageFScoreWeighted = this[fi.Key].FScoreWeighted / this[fi.Key].FScore;
                    this[fi.Key].AverageGain           = this[fi.Key].Gain / this[fi.Key].FScore;
                    this[fi.Key].ExpectedGain         += fi.Value.ExpectedGain;
                    this[fi.Key].SumLeafCoversLeft    += fi.Value.SumLeafCoversLeft;
                    this[fi.Key].SumLeafCoversRight   += fi.Value.SumLeafCoversRight;
                    this[fi.Key].SumLeafValuesLeft    += fi.Value.SumLeafValuesLeft;
                    this[fi.Key].SumLeafValuesRight   += fi.Value.SumLeafValuesRight;
                    this[fi.Key].TreeIndex            += fi.Value.TreeIndex;
                    this[fi.Key].AverageTreeIndex      = this[fi.Key].TreeIndex / this[fi.Key].FScore;
                    this[fi.Key].TreeDepth            += fi.Value.TreeDepth;
                    this[fi.Key].AverageTreeDepth      = this[fi.Key].TreeDepth / this[fi.Key].FScore;

                    //if (fi.Value.Depth == 0)
                    //{
                    //    this[fi.Key].SplitValueHistogram.Merge(fi.Value.SplitValueHistogram);

                    //}
                    this[fi.Key].SplitValueHistogram.Merge(fi.Value.SplitValueHistogram);
                }
            }
        }
示例#2
0
        public FeatureInteractions GetFeatureInteractions(int maxInteractionDepth = -1, int maxDeepening = -1)
        {
            FeatureInteractions xgbFeatureInteractions = new FeatureInteractions();

            _maxInteractionDepth = maxInteractionDepth;
            _maxDeepening        = maxDeepening;

            Console.ResetColor();
            if (_maxInteractionDepth == -1)
            {
                Console.WriteLine(String.Format("Collectiong feature interactions"));
            }
            else
            {
                Console.WriteLine(String.Format("Collectiong feature interactions up to depth {0}", _maxInteractionDepth));
            }

            for (int i = 0; i < NumTrees; i++)
            {
                Console.ForegroundColor = ConsoleColor.DarkGreen;
                Console.Write(String.Format("Collectiong feature interactions within tree #{0} ", i + 1));

                _treeFeatureInteractions = new FeatureInteractions();
                _pathMemo  = new HashSet <string>();
                _treeIndex = i;
                CollectFeatureInteractions(XgbTrees[i], new HashSet <XgbTreeNode>(), currentGain: 0, currentCover: 0, pathProbability: 1, depth: 0, deepening: 0);

                //double treeGain = _treeFeatureInteractions.GetFeatureInteractionsOfDepth(0).Sum(x => x.Value.Gain);
                //foreach (KeyValuePair<string, FeatureInteraction> fi in _treeFeatureInteractions)
                //{
                //    fi.Value.Gain /= treeGain;
                //}

                Console.WriteLine(String.Format("=> number of interactions: {0}", _treeFeatureInteractions.Count));
                Console.ResetColor();
                xgbFeatureInteractions.Merge(_treeFeatureInteractions);
            }

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine(String.Format("{0} feature interactions has been collected.\n", xgbFeatureInteractions.Count));
            Console.ResetColor();

            return(xgbFeatureInteractions);
        }
示例#3
0
 public void Merge(FeatureInteractions interactions)
 {
     foreach (KeyValuePair <string, FeatureInteraction> fi in interactions)
     {
         if (!ContainsKey(fi.Key))
         {
             Add(fi.Key, fi.Value);
         }
         else
         {
             this[fi.Key].Gain                 += fi.Value.Gain;
             this[fi.Key].Cover                += fi.Value.Cover;
             this[fi.Key].FScore               += fi.Value.FScore;
             this[fi.Key].FScoreWeighted       += fi.Value.FScoreWeighted;
             this[fi.Key].AverageFScoreWeighted = this[fi.Key].FScoreWeighted / this[fi.Key].FScore;
             this[fi.Key].AverageGain           = this[fi.Key].Gain / this[fi.Key].FScore;
             this[fi.Key].ExpectedGain         += fi.Value.ExpectedGain;
             this[fi.Key].SumLeafCoversLeft    += fi.Value.SumLeafCoversLeft;
             this[fi.Key].SumLeafCoversRight   += fi.Value.SumLeafCoversRight;
             this[fi.Key].SumLeafValuesLeft    += fi.Value.SumLeafValuesLeft;
             this[fi.Key].SumLeafValuesRight   += fi.Value.SumLeafValuesRight;
         }
     }
 }