Пример #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
        /// <summary>
        /// Turns an open node to a leaf.
        /// </summary>
        /// <param name="node">The open node to transform into a leaf node.</param>
        private void MakeLeafNode(LearningOpenNode openNode)
        {
            double nodeWeight = openNode.LearningSet().Size();

            LearningLeafNode leafNode =
                new LearningLeafNode(nodeWeight, openNode.LearningSet());

            openNode.Replace(leafNode);
        }
Пример #3
0
        private void MakeTestNode(LearningOpenNode openNode, Test test, double score)
        {
            double nodeWeight = openNode.LearningSet().Size();

            LearningTestNode testNode = new LearningTestNode(nodeWeight, test, score, openNode.LearningSet());

            openNode.Replace(testNode);

            ItemSet[] subSets = openNode.LearningSet().Split(test).ToArray();

            for (int i = 0; i < test.NumOfIssues; i++)
            {
                LearningOpenNode node = new LearningOpenNode(subSets[i].Size(), subSets[i]);
                testNode.Son(i).Replace(node);
            }
        }
Пример #4
0
 private OpenNode ConvertOpenNode(LearningOpenNode node)
 {
     return(new OpenNode(node.Weight));
 }