示例#1
0
        public void Without_any_excluded_facts_and_multiple_variants_then_all_possible_opening_facts_are_generated()
        {
            //Given
            var openingsFactsGenerator = new OpeningsFactsGenerator();
            var chessGame = new ChessGame();

            chessGame.White   = "tailuge";
            chessGame.Black   = "sydeman";
            chessGame.Result  = "1-0";
            chessGame.Opening = "King's Gambit, Polerio Gambit, something here, Accepted";

            //When
            var result = openingsFactsGenerator.Generate(new List <IFact <ChessGame> >(), chessGame);

            //Then
            var kingsGambitFact = new OpeningFact("King's Gambit");
            var kingsGambitPolerioGambitFact = new OpeningFact("King's Gambit, Polerio Gambit");
            var kingsGambitPolerioGambitSomethingHereFact = new OpeningFact("King's Gambit, Polerio Gambit, something here");
            var kingsGambitPolerioGambitAcceptedFact      = new OpeningFact("King's Gambit, Polerio Gambit, something here, Accepted");
            var gambit = new OpeningFact("Gambit");

            Assert.Equal(5, result.Count);
            Assert.Contains(kingsGambitFact, result);
            Assert.Contains(kingsGambitPolerioGambitFact, result);
            Assert.Contains(kingsGambitPolerioGambitAcceptedFact, result);
            Assert.Contains(kingsGambitPolerioGambitSomethingHereFact, result);
            Assert.Contains(gambit, result);
        }
示例#2
0
        public void Without_any_excluded_facts_and_with_an_opening_without_any_variants_then_no_variant_openings_are_generated(string opening)
        {
            //Given
            var openingsFactsGenerator = new OpeningsFactsGenerator();
            var chessGame = new ChessGame();

            chessGame.White   = "tailuge";
            chessGame.Black   = "sydeman";
            chessGame.Result  = "1-0";
            chessGame.Opening = opening;

            //When
            var result = openingsFactsGenerator.Generate(new List <IFact <ChessGame> >(), chessGame);

            //Then
            var openingFact = new OpeningFact(opening);

            Assert.Equal(1, result.Count);
            Assert.Contains(openingFact, result);
        }
示例#3
0
        public void With_excluded_facts_then_opening_facts_are_generated_that_are_not_in_the_exclusion_list()
        {
            //Given
            var openingsFactsGenerator = new OpeningsFactsGenerator();
            var chessGame = new ChessGame();

            chessGame.White   = "tailuge";
            chessGame.Black   = "sydeman";
            chessGame.Result  = "1-0";
            chessGame.Opening = "King's Gambit, Accepted";

            //When
            var kingsGambitAcceptedFact = new OpeningFact("King's Gambit, Accepted");
            var result = openingsFactsGenerator.Generate(new List <IFact <ChessGame> >()
            {
                kingsGambitAcceptedFact
            }, chessGame);

            //Then
            Assert.Equal(0, result.Count);
        }
        public IEnumerable <AssociationRule <ChessGame> > Mine(Double relativeMinsup, Double minconf, IEnumerable <IFact <ChessGame> > projectionFacts = null, IEnumerable <IFact <ChessGame> > targetFacts = null)
        {
            //Fact Generators
            var openingFactsGenerator     = new OpeningsFactsGenerator();
            var simpleFactsGenerator      = new SimpleFactsGenerator();
            var timeControlFactsGenerator = new TimeControlFactsGenerator(new TimeControlCategoriser());
            var takesFirstFactGenerator   = new TakesFirstFactGenerator();

            var candidateGenerator = new SelfJoinAndPruneGenerator <ChessGame>();
            var factGenerators     = new List <IFactsGenerator <ChessGame> >()
            {
                simpleFactsGenerator, openingFactsGenerator, timeControlFactsGenerator, takesFirstFactGenerator
            };
            var apriori  = new Apriori <ChessGame>(candidateGenerator, factGenerators);
            var filterer = new ThresholdFilterer <ChessGame>();
            var candidateRuleGenerator = new CandidateRuleGenerator <ChessGame>();

            var database      = new Database <ChessGame>(games.ToList());
            var ruleGenerator = new AssociationRuleGenerator <ChessGame>(database, apriori, candidateRuleGenerator, filterer);

            return(ruleGenerator.Generate(relativeMinsup, minconf, projectionFacts, targetFacts));
        }
示例#5
0
        static void Main(string[] args)
        {
            List <ChessGame> result;
            var serializer = new JsonSerializer();

            using (var re = File.OpenText("rated.json"))
                using (var reader = new JsonTextReader(re))
                {
                    result = serializer.Deserialize <List <ChessGame> >(reader);
                }

            var database = new Database <ChessGame>(result);

            var projectedFact1 = new OpeningFact("Gambit");
            //var projectedFact2 = new SimpleFact("White", "tailuge");
            var projectedFacts = new List <IFact <ChessGame> >()
            {
                projectedFact1
            };

            var targetFact  = new SimpleFact("Result", "1-0");
            var targetFacts = new List <IFact <ChessGame> >()
            {
                targetFact
            };

            //Fact Generators
            var openingFactsGenerator     = new OpeningsFactsGenerator();
            var simpleFactsGenerator      = new SimpleFactsGenerator();
            var timeControlFactsGenerator = new TimeControlFactsGenerator(new TimeControlCategoriser());
            var takesFirstFactGenerator   = new TakesFirstFactGenerator();

            var candidateGenerator = new SelfJoinAndPruneGenerator <ChessGame>();
            var factGenerators     = new List <IFactsGenerator <ChessGame> >()
            {
                simpleFactsGenerator, openingFactsGenerator, timeControlFactsGenerator, takesFirstFactGenerator
            };
            var apriori  = new Apriori <ChessGame>(candidateGenerator, factGenerators);
            var filterer = new ThresholdFilterer <ChessGame>();
            var candidateRuleGenerator = new CandidateRuleGenerator <ChessGame>();
            var ruleGenerator          = new AssociationRuleGenerator <ChessGame>(database, apriori, candidateRuleGenerator, filterer);

            //When
            var minsup  = 0.01;
            var minconf = 0.1;
            var rules   = ruleGenerator.Generate(minsup, minconf, projectedFacts, targetFacts);

            var i = 1;

            using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\tferguson\Documents\Visual Studio 2013\Projects\PatternDiscoveryInDataMining\Week1\chessAssociationRules.txt"))
            {
                file.WriteLine("Minsup: " + minsup + ", " + "Minconf: " + minconf);
                file.WriteLine("For games where " + projectedFacts[0] + ", ");
                file.WriteLine("there are " + rules.Count + " strong association rules \n");

                foreach (var rule in rules)
                {
                    file.Write(i + ". ");
                    file.WriteLine(rule);
                    i++;
                }
            }

            System.Console.WriteLine("Done!");
            System.Console.ReadLine();
        }