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
Ejemplo n.º 1
0
        private static SimpleGradientTrainer GetSampleTrainer()
        {
            var trainer = new SimpleGradientTrainer
            {
                LearningRate = 0.5,
                Momentum = 2,
                NumEpochs = 1,
                QuadraticRegularization = 0.1,
                ShouldInitializeWeights = false
            };

            return trainer;
        }
Ejemplo n.º 2
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}*");
 }
Ejemplo n.º 3
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}*");
 }
Ejemplo n.º 4
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}*");
 }
Ejemplo n.º 5
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}*");
 }
Ejemplo n.º 6
0
 public void Validate_IfValid_ShouldDoNothing()
 {
     var config = new SimpleGradientTrainer { LearningRate = 0.1, NumEpochs = 100 };
     config.Validate();
 }