コード例 #1
0
        static void Testing()
        {
            int[] array = { 10, 20, 2 };

            string str = File.ReadAllText("TD1.txt");

            double[][] vs1   = JsonConvert.DeserializeObject <double[][]>(str);
            NNModel    model = new NNModel(array);

            Console.Beep();
            var             watch           = System.Diagnostics.Stopwatch.StartNew();
            BackPropagation backPropagation = new BackPropagation();

            backPropagation.Learn(model, vs1);
            watch.Stop();
            Console.WriteLine(watch.ElapsedMilliseconds);
            string str1 = File.ReadAllText("TD2.txt");

            double[][] vs2 = JsonConvert.DeserializeObject <double[][]>(str1);
            for (int i = 0; i < vs2.Length; i++)
            {
                model.Compute(NNModel.ReculcArray(vs2[i])).Neurons.ForEach(x =>
                {
                    Console.WriteLine(x.Value + "  ");
                });
                Console.WriteLine();
            }
            Console.WriteLine("_______");
            model.Save();
            Console.Beep();
            Console.ReadKey();
        }
コード例 #2
0
        static void Testing1()
        {
            int[] array = { 9, 20, 1 };

            string str = File.ReadAllText("TD1.txt");

            double[][] vs1 = JsonConvert.DeserializeObject <double[][]>(str);
            for (int i = 0; i < vs1.Length; i += 2)
            {
                var tmp = vs1[i];
                vs1[i] = new double[9];
                for (int j = 0; j < 9; j++)
                {
                    vs1[i][j] = tmp[j] / tmp[j + 1];
                }
            }
            NNModel model = new NNModel(array);

            //NNModel model = NNModel.Open("nnmodel.dat");
            Console.Beep();
            var             watch           = System.Diagnostics.Stopwatch.StartNew();
            BackPropagation backPropagation = new BackPropagation();

            backPropagation.Learn(model, vs1);
            watch.Stop();
            Console.WriteLine(watch.ElapsedMilliseconds);
            string str1 = File.ReadAllText("TD2.txt");

            double[][] vs2 = JsonConvert.DeserializeObject <double[][]>(str1);
            for (int i = 0; i < vs2.Length; i++)
            {
                var inp = new double[9];
                var tmp = vs2[i];
                for (int j = 0; j < 9; j++)
                {
                    inp[j] = tmp[j] / tmp[j + 1];
                }
                model.Compute(inp).Neurons.ForEach(x =>
                {
                    Console.WriteLine(x.Value + "  ");
                });
                Console.WriteLine();
            }
            Console.WriteLine("_______");
            //for (int i = 90; i < vs1.Length; i += 90)
            //{

            //    for (int j = 0; j < 3; j++)
            //    {
            //        var inp = new double[9];
            //        var tmp = vs1[i + j];
            //        for (int k = 0; k < 9; k++)
            //        {
            //            inp[k] = tmp[k] / tmp[k + 1];
            //        }

            //        model.Compute(inp).Neurons.ForEach(x =>
            //        {
            //            Console.WriteLine(x.Value + "  ");
            //        });
            //        Console.WriteLine();
            //    }
            //}
            model.Save();
            Console.Beep();
            Console.ReadKey();
        }