Пример #1
0
 public double[] feedResult(double[] pattern)
 {
     lock (locker)
     {
         return(nn.feedResult(pattern));
     }
 }
Пример #2
0
        void set_test(string setfile)
        {
            learn.open(setfile, out var stream, out int len, out nn, out var nnfile, out var dir, out var file);

            string line = "";
            uint   skip = 0;
            uint   pos  = 0;

            do
            {
                pos += skip;
                for (int i = 0; i < skip; i++)
                {
                    learn.GetNextGame(stream, len, out var a, out var b);
                }

                pos++;
                learn.GetNextGame(stream, len, out var inputs, out var result);
                double ourOutput = nn.feedResult(inputs)[0];

                Console.WriteLine();
                Console.WriteLine("#" + pos);
                Console.WriteLine($"Inputs : {string.Join(",", inputs)}");
                Console.WriteLine($"Correct : {result[0]}");
                Console.WriteLine($"OurOutput : {ourOutput}");

                line = Console.ReadLine();
                uint.TryParse(line, out skip);
            }while (line != "stop");
        }
Пример #3
0
        public void nn_test(string nnfile, string serializerName = nameof(StdSerializers.AllOneHotSerial))
        {
            string path = File.Exists(nnfile) ? nnfile : root.StdDir + nnfile;

            nn = new vnn(File.ReadAllBytes(path));

            getPlayers(out Player A, out Player B, out var data);
            ObviousWin(A, B);

            //double[] inputs = LearningGround.serializer.ConvertPosition(A);
            double[] inputs    = StdSerializers.Util.CreateFromName(serializerName, data).ConvertPosition(A);
            double   output    = nn.feedResult(inputs)[0];
            double   formatted = Math.Round(output, 2) * 100;

            Console.WriteLine($"A will win = {formatted}%");
        }
Пример #4
0
        public static void TestLoop(this vnn nn, Func <string, double[]> input_translator, Func <double[], string> output_translator)
        {
            try
            {
                while (true)
                {
                    double[] inp = new double[nn.NInput];

                    Console.Write("in = ");
                    inp = input_translator(Console.ReadLine());
                    Console.WriteLine();

                    double[] ans = nn.feedResult(inp);
                    Console.WriteLine("out = " + output_translator(ans));
                    Console.WriteLine("".PadRight(10, '='));
                }
            } catch { }
        }
Пример #5
0
        unsafe void testWeights(double[] inputs, Action <ISimpleMLP> randFunc, string name)
        {
            var nn = new vnn(NINPUTS, NHIDDEN, NOUTPUT, randFunc);
            //var nn = new vnnCpp(NINPUTS, NHIDDEN, NOUTPUT);

            var re = nn.feedResult(inputs);

            //Histogram.PrintHist(nn.hiddenNeurons);
            Histogram.PrintHist(re);
            Histogram.ShowHist(re, name: name);
            //PrintHist(re);

            //Write("Inputs\t: ");
            //PrintHist(nn.inputNeurons.Take(NINPUTS).ToArray());
            //Write("Hidden\t: ");
            //PrintHist(nn.hiddenNeurons.Take(NHIDDEN).ToArray(), lower: 0, upper: 1);
            //Write("Output\t: ");
            //PrintHist(nn.outputNeurons, lower: 0, upper: 1);
        }
Пример #6
0
        static void GetError(FileStream logStream, int len, vnn nn, out double err, out double corr, out double avg_out)
        {
            const int n = 3000;

            err = 0.0; corr = 0.0; avg_out = 0.0;
            for (int i = 0; i < n; i++)
            {
                if (learn.GetNextGame(logStream, len, out var inp, out var res))
                {
                    double output = nn.feedResult(inp)[0];
                    double diff   = Math.Abs(res[0] - output);

                    err     = (err * i + diff) / (double)(i + 1);
                    avg_out = (avg_out * i + output) / (double)(i + 1);

                    if (diff < 0.5)
                    {
                        corr++;
                    }
                }
Пример #7
0
        public static void TestLoop(this vnn nn, Func <double[], double[]> answerkey, Func <string, double[]> translator)
        {
            try
            {
                while (true)
                {
                    double[] inp = new double[nn.NInput];

                    Console.Write("in = ");
                    inp = translator(Console.ReadLine());
                    Console.WriteLine();

                    double[] ans  = nn.feedResult(inp);
                    double[] corr = answerkey(ans);
                    for (int i = 0; i < nn.NOutput; i++)
                    {
                        Console.WriteLine("ou[{0}] = {1:0.000}; co[{0}] = {2:0.000}; dx[{0}] = {3:0.000};", i, ans[i], corr[i], Abs(corr[i] - ans[i]));
                    }
                    Console.WriteLine("".PadRight(10, '='));
                }
            } catch { }
        }
Пример #8
0
 public static void TestLoop(this vnn nn)
 {
     try
     {
         while (true)
         {
             double[] inp = new double[nn.NInput];
             for (int i = 0; i < nn.NInput; i++)
             {
                 System.Console.Write("in[" + i + "] = ");
                 inp[i] = double.Parse(System.Console.ReadLine());
             }
             System.Console.WriteLine();
             double[] ans = nn.feedResult(inp);
             for (int i = 0; i < nn.NOutput; i++)
             {
                 Console.WriteLine("ou[" + i + "] = " + Round(ans[i], 5));
             }
             Console.WriteLine("".PadRight(10, '='));
         }
     } catch { }
 }
Пример #9
0
        void fulladopt_test(string datafile)
        {
            learn.open(datafile, out var stream, out int len, out nn, out var nnfile, out var dir, out var file);

            ReportAsync();
            WaitStopAsync();

            err = 0.0; corr = 0.0; i = 0;
            while (learn.GetNextGame(stream, len, out var inp, out var res))
            {
                double output = nn.feedResult(inp)[0];
                double diff   = Math.Abs(res[0] - output);

                err  = (err * i + diff) / (double)(i + 1);
                corr = (corr * i + (diff < 0.5 ? 1 : 0)) / (double)(i + 1);

                i++;
                if (stop)
                {
                    return;
                }
            }
        }