コード例 #1
0
ファイル: Program.cs プロジェクト: jamiemaguiredotnet/nBayes
        /// <summary>This sample program has 3 options, and will use the the optimizer
        /// to run a test scenario. Two options are picked, and we will simulate user interest in one,
        /// then user sentiment changing to favor the second option.</summary>
        private static void TestOptimizer()
        {
            var optimizer = new Optimizer();

            // define the available options
            Option[] options = new Option[] {
                Option.Named("Orange"),
                Option.Named("Green"),
                Option.Named("White")
            };
            optimizer.Add(options[0]);
            optimizer.Add(options[1]);
            optimizer.Add(options[2]);

            // pick two options, and define when user interest will change
            var firstWinner  = options[2]; // white
            var secondWinner = options[1]; // green
            var switchRatio  = .35f;       // 35% of the way through the test set
            int tries        = 100;        // the test set

            for (int i = 0; i < tries; i++)
            {
                Option selected = optimizer.Choose().Result; // don't care about asyncrony in this particular example
                Console.WriteLine("Choosing: {0}", selected);

                // decide which chosen option 'the users' will prefer
                bool isFirstBatch = (float)tries * switchRatio > i;
                if (isFirstBatch && selected == firstWinner)
                {
                    firstWinner.IncrementSuccesses();
                }
                else if (!isFirstBatch && selected == secondWinner)
                {
                    secondWinner.IncrementSuccesses();
                }
            }

            Console.WriteLine("\nResults! We expect that ({0}) will have the highest success rate, and ({1}) will be in second place", secondWinner, firstWinner);
            Console.WriteLine("\nThis is the final result after {0} tries\n{1}", tries, optimizer);
        }