public static 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(); Console.Out.WriteLine(error); for (int i = 0; i < input_test.Length; i++ ) { network.SetInput(input_test[i]); Show(new []{input_test[i][0], network.GetOutput()[0], Math.Sin(input_test[i][0])}); } }
public void DimensionTestCheck() { NNetwork network = NNetwork.SigmoidNetwork(new int[] { 2, 4, 3 }); NetworkTrainer trainer = new NetworkTrainer(network); double[][] incorrect_input = new double[1][] { new double[3] }; double[][] correct_input = new double[1][] { new double[2] }; double[][] incorrect_output = new double[1][] { new double[4] }; double[][] correct_output = new double[1][] { new double[3] }; Assert.Throws(typeof(IncorrectInputDimensionException), () => trainer.TrainClassification(incorrect_input, correct_output)); Assert.Throws(typeof(IncorrectOutputDimensionException), () => trainer.TrainClassification(correct_input, incorrect_output)); }
public void TestHyperbolicClassification() { 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.55); }