示例#1
0
        private int SplitInternal(Col before, int rank)
        {
            (var left, var right) = before.Split <Num>(1);
            var best = before.Variety();
            int?cut  = null;

            for (int j = 1; j < before.N; j++)
            {
                var now = left.cells.Last();
                left.AddCell(right.RemoveCell(right.cells.First()));
                var after = left.cells.Last();

                if (left.N >= step && right.N >= step)
                {
                    if (now.RawValue.Equals(after.RawValue))
                    {
                        continue;
                    }
                    if (Math.Abs(right.Mu - left.Mu) >= epsilon)
                    {
                        if (after.NumericValue - start.NumericValue > epsilon)
                        {
                            if (stop.NumericValue - now.NumericValue > epsilon)
                            {
                                var expect = left.Expect(right);
                                if (expect * trivial < best)
                                {
                                    best = expect;
                                    cut  = j;
                                }
                            }
                        }
                    }
                }
            }

            if (cut.HasValue)
            {
                (left, right) = before.Split <Num>(cut.Value);
                rank          = SplitInternal(left, rank) + 1;
                rank          = SplitInternal(right, rank);
            }
            else
            {
                gain       += before.N * before.Variety();
                before.Rank = rank;
                ranges.Add(before);
            }

            return(rank);
        }
示例#2
0
        private int SplitInternal <T>(Col before, int rank) where T : Col, new()
        {
            (var left, var right) = before.Split <T>(1);
            var best = before.Variety();
            int?cut  = null;

            for (int j = 1; j < before.N; j++)
            {
                var now = left.cells.Last();
                left.AddCell(right.RemoveCell(right.cells.First()));
                var after = left.cells.Last();

                if (left.N >= step && right.N >= step)
                {
                    if (now.RawValue.Equals(after.RawValue))
                    {
                        continue;
                    }
                    if (left.IsCentralTendencyDifferent(right, epsilon))
                    {
                        if (after.IsDifferent(start, epsilon))
                        {
                            if (stop.IsDifferent(now, epsilon))
                            {
                                var expect = left.Expect(right);
                                if (expect * trivial < best)
                                {
                                    best = expect;
                                    cut  = j;
                                }
                            }
                        }
                    }
                }
            }

            if (cut.HasValue)
            {
                (left, right) = before.Split <T>(cut.Value);
                rank          = SplitInternal <T>(left, rank) + 1;
                rank          = SplitInternal <T>(right, rank);
            }
            else
            {
                gain       += before.N * before.Variety();
                before.Rank = rank;
                ranges.Add(before);
            }

            return(rank);
        }
示例#3
0
        public double Expect(Col other)
        {
            var n = N + other.N;

            return(N / n * Variety() + other.N / n * other.Variety());
        }