예제 #1
0
        public void Validate_IfValid_ShouldDoNothing()
        {
            var config = new SimpleGradientTrainer {
                LearningRate = 0.1, NumEpochs = 100
            };

            config.Validate();
        }
예제 #2
0
        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}*");
        }
예제 #3
0
        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}*");
        }
예제 #4
0
        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}*");
        }
예제 #5
0
        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}*");
        }
예제 #6
0
        private static SimpleGradientTrainer GetSampleTrainer()
        {
            var trainer = new SimpleGradientTrainer
            {
                LearningRate            = 0.5,
                Momentum                = 2,
                NumEpochs               = 1,
                QuadraticRegularization = 0.1,
                ShouldInitializeWeights = false
            };

            return(trainer);
        }
예제 #7
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);
        }