Beispiel #1
0
        /// <summary>
        /// Work out if this leaf node should split.  If it should, a new split value and dimension is calculated
        /// based on the dimension with the largest range.
        /// </summary>
        /// <returns>True if the node split, false if not.</returns>
        private bool CalculateSplit()
        {
            // Don't split if we are just one point.
            if (bSinglePoint)
            {
                return(false);
            }

            // Find the dimension with the largest range.  This will be our split dimension.
            DomainType fWidth = d_algebra.AddIdentity;

            for (int i = 0; i < d_dimension_count; i++)
            {
                DomainType fDelta = d_algebra.Subtract(tMaxBound[i], tMinBound[i]);
                if (d_algebra.IsNaN(fDelta))
                {
                    fDelta = d_algebra.AddIdentity;
                }

                if (fDelta.CompareTo(fWidth) == 1)
                {
                    d_split_dimension = i;
                    fWidth            = fDelta;
                }
            }

            // If we are not wide (i.e. all the points are in one place), don't split.
            if (fWidth.Equals(d_algebra.AddIdentity))
            {
                return(false);
            }

            // Split in the middle of the node along the widest dimension.
            d_split_value = d_algebra.Mean(tMinBound[d_split_dimension], tMaxBound[d_split_dimension]);

            // Never split on infinity or NaN.
            if (d_split_value.Equals(d_algebra.PositiveInfinity))
            {
                d_split_value = d_algebra.MaxValue;
            }
            else if (d_split_value.Equals(d_algebra.NegativeInfinity))
            {
                d_split_value = d_algebra.MinValue;
            }

            // Don't let the split value be the same as the upper value as
            // can happen due to rounding errors!
            if (d_split_value.Equals(tMaxBound[d_split_dimension]))
            {
                d_split_value = tMinBound[d_split_dimension];
            }

            // Success
            return(true);
        }