public void Validate_IfValid_ShouldDoNothing()
        {
            var config = new SimpleGradientTrainer {
                LearningRate = 0.1, NumEpochs = 100
            };

            config.Validate();
        }
        public void Validate_IfNumEpochsIsNotPositive_Throw(int badNumEpochs)
        {
            var trainer = new SimpleGradientTrainer {
                LearningRate = 0.1, NumEpochs = badNumEpochs
            };
            Action action = () => trainer.Validate();

            action.ShouldThrow <NeuralNetworkException>()
            .WithMessage($"*Property NumEpochs must be positive; was {badNumEpochs}*");
        }
        public void Validate_IfLearningRateNotPositive_Throw(double badLearnignRate)
        {
            var trainer = new SimpleGradientTrainer {
                LearningRate = badLearnignRate, NumEpochs = 100
            };
            Action action = () => trainer.Validate();

            action.ShouldThrow <NeuralNetworkException>()
            .WithMessage($"*Property LearningRate must be positive; was {badLearnignRate}*");
        }
        public void Validate_IfQuadraticRegularizationNegative_Throw()
        {
            const double bad     = -0.1;
            var          trainer = new SimpleGradientTrainer {
                LearningRate = 0.1, NumEpochs = 100, QuadraticRegularization = bad
            };
            Action action = () => trainer.Validate();

            action.ShouldThrow <NeuralNetworkException>()
            .WithMessage($"*Property QuadraticRegularization cannot be negative; was {bad}*");
        }
        public void Validate_IfMomentumNegative_Throw()
        {
            const double badMomentum = -0.2;
            var          trainer     = new SimpleGradientTrainer {
                LearningRate = 0.1, NumEpochs = 100, Momentum = badMomentum
            };
            Action action = () => trainer.Validate();

            action.ShouldThrow <NeuralNetworkException>()
            .WithMessage($"*Property Momentum cannot be negative; was {badMomentum}*");
        }
Example #6
0
        public static string MakeSimpleGradientTrainer(
            [ExcelArgument(Description = "Name of trainer object to create.")] string name,
            [ExcelArgument(Description = "Number of backpropagation steps to run. Each step may be on-line or a batch step.")] int numEpochs,
            [ExcelArgument(Description = "Impact of each backpropagation step on weight adjustment.")] double learningRate,
            [ExcelArgument(Description = "Impact of previous backpropagation stepts each step's adjustment.")] double momentum,
            [ExcelArgument(Description = "Higher numbers help with keeping weights from becoming too large.")] double quadraticRegularization,
            [ExcelArgument(Description = "Number of training samples to evaluate for each backpropagation step.")] int batchSize,
            [ExcelArgument(Description = "Seed for random number generation.")] int seed)
        {
            var config = new SimpleGradientTrainer
            {
                NumEpochs               = numEpochs,
                LearningRate            = learningRate,
                Momentum                = momentum,
                QuadraticRegularization = quadraticRegularization,
                BatchSize               = batchSize,
                Seed = seed,
            };

            config.Validate();

            ObjectStore.Add(name, config);
            return(name);
        }