public void TestTanhLearningOnSinus() { NNetwork network = NNetwork.HyperbolicNetwork(new int[] { 1, 2, 1 }); network.RandomizeWeights(1, 2); NetworkTrainer trainer = new NetworkTrainer(network); double[][] inputs = SinusTrainSet()[0]; double[][] outputs = SinusTrainSet()[1]; double error = 1; double delta = 1; int j = 0; for (; error > 0.01 && !(delta <= 0.000001) || j == 1; j++) { trainer.TrainClassification(inputs, outputs); double new_cost = trainer.GetError(); delta = error - new_cost; error = new_cost; } double[][] input_test = SinusTrainSet(20)[0]; double[][] output_test = SinusTrainSet(20)[1]; trainer.IsLearning = false; trainer.TrainClassification(input_test, output_test); error = trainer.GetError(); Assert.Less(error, 0.53); }
public void TestCostFunctionAccumulation() { NNetwork network = NNetwork.SigmoidNetwork(new int[] { 2, 4, 3 }); NetworkTrainer trainer = new NetworkTrainer(network); double[] train_set = new[] { 0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1 }; Assert.Throws(typeof(NoErrorInfoYetException), () => trainer.GetError()); double error; trainer.TrainPrediction(train_set); error = trainer.GetError(); Assert.AreNotEqual(error, 0); trainer.TrainPrediction(train_set); Assert.AreNotEqual(error, trainer.GetError()); }