protected double[] GoalValueDistribution(Item item, Node node)
        {
            if (node.IsLeaf())
            {
                return(((LeafNode)node).GoalValueDistribution);
            }
            else
            {
                if (node is TestNode)
                {
                    TestNode tNode = (TestNode)node;

                    int testAttrIndex = _attributeSet.IndexOf(tNode.Test.Attribute);

                    if (item.ValueOf(testAttrIndex).IsUnknown())
                    {
                        int      nbValues = item.NumberOfAttributes();
                        double[] distr    = new double[nbValues];
                        for (int i = 0; i < nbValues; i++)
                        {
                            distr[i] = 0.0d;
                        }

                        for (int i = 0; i < tNode.NumOfSons(); i++)
                        {
                            Add(distr, Times(
                                    GoalValueDistribution(item, tNode.Son(i)),
                                    tNode.Son(i).Weight));

                            Times(distr, 1.0 / tNode.Weight);
                        }

                        return(distr);
                    }
                    else
                    {
                        Node nextNode = tNode.MatchingSon(item.ValueOf(testAttrIndex));

                        return(GoalValueDistribution(item, nextNode));
                    }
                }
            }

            throw new InvalidOperationException("Open node found while exploring tree.");
        }
        /// <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);
        }
Пример #3
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)));
 }