コード例 #1
0
        public void testDecisionListHandlesEmptyDataSet()
        {
            // tests first base case of recursion
            DecisionList dlist = new DecisionList("Yes", "No");

            aima.net.learning.inductive.DecisionListTest test1 = new aima.net.learning.inductive.DecisionListTest();
            test1.add("type", "Thai"); // doesn't match first example
            dlist.add(test1, "test1success");
        }
コード例 #2
0
        public void testDLTestMatchFailsOnMismatchedExample()
        {
            DataSet ds = DataSetFactory.getRestaurantDataSet();
            Example e  = ds.getExample(0);

            aima.net.learning.inductive.DecisionListTest test = new aima.net.learning.inductive.DecisionListTest();
            test.add("type", "Thai");
            Assert.IsFalse(test.matches(e));
        }
コード例 #3
0
        public void testDLTestMatchSucceedsWithMatchedExample()
        {
            DataSet ds = DataSetFactory.getRestaurantDataSet();
            Example e  = ds.getExample(0);

            aima.net.learning.inductive.DecisionListTest test = new aima.net.learning.inductive.DecisionListTest();
            test.add("type", "French");
            Assert.IsTrue(test.matches(e));
        }
コード例 #4
0
        public void testDLTestMatchesEvenOnMismatchedTargetAttributeValue()


        {
            DataSet ds = DataSetFactory.getRestaurantDataSet();
            Example e  = ds.getExample(0);

            aima.net.learning.inductive.DecisionListTest test = new aima.net.learning.inductive.DecisionListTest();
            test.add("type", "French");
            Assert.IsTrue(test.matches(e));
        }
コード例 #5
0
        public void testDecisionListWithSingleTestReturnsTestValueIfTestSuccessful()


        {
            DecisionList dlist = new DecisionList("Yes", "No");
            DataSet      ds    = DataSetFactory.getRestaurantDataSet();

            aima.net.learning.inductive.DecisionListTest test = new aima.net.learning.inductive.DecisionListTest();
            test.add("type", "French");

            dlist.add(test, "test1success");

            Assert.AreEqual("test1success", dlist.predict(ds.getExample(0)));
        }
コード例 #6
0
        public void testDecisionListFallsThruToDefaultIfNoTestMatches()


        {
            DecisionList dlist = new DecisionList("Yes", "No");
            DataSet      ds    = DataSetFactory.getRestaurantDataSet();

            aima.net.learning.inductive.DecisionListTest test1 = new aima.net.learning.inductive.DecisionListTest();
            test1.add("type", "Thai"); // doesn't match first example
            dlist.add(test1, "test1success");

            aima.net.learning.inductive.DecisionListTest test2 = new aima.net.learning.inductive.DecisionListTest();
            test2.add("type", "Burger");
            dlist.add(test2, "test2success");// doesn't match first example

            Assert.AreEqual("No", dlist.predict(ds.getExample(0)));
        }
コード例 #7
0
        public void testDLTestReturnsMatchedAndUnmatchedExamplesCorrectly()


        {
            DataSet ds = DataSetFactory.getRestaurantDataSet();

            aima.net.learning.inductive.DecisionListTest test = new aima.net.learning.inductive.DecisionListTest();
            test.add("type", "Burger");

            DataSet matched = test.matchedExamples(ds);

            Assert.AreEqual(4, matched.size());

            DataSet unmatched = test.unmatchedExamples(ds);

            Assert.AreEqual(8, unmatched.size());
        }
コード例 #8
0
        public void testDecisionListMerge()
        {
            DecisionList dlist1 = new DecisionList("Yes", "No");
            DecisionList dlist2 = new DecisionList("Yes", "No");
            DataSet      ds     = DataSetFactory.getRestaurantDataSet();

            aima.net.learning.inductive.DecisionListTest test1 = new aima.net.learning.inductive.DecisionListTest();
            test1.add("type", "Thai"); // doesn't match first example
            dlist1.add(test1, "test1success");

            aima.net.learning.inductive.DecisionListTest test2 = new aima.net.learning.inductive.DecisionListTest();
            test2.add("type", "French");
            dlist2.add(test2, "test2success");// matches first example

            DecisionList dlist3 = dlist1.mergeWith(dlist2);

            Assert.AreEqual("test2success", dlist3.predict(ds.getExample(0)));
        }
コード例 #9
0
        public virtual ICollection <DecisionListTest> createDLTestsWithAttributeCount(DataSet ds, int i)
        {
            if (i != 1)
            {
                throw new RuntimeException("For now DLTests with only 1 attribute can be craeted , not" + i);
            }
            ICollection <string>           nonTargetAttributes = ds.getNonTargetAttributes();
            ICollection <DecisionListTest> tests = CollectionFactory.CreateQueue <DecisionListTest>();

            foreach (string ntAttribute in nonTargetAttributes)
            {
                ICollection <string> ntaValues = ds.getPossibleAttributeValues(ntAttribute);
                foreach (string ntaValue in ntaValues)
                {
                    DecisionListTest test = new DecisionListTest();
                    test.add(ntAttribute, ntaValue);
                    tests.Add(test);
                }
            }
            return(tests);
        }
コード例 #10
0
ファイル: DecisionList.cs プロジェクト: tvn-cosine/aima.net
 public void add(DecisionListTest test, string outcome)
 {
     tests.Add(test);
     testOutcomes.Put(test, outcome);
 }