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 double GetControlError(NetworkTrainer networkTrainer, double lambda, double alpha)
        {
            networkTrainer.IsLearning = false;
            networkTrainer.TrainPrediction(test_data, lambda, alpha);
            double error = Math.Abs(trainer.GetError());

            networkTrainer.IsLearning = true;
            return(error);
        }
        private void buttonTrain_Click(object sender, EventArgs e)
        {
            groupPlotting.Enabled = false;
            trainer = new NetworkTrainer(network);
            double lambda = double.Parse(textLambda.Text);
            double alpha  = double.Parse(textAlpha.Text);

            AssignData();
            double    error          = 1;
            double    delta          = 1;
            double    required_error = double.Parse(textErrorStop.Text);
            double    required_delta = double.Parse(textDeltaStop.Text);
            int       time_limit     = int.Parse(textStopTime.Text) * 1000;
            int       j         = 0;
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Reset();
            stopwatch.Start();
//            while(error > required_error && (delta >= required_delta) || j == 1)
            while (error > required_error && (delta >= 0) || j == 1)
            {
                trainer.TrainPrediction(train_data, lambda, alpha);
                double new_error = Math.Abs(trainer.GetError());
                delta = error - new_error;
                error = new_error;
                j++;
                if (stopwatch.ElapsedMilliseconds > time_limit)
                {
                    break;
                }
            }
            textError.Text = Math.Round(error, 5).ToString();
            Double control_error = GetControlError(trainer, lambda, alpha);

            textControlError.Text = Math.Round(control_error, 5).ToString();
            textTimes.Text        = j.ToString();
            groupPlotting.Enabled = true;
        }
//        public static void Main()
//        {
//            TrainPrediction();
////            Sinus();
////            TestTanhLearningOnSinus();
////            TestTanhDerivative();
//
//        }

        public static void TrainPrediction()
        {
            NNetwork network = NNetwork.SigmoidNetwork(new int[] { 5, 1 });

            network.RandomizeWeights(-1, 20);
            NetworkTrainer trainer = new NetworkTrainer(network);
            List <double>  tr      = new List <double>();

            for (double i = 0; i <= 1; i = i + 0.05)
            {
                tr.Add(i);
            }
            double[] train_set = tr.ToArray();//new double[] { 0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1 };
            double   error     = 1;
            double   delta     = 1;
            int      j         = 0;

            for (; error > 0.01 && !(delta <= 0.00001) || j == 1; j++)
            {
                trainer.TrainPrediction(train_set, 0.0001, 0.2);
                double new_cost = trainer.GetError();
                delta = error - new_cost;
                error = new_cost;
            }
            Console.Out.WriteLine(j + ": " + error);
            for (double i = 0; i <= 0.5; i = i + 0.05)
            {
                network.SetInput(new double[] { i + 0.0, i + 0.1, i + 0.2, i + 0.3, i + 0.4 });
                Show(new double[]
                {
                    i + 0.5,
                    network.GetOutput()[0],
//                        network.GetOutput()[1]
                });
            }
        }