Ejemplo n.º 1
0
        public SimpleDecisionTreeBuilder(ItemSet learningItemSet, AttributeSet testAttributeSet, SymbolicAttribute goalAttribute)
        {
            System.Console.WriteLine("Inside the tree builder!!!!!!!!!!");
            if (learningItemSet == null || learningItemSet.NumOfItems() == 0)
            {
                throw new ArgumentNullException();
            }

            this._learningSet      = learningItemSet;
            this._testAttributeSet = testAttributeSet;
            this._goalAttribute    = goalAttribute;

            LearningDecisionTree tree =
                new LearningDecisionTree(learningItemSet.AttrSet, goalAttribute, learningItemSet);

            this._tree = tree;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Finds the test on each attribute performing the best split for finding the value of a 'goal'
        /// attribute.
        /// </summary>
        /// <param name="candidateAttributes"></param>
        /// <param name="goalAttribute"></param>
        /// <returns></returns>
        public IEnumerable <TestScore> BestSplitTests(AttributeSet candidateAttributes, SymbolicAttribute goalAttribute)
        {
            if (candidateAttributes == null || goalAttribute == null || candidateAttributes.Size() == 0)
            {
                throw new ArgumentNullException();
            }

            List <TestScore> bestScores = new List <TestScore>();

            List <Attribute> attributes = candidateAttributes.GetAttributes().ToList();

            foreach (Attribute attr in attributes)
            {
                bestScores.Add(BestSplitTest(attr, goalAttribute));
            }

            return(bestScores);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Find the leaf/Open node matching an item. All the (tested)attributes of the item
        /// must be known.
        /// </summary>
        /// <param name="item">An item compatible with the tree attribute set.</param>
        /// <returns>The leaf node matching item</returns>
        public Node LeafNode(Item item)
        {
            if (_attributeSet == null || _goalAttribute == null)
            {
                throw new InvalidOperationException("No attribute set or goal attribute defined.");
            }

            AttributeSet attrSet = _attributeSet;

            Node node = Root();

            while (!(node.IsLeaf()))
            {
                TestNode testNode = (TestNode)node;

                int testAttrIndex = attrSet.IndexOf(testNode.Test.Attribute);

                node = testNode.MatchingSon(item.ValueOf(testAttrIndex));
            }

            return(node);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Return the value of an attribute
 /// </summary>
 /// <param name="attrs"></param>
 /// <param name="attribute"></param>
 /// <returns></returns>
 public AttributeValue ValueOf(AttributeSet attrs, Attribute attribute)
 {
     return(this.ValueOf(attrs.IndexOf(attribute)));
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Finds the test on one attribute performing the best split (bringing the most information)
 /// for finding the value of a 'goal' attribute
 /// </summary>
 /// <param name="candidateAttributes">The set of attributes defining which attributes can be tested</param>
 /// <param name="goalAttribute">the attribute guess using the test</param>
 /// <returns></returns>
 public TestScore BestSplitTest(AttributeSet candidateAttributes, SymbolicAttribute goalAttribute)
 {
     return(BestSplitTests(candidateAttributes, goalAttribute).Max <TestScore>());
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Create an empty learning decision tree.
 /// </summary>
 /// <param name="attrSet"></param>
 /// <param name="goalAttr"></param>
 /// <param name="learnignSet"></param>
 public LearningDecisionTree(AttributeSet attrSet, SymbolicAttribute goalAttr, ItemSet learnignSet)
     : base(attrSet, goalAttr)
 {
     Root().Replace(new LearningOpenNode(0, learnignSet));
 }
 public WeightedItemSet(AttributeSet attrSet)
     : base(attrSet)
 {
     _weights    = new List <double>();
     _weightsSum = 0.0d;
 }