Exemple #1
0
        protected override Network CreateNeuralNetwork()
        {
            Random random  = new Random(Properties.Seed);
            var    network = new TicTacToeValueNetwork(Properties.NetworkLayersSize, FunctionName.Sigmoidal, random);

            return(network.Network);
        }
Exemple #2
0
        static Player Match(TicTacToeValueNetwork nought, TicTacToeValueNetwork cross)
        {
            var noughtNavigator   = new VNetworkMCTreeSearchNavigator(nought);
            var crossNavigator    = new VNetworkMCTreeSearchNavigator(cross);
            var activeNavigator   = noughtNavigator;
            var inactiveNavigator = crossNavigator;

            while (activeNavigator.CurrentNode.State.IsFinal == false)
            {
                activeNavigator.Round(50);

                Console.WriteLine(ToString(activeNavigator.CurrentNode));
                Console.WriteLine();

                var node = activeNavigator.CurrentNode.GetMostVisitedChild();
                activeNavigator.Play(node.LastAction);
                inactiveNavigator.Play(node.LastAction);
                Swap(ref activeNavigator, ref inactiveNavigator);
            }

            Console.ReadLine();
            return(activeNavigator.CurrentNode.State.GetWinner());

            //var expanderA = new PVNetworkBasedMCTreeSearchExpander<TicTacToeGame, GameState, GameAction, Player>(TicTacToeGame.Instance, new Random(0), networkA);
            //var mctsA = new PVNetworkBasedMCTreeSearch<TicTacToeGame, GameState, GameAction, Player>(expanderA);
            //var rootStateA = new GameState();
            //var nodeA = PVNetworkBasedMCTreeSearchNode<GameState, GameAction>.CreateRoot(rootStateA, networkA.);

            //mctsA.Round()
        }
Exemple #3
0
        private void Training(TrainingSettings settings)
        {
            var trainingData = TicTacToeValueLoader.LoadAllUniqueStates(Storage.Instance, TicTacToeValueNetwork.DefaultInputTransform);
            var trainer      = new TicTacToeValueNetworkTrainer(trainingData, 0)
            {
                HiddenLayerSizes = settings.Layers,
                LearingRate      = settings.LearningRate,
                Momentum         = settings.Momentum,
            };

            TrainedNetwork = trainer.Train(settings.Epoches, new TrainingMonitor(this));

            Invoke((MethodInvoker) delegate()
            {
                var accuracy          = AccuracyMonitor.CalculateAccuracy(TrainedNetwork, trainingData);
                labelAccuracy.Text    = $"{accuracy.CorrectPredictions}/{accuracy.TestingSetSize} ({accuracy.Value * 100.0:f2}%)";
                buttonTrained.Enabled = true;
            });
        }
Exemple #4
0
 public static Accuracy CalculateAccuracy(TicTacToeValueNetwork network, LabeledState <GameState, TicTacToeValue>[] data)
 {
     return(CalculateAccuracy(network.Network.Evaluate, data));
 }
Exemple #5
0
 public AccuracyMonitor(TicTacToeValueNetwork network)
 {
     Network = network;
 }
Exemple #6
0
 public TicTacToeAI(TicTacToeValueNetwork network)
 {
     Network = network;
 }
Exemple #7
0
 public VNetworkBasedMCTreeSearch(TicTacToeValueNetwork network) : base(new VNetworkBasedMCTreeSearchExpander(TicTacToeGame.Instance))
 {
     Network = network;
 }
Exemple #8
0
 public VNetworkMCTreeSearchNavigator(TicTacToeValueNetwork network) : base(new VNetworkBasedMCTreeSearch(network), TicTacToeGame.Instance, new MCTreeSearchNode <GameState, GameAction>(new GameState()))
 {
 }