/// <summary>
        /// Trains a new player network based on available database data and returns the most accurate network, previous or new.
        /// </summary>
        /// <param name="playerId"></param>
        /// <param name="currentHandId"></param>
        /// <param name="currentNetwork"></param>
        /// <returns></returns>
        protected PAPNetworkContainer trainPlayerNetwork(long playerId, long currentHandId, PAPNetworkContainer previousNetwork, long startingHandId, int maxTrainingActions)
        {
            DateTime startTime = DateTime.Now;

            PAPNetworkContainer  returnNetworkContainer;
            PokerPlayerNNModelv1 playerPredictionNNModel = new PokerPlayerNNModelv1();

            playerPredictionNNModel.populatePlayActions(playerId, maxTrainingActions, startingHandId);
            playerPredictionNNModel.SuffleDataSource();

            if (playerPredictionNNModel.DataSourceCount < minActionsRequiredForNetwork)
            {
                return(previousNetwork);
            }

            playerPredictionNNModel.createNetwork();
            playerPredictionNNModel.createTrainingSets();
            playerPredictionNNModel.trainNetwork();
            playerPredictionNNModel.createTestingSets();

            BasicNetwork newPlayerNetwork   = playerPredictionNNModel.Network;
            decimal      newNetworkAccuracy = playerPredictionNNModel.getNetworkAccuracy();

            //We need to get the accuracy of the previous network on the new data so that it is a fair comparison
            playerPredictionNNModel.Network = previousNetwork.PlayerNetworkPool.BaseNetwork;
            decimal previousNetworkAccuracy = playerPredictionNNModel.getNetworkAccuracy();

            if (newNetworkAccuracy > previousNetworkAccuracy)
            {
                previousNetwork.UpdateNetwork(newPlayerNetwork, newNetworkAccuracy, playerPredictionNNModel.DataSourceCount, currentHandId);
            }
            else
            {
                //Regardless of whether we replace network/accuracy, we reset the trainingActions and mostRecentHandId
                previousNetwork.UpdateNetwork(previousNetwork.PlayerNetworkPool.BaseNetwork, previousNetworkAccuracy, playerPredictionNNModel.DataSourceCount, currentHandId);
            }

            returnNetworkContainer = previousNetwork;

            //SerializeObject.Save(PAP_STORE + playerId.ToString() + ".PAPdat", returnNetworkContainer);
            returnNetworkContainer.SavePAPContainer(PAP_STORE, playerId.ToString());
            return(returnNetworkContainer);
        }
Exemple #2
0
        public void Go3()
        {
            Console.WriteLine("Let's get this show on the road!!");

            long[] allPlayerIds = new long[0];

            //Todo - Add players to allPlayerIds

            //Get all of the playerActions
            Console.WriteLine("Testing new network accuracy for {0} players.", allPlayerIds.Length);

            for (int i = 0; i < allPlayerIds.Length; i++)
            {
                try
                {
                    PokerPlayerNNModelv1 playerPrediction = new PokerPlayerNNModelv1();

                    playerPrediction.populatePlayActions(allPlayerIds[i], 10000, 0);
                    playerPrediction.SuffleDataSource();

                    //playerPrediction.createNetwork();
                    //playerPrediction.createTrainingSets();
                    //playerPrediction.trainNetwork();
                    playerPrediction.Network = NNLoadSave.loadNetwork("generalPlayer.eNN", "");

                    Console.WriteLine("... data loaded for player index {0} ({1}). {2} actions added.", i, allPlayerIds[i], playerPrediction.NeuralNetDataSource.Count);
                    //playerPrediction.SaveNNDataSource("allPlayerPAPData.csv");

                    playerPrediction.createTestingSets();
                    decimal accuracy = playerPrediction.getNetworkAccuracy();
                    Console.WriteLine("PlayerId:{0} Predicted {1}% Of Actions Correctly.", allPlayerIds[i], Math.Round(accuracy, 1));

                    using (System.IO.StreamWriter sw = new System.IO.StreamWriter("accuracy.csv", true))
                        sw.WriteLine(allPlayerIds[i] + ", " + Math.Round(accuracy, 1));
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Meh - Error on playerId {0}.", allPlayerIds[i]);
                    using (System.IO.StreamWriter sw = new System.IO.StreamWriter("errors.txt", true))
                        sw.WriteLine(ex.ToString());
                }
            }

            //NNLoadSave.saveNetwork(playerPrediction.Network, "generalPlayer.eNN", "");
            Console.WriteLine("... completed.");
            Console.ReadKey();
        }
Exemple #3
0
        public void Go2()
        {
            Console.WriteLine("Let's get this show on the road!!");

            //Get all of the playerActions
            for (int i = 0; i < 20; i++)
            {
                PokerPlayerNNModelv1 playerPrediction = new PokerPlayerNNModelv1();
                playerPrediction.LoadNNDatasource("allPlayerPAPData.csv", PokerPlayerNNModelv1.Input_Neurons, PokerPlayerNNModelv1.Output_Neurons);

                playerPrediction.SuffleDataSource();
                playerPrediction.createNetwork();
                playerPrediction.createTrainingSets();
                playerPrediction.trainNetwork();
                playerPrediction.createTestingSets();
                decimal accuracy = playerPrediction.getNetworkAccuracy();

                Console.WriteLine("Achieved {0}% accuracy.", accuracy);
                NNLoadSave.saveNetwork(playerPrediction.Network, accuracy.ToString() + "_generalPlayer.eNN", "");
            }

            Console.WriteLine("... completed.");
            Console.ReadKey();
        }