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]) });
            }
        }
        private void buttonCreateNetwork_Click(object sender, EventArgs e)
        {
            String[] layers_string = textLayers.Text.Split(";".ToCharArray());
            int[]    layers        = new int[layers_string.Length];
            for (int i = 0; i < layers_string.Length; i++)
            {
                layers[i] = int.Parse(layers_string[i]);
            }
            if (radioHyperbolic.Checked)
            {
                network       = NNetwork.HyperbolicNetwork(layers);
                is_hyperbolic = true;
                is_sigmoid    = false;
            }
            if (radioSigmoid.Checked)
            {
                network       = NNetwork.SigmoidNetwork(layers);
                is_hyperbolic = false;
                is_sigmoid    = true;
            }
            if (radioCombined.Checked)
            {
                network       = NNetwork.CombinedNetwork(layers);
                is_hyperbolic = false;
                is_sigmoid    = true;
            }
            bool two_steps   = network.OutputCount() >= 2;
            bool three_steps = network.OutputCount() >= 3;

            checkTrain2.Enabled  = two_steps;
            checkTest2.Enabled   = two_steps;
            checkTrain3.Enabled  = three_steps;
            checkTest3.Enabled   = three_steps;
            groupWeights.Enabled = true;
        }
        public void TestTanhDerivative()
        {
            // SO-SO test =(
            NNetwork n = NNetwork.HyperbolicNetwork(new int[] { 2, 2, 1 });

            n.RandomizeWeights(-1, 10);
            Random random = new Random();
            double x;
            double y;
            double z;

            x = random.NextDouble();
            y = random.NextDouble();
            z = some_function(x, y);
            n.SetInput(new double[] { x, y });
            n.SetAnswers(new double[] { z });
            n.BackPropagate();
            double[] ders  = n.Derivatives();
            double[] ests  = n.Estimation(0.0001);
            var      koeff = ests[0] / ders[0];

            for (int i = 0; i < ders.Length; i++)
            {
                MyAssert.CloseTo(ests[i] / ders[i], koeff, 0.00001);
            }
        }
        public void TestTanhNetwork()
        {
            NNetwork n = NNetwork.HyperbolicNetwork(new int[] { 2, 4, 4, 2 });

            INeuron[][] neurons = n.Neurons;
            Assert.IsInstanceOf(typeof(TanhNeuron), neurons[2][2]);
        }
Beispiel #5
0
        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 static void TestTanhDerivative()
        {
            NNetwork n = NNetwork.HyperbolicNetwork(new int[] { 2, 2, 1 });

            n.RandomizeWeights(-1, 10);
            Random random = new Random();
            double x;
            double y;
            double z;

            x = random.NextDouble();
            y = random.NextDouble();
            z = some_function(x, y);
            n.SetInput(new double[] { x, y });
            n.SetAnswers(new double[] { z });
            n.BackPropagate();
            double[] ders = n.Derivatives();
            double[] ests = n.Estimation(0.0001);
            for (int i = 0; i < ders.Length; i++)
            {
                Show(new[] { ders[i], ests[i], ests[i] / ders[i] });
            }
        }