예제 #1
0
        private protected override bool ShouldStop(IChannel ch, ref EarlyStoppingRuleBase earlyStoppingRule, ref int bestIteration)
        {
            if (FastTreeTrainerOptions.EarlyStoppingRuleFactory == null)
            {
                return(false);
            }

            ch.AssertValue(ValidTest);
            ch.AssertValue(TrainTest);

            var validationResult = ValidTest.ComputeTests().First();

            ch.Assert(validationResult.FinalValue >= 0);
            bool lowerIsBetter = validationResult.LowerIsBetter;

            var trainingResult = TrainTest.ComputeTests().First();

            ch.Assert(trainingResult.FinalValue >= 0);

            // Create early stopping rule if it's null.
            if (earlyStoppingRule == null)
            {
                if (FastTreeTrainerOptions.EarlyStoppingRuleFactory != null)
                {
                    earlyStoppingRule = FastTreeTrainerOptions.EarlyStoppingRuleFactory.CreateComponent(Host, lowerIsBetter);
                }
            }

            // Early stopping rule cannot be null!
            ch.Assert(earlyStoppingRule != null);

            bool isBestCandidate;
            bool shouldStop = earlyStoppingRule.CheckScore((float)validationResult.FinalValue,
                                                           (float)trainingResult.FinalValue, out isBestCandidate);

            if (isBestCandidate)
            {
                bestIteration = Ensemble.NumTrees;
            }

            return(shouldStop);
        }
        protected override bool ShouldStop(IChannel ch, ref IEarlyStoppingCriterion earlyStoppingRule, ref int bestIteration)
        {
            if (Args.EarlyStoppingRule == null)
            {
                return(false);
            }

            ch.AssertValue(ValidTest);
            ch.AssertValue(TrainTest);

            var validationResult = ValidTest.ComputeTests().First();

            ch.Assert(validationResult.FinalValue >= 0);
            bool lowerIsBetter = validationResult.LowerIsBetter;

            var trainingResult = TrainTest.ComputeTests().First();

            ch.Assert(trainingResult.FinalValue >= 0);

            // Create early stopping rule.
            if (earlyStoppingRule == null)
            {
                earlyStoppingRule = Args.EarlyStoppingRule.CreateComponent(Host, lowerIsBetter);
                ch.Assert(earlyStoppingRule != null);
            }

            bool isBestCandidate;
            bool shouldStop = earlyStoppingRule.CheckScore((Float)validationResult.FinalValue,
                                                           (Float)trainingResult.FinalValue, out isBestCandidate);

            if (isBestCandidate)
            {
                bestIteration = Ensemble.NumTrees;
            }

            return(shouldStop);
        }