コード例 #1
0
        public void Expand()
        {
            LearningOpenNode node = _tree.OpenNode() as LearningOpenNode;

            if (node == null)
            {
                throw new Exception("No open node left");
            }

            ItemSet set     = node.LearningSet();
            double  entropy = set.CalEntropy(_goalAttribute);

            if (entropy <= _entropyThreshold || _testAttributeSet.Size() == 0)
            {
                MakeLeafNode(node);
            }
            else
            {
                TestScore testScore = set.BestSplitTest(_testAttributeSet, _goalAttribute);

                if (testScore.Score * set.Size() <= _scoreThreshold)
                { //forward pruning: test does not provide enough information
                    MakeLeafNode(node);
                }
                else
                {
                    MakeTestNode(node, testScore.Test, testScore.Score * set.Size());
                }
            }
        }
コード例 #2
0
        public int CompareTo(object obj)
        {
            TestScore to = (TestScore)obj;

            if (Score < to.Score)
            {
                return(-1);
            }
            else if (Score > to.Score)
            {
                return(1);
            }
            else
            {
                return(0);
            }
        }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="testAttr"></param>
        /// <param name="goalAttr"></param>
        /// <returns></returns>
        protected TestScore BestSplitTest(Attribute testAttr, SymbolicAttribute goalAttr)
        {
            ItemSet knownItems = new ItemSet(_attributeSet);
            int     nbKnown    = 0;

            foreach (Item it in _items)
            {
                if (!it.ValueOf(_attributeSet, testAttr).IsUnknown())
                {
                    knownItems.Add(it);
                    nbKnown++;
                }
            }

            if (nbKnown == 0)
            { //No Information can be gained from this test
                Test test;

                if (testAttr is SymbolicAttribute)
                { //Symblic test
                    test = new SymbolicTest((SymbolicAttribute)testAttr,
                                            new KnownSymbolicValue[] { new KnownSymbolicValue(0) });
                }
                else
                { //Numerical test
                    test = new NumericalTest((NumericalAttribute)testAttr, 0.0d);
                }

                return(new TestScore(test, 0.0d));
            }
            else
            {
                TestScore knownTestScore = knownItems.BestSplitTest(testAttr, goalAttr);

                return(new TestScore(knownTestScore.Test, knownTestScore.Score * (double)nbKnown / Items.Count));
            }
        }