当前位置: 首页>>代码示例>>C#>>正文


C# Network.AddBiasNeuron方法代码示例

本文整理汇总了C#中Network.AddBiasNeuron方法的典型用法代码示例。如果您正苦于以下问题:C# Network.AddBiasNeuron方法的具体用法?C# Network.AddBiasNeuron怎么用?C# Network.AddBiasNeuron使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Network的用法示例。


在下文中一共展示了Network.AddBiasNeuron方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Run

        public static void Run()
        {
            var trainingSets = LoadTrainingSets();

            Network network = new Network(13, 1, 4, 3);
            network.AddBiasNeuron(0);
            double error = 0;
            double deltaDrop = 0;
            int tries = 0;
            do
            {
                //if (tries % 5 == 0 && deltaDrop < 0.5)
                //{
                //    Console.Write("Randomizing weights");
                //    network.RandomizeWeights();
                //}
                Console.WriteLine("Optimizing...");
                //network.Weights = BruteOptimizer.OptimizeMulti(network, trainingSets);
                network.Weights = BackPropOptimizer.Optimize(network, trainingSets, 2, 1);
                var newError = network.Error(trainingSets, network.Weights);
                deltaDrop = error - newError;
                error = newError;
                Console.WriteLine("Error from last optimization attempt: " + error);
                tries++;
            } while (error > 5 /*false || error > 10 || deltaDrop < 1*/);

            Console.WriteLine("Optimization complete!");
            while (true)
            {
                Console.Write("Enter comma-separated inputs: ");
                var inputs = Console.ReadLine().Split(',');
                if (inputs.Length == 1)
                {
                    break;
                }
                var inputArray = new double[13];
                for (var i = 0; i < 13; i++)
                {
                    var minVal = RawTrainingSets.Min(set => set.Inputs[i]);
                    var maxVal = RawTrainingSets.Max(set => set.Inputs[i]);
                    inputArray[i] = Normalize(double.Parse(inputs[i].Trim()), minVal, maxVal);
                }
                var output = network.Pulse(inputArray);
                Console.WriteLine(output[0] + " " + output[1] + " " + output[2]);
            }
        }
开发者ID:matthewsot,项目名称:zoltar,代码行数:46,代码来源:WineMatch.cs

示例2: Run

        public static void Run()
        {
            TrainingSets = new TrainingSet[0];

            Network = new Network(9, 3, 10, 9);
            Network.AddBiasNeuron(0);
            Network.AddBiasNeuron(1);
            Network.AddBiasNeuron(2);
            double error = 0;

            Console.WriteLine("Optimization complete!");
            var beforePrompt = 10;
            while (true)
            {
                beforePrompt--;
                Console.WriteLine(beforePrompt);
                var control = false;
                if (beforePrompt <= 0)
                {
                    Console.WriteLine("Take control? (Type TC)");
                    control = Console.ReadLine() == "TC";
                    if (control)
                    {
                        beforePrompt = 0;
                    }
                    else
                    {
                        beforePrompt = 30;
                    }
                }
                var board = GenerateBoard(0);
                var lastMove = -1;
                var lastComputerMove = -1;

                do
                {
                    Console.WriteLine("Board: ");
                    OutputBoard(board);

                    var spot = RandomMove(board);
                    if (control)
                    {
                        Console.Write("Pick to drop an X: ");
                        spot = int.Parse(Console.ReadLine());
                    }
                    board[spot] = -1;
                    lastMove = spot;
                    if (WinnerOfBoard(board) != -2)
                    {
                        break;
                    }
                    //var computerChoice = BestNextMove(board);
                    var output = Network.Pulse(board);
                    var computerChoice = -1;
                    double computerMax = -1;
                    for (var i = 0; i < output.Length; i++)
                    {
                        if (board[i] != 0)
                        {
                            continue;
                        }
                        if (output[i] > computerMax)
                        {
                            computerChoice = i;
                            computerMax = output[i];
                        }
                    }
                    if (computerChoice == -1) computerChoice = 0;
                    board[computerChoice] = 1;
                    lastComputerMove = computerChoice;
                } while (WinnerOfBoard(board) == -2);

                var winner = WinnerOfBoard(board);
                switch (winner)
                {
                    case 0:
                        Console.WriteLine("Tie!");
                        break;
                    case -1:
                        board[lastMove] = 0;
                        var output = new double[9];
                        output[lastMove] = 1;
                        Console.WriteLine("You win!");
                        Train(new TrainingSet(board, output), 1);
                        break;
                    case 1:
                        board[lastComputerMove] = 0;
                        output = new double[9];
                        output[lastComputerMove] = 1;
                        Console.WriteLine("Computer wins!");
                        Train(new TrainingSet(board, output), -1);
                        break;
                }
                Console.WriteLine("Final Board: ");
                OutputBoard(board);
            }
        }
开发者ID:matthewsot,项目名称:zoltar,代码行数:97,代码来源:SketchyTicTacToe.cs


注:本文中的Network.AddBiasNeuron方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。