コード例 #1
0
        private static void PrintTest(string[] tv, double[] outputArray)
        {
            var manaCostString = $"Mana Cost: {tv[0].PadLeft(3, ' ')}";
            var weights        = $"W: {outputArray[0]:0.0000}  U: {outputArray[1]:0.0000}, B: {outputArray[2]:0.0000}, R: {outputArray[3]:0.0000}, G: {outputArray[4]:0.0000}";
            var text           = tv[1];
            var prediction     = MtgDataLoader.ConvertOutputToCardColors(outputArray).PadLeft(5, ' ');

            Console.WriteLine($"{manaCostString} | {text.PadRight(30,' ')} | {prediction.PadRight(5,' ')} | {weights} ");
        }
コード例 #2
0
        private static void Train(BasicNetwork network)
        {
            // load all of the cards from the MagicAssistant library
            var cards = MtgDataLoader.GetAllCards(@"C:\Users\napol\MagicAssistantWorkspace\magiccards\MagicDB");

            // build inputs and ideals
            var mtgData = new MtgDataLoader(cards);
            var input   = mtgData.Inputs;
            var ideal   = mtgData.Ideals;

            // create training data
            IMLDataSet trainingSet = new BasicMLDataSet(input, ideal);

            // train the neural network
            IMLTrain train = new ResilientPropagation(network, trainingSet);

            int epoch = 1;

            do
            {
                train.Iteration();
                if (epoch % 10 == 0)
                {
                    Console.WriteLine(@"Epoch #" + epoch + @" Error:" + train.Error);
                }

                epoch++;

                // if we're not below 1% after 600 iterations (highly unlikely) just bow out.
                if (epoch > 1000)
                {
                    break;
                }
            } while (train.Error > 0.01);

            train.FinishTraining();

            Console.WriteLine($"Final Error: {train.Error}");

            Console.WriteLine("Writing network to file");

            if (System.IO.File.Exists("network.data"))
            {
                System.IO.File.Delete("network.data");
            }

            Encog.Util.SerializeObject.Save("network.data", network);
        }
コード例 #3
0
        private static void TestNetwork(string[][] testValues, BasicNetwork network)
        {
            // test the neural network
            Console.WriteLine(@"Neural Network Test Results:");

            foreach (var tv in testValues)

            {
                IMLData output2 = network.Compute(new BasicMLData(MtgDataLoader.GenerateInputs(tv[0], tv[1])));

                double[] outputArray = new double[5];
                for (int i = 0; i < 5; i++)
                {
                    outputArray[i] = output2[i];
                }

                // Shiny pretty console display
                PrintTest(tv, outputArray);
            }
        }