Example #1
0
        private List <Tree> Split()
        {
            var splitInfo = FindBestSplit();
            //var splitInfo = FindBestRandomSplit();
            int    bestLocalDimIndex = splitInfo.Item1;
            double bestSplit         = splitInfo.Item2;
            double maxExpectedInfo   = splitInfo.Item3;

            if (bestLocalDimIndex == -1)
            {
                return(null);
            }

            int bestGlobalDimIndex = this.TargetFeatures[bestLocalDimIndex];

            bool[] filter = TrainPoints.FeatureCols[bestGlobalDimIndex].Geq(bestSplit);

            var upperMinCorner = new double[NDim];

            MinCorner.CopyTo(upperMinCorner, 0);
            upperMinCorner[bestLocalDimIndex] = bestSplit;

            var lowerMaxCorner = new double[NDim];

            MaxCorner.CopyTo(lowerMaxCorner, 0);
            lowerMaxCorner[bestLocalDimIndex] = bestSplit;

            var upperTree = new Tree(
                TrainPoints.Filter(filter),
                this.TargetFeatures,
                upperMinCorner,
                MaxCorner,
                includeMax: IncludeMax,
                normalizingConstant: NormalizingConstant
                );

            bool[] lowerIncludeMax = new bool[NDim];
            IncludeMax.CopyTo(lowerIncludeMax, 0);
            lowerIncludeMax[bestLocalDimIndex] = false;

            Yarr.InlineNot(filter);
            var lowerTree = new Tree(
                TrainPoints.Filter(filter),
                this.TargetFeatures,
                MinCorner,
                lowerMaxCorner,
                includeMax: lowerIncludeMax,
                normalizingConstant: NormalizingConstant
                );

            this.SplitDim = bestLocalDimIndex;
            this.SplitVal = bestSplit;
            return(new List <Tree> {
                upperTree, lowerTree
            });
        }
Example #2
0
        private Tree MakeTree()
        {
            var cols = RandomUtils.Choice(this.ColIndices, this.ColsPerTree).ToArray();

            bool[] filter       = Yarr.InlineNot(this.Data.HasNaN(cols));
            var    filteredData = this.Data.Filter(filter);

            var result = new Tree(
                filteredData,
                cols,
                Yarr.FancyIndex(this.GlobalMinCorner, cols),
                Yarr.FancyIndex(this.GlobalMaxCorner, cols)
                );

            result.Train();

            return(result);
        }
Example #3
0
        public Score Score(RecordSet data, bool parallel = true)
        {
            //NOTE: ignore parallel parameter

            double[] sScores = Yarr.Repeat(double.NaN, data.NRows);
            double[] bScores = Yarr.Repeat(double.NaN, data.NRows);

            bool[] filter       = Yarr.InlineNot(data.HasNaN(this.TargetFeatures));
            var    filteredData = data.Filter(filter);

            data = null;             // unlikely to let anything be GC'ed (lots of references to same obj) but it can't hurt

            this._Score(
                filteredData,
                Yarr.Range(filteredData.NRows).MakeSlice(),
                sScores,
                bScores
                );
            return(new Score(sScores, bScores));
        }