Example #1
0
        public static void LoadValueNetworkAndTestOnAllStates()
        {
            string modelPath = @"C:\Users\pstepnowski\Source\Repos\fdafadf\basics\Workspace\TicTacToeKerasModel.bin";

            Console.WriteLine($"Loading Testing Data");
            var testingData = TicTacToeValueLoader.LoadAllUniqueStates(null);

            //TicTacToeTrainingData.Load(TicTacToeNeuralIOLoader.InputTransforms.Bipolar, out double[][] inputs, out TicTacToeResultProbabilities[] outputs);
            Console.WriteLine($"Loading Model");
            var model = new KerasModel(() => BaseModel.LoadModel(modelPath));

            Console.WriteLine($"Testing Model (All Possible States)");
            TestModel(model, testingData, (l, p, i) => false, out int correct, out int wrong);;
            Console.WriteLine(string.Format("Correct: {0}", correct));
            Console.WriteLine(string.Format("Wrong: {0}", wrong));
        }
Example #2
0
        public static void PredictTimeTest()
        {
            global::Keras.Keras.DisablePySysConsoleLog = true;
            string modelPath = @"C:\Users\pstepnowski\Source\Repos\fdafadf\basics\Workspace\TicTacToeKerasModel.bin";

            Console.WriteLine($"Loading Model");
            var model     = new KerasModel(() => BaseModel.LoadModel(modelPath));
            var startTime = DateTime.Now;

            //Parallel.ForEach(Enumerable.Range(1, 100), (a) =>
            //{
            //});

            for (int i = 0; i < 100; i++)
            {
                model.Predict(new double[] { 1, 0, 1, 0, 1, 0, 1, 0, 1 });
            }

            var elapsedTime = DateTime.Now - startTime;

            Console.WriteLine($"{elapsedTime}");
            List <double[]> inputs     = new List <double[]>();
            var             startTime2 = DateTime.Now;

            for (int i = 0; i < 100; i++)
            {
                int a = i & 1;
                int b = i & 2;
                int c = i & 4;
                int d = i & 8;
                int e = i & 16;
                int f = i & 32;
                int g = i & 64;
                inputs.Add(new double[] { a, b, c, d, e, f, g, 0, 1 });
            }

            model.Predict(inputs.ToArray());
            var elapsedTime2 = DateTime.Now - startTime2;

            Console.WriteLine($"{elapsedTime2}");
        }
Example #3
0
        private static void TestModel <TState, TLabel>(KerasModel model, LabeledState <TState, TLabel>[] testingData, Func <TLabel, float[], int, bool> outputComparer, out int correct, out int wrong)
        {
            correct = 0;
            wrong   = 0;

            string boardLineToString(double[] input, int line)
            {
                string result = string.Empty;

                for (int x = 0; x < 3; x++)
                {
                    double v = input[line * 3 + x];
                    result += v < 0 ? "X" : (v > 0 ? "O" : ".");
                }

                return(result);
            }

            float[] outputs = model.Predict(testingData.Select(item => item.Input).ToArray());

            for (int i = 0; i < testingData.Length; i++)
            {
                double[] input          = testingData[i].Input;
                TLabel   expectedOutput = testingData[i].Label;

                if (outputComparer(expectedOutput, outputs, i))
                {
                    correct++;
                }
                else
                {
                    //Console.WriteLine($"{boardLineToString(input, 0)}   O: {output[0]:f3}   O: {expectedOutput[0]:f3}");
                    //Console.WriteLine($"{boardLineToString(input, 1)}   X: {output[1]:f3}   X: {expectedOutput[1]:f3}");
                    //Console.WriteLine($"{boardLineToString(input, 2)}      {output[2]:f3}      {expectedOutput[2]:f3}");
                    wrong++;
                }
            }
        }
Example #4
0
 public KerasPVNetwork(KerasModel model)
 {
     Model = model;
 }
Example #5
0
 public TicTacToeKerasAI(string modelPath)
 {
     //PythonEngine.BeginAllowThreads();
     model = new KerasModel(() => BaseModel.LoadModel(modelPath));
 }