A SimpleGradientTrainer is an on-line gradient descent trainer that applies backpropagation (with a few adjustments) NumEpochs times. Next input/target pair is selected randomly from the training set.
Inheritance: BaseTrainer
        private static SimpleGradientTrainer GetSampleTrainer()
        {
            var trainer = new SimpleGradientTrainer
            {
                LearningRate = 0.5,
                Momentum = 2,
                NumEpochs = 1,
                QuadraticRegularization = 0.1,
                ShouldInitializeWeights = false
            };

            return trainer;
        }
 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_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_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}*");
 }
 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_IfValid_ShouldDoNothing()
 {
     var config = new SimpleGradientTrainer { LearningRate = 0.1, NumEpochs = 100 };
     config.Validate();
 }