/// <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); }
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(); }