Exemple #1
0
        public void addChild(object childname, string childtype)
        {
            if (Children == null)
            {
                Children = new List <SimpleNode>();
            }

            if (childname is SimpleNode)
            {
                Children.Add((SimpleNode)childname);
            }
            else
            {
                SimpleNode ch = new SimpleNode();
                ch.initNode((string)childname, "default", null, null);
                Children.Add(ch);
            }
        }
Exemple #2
0
        public SimpleNode buildtree(object nd, DataHolder dataholder, List <string> features_to_exclude, string default_class)
        {
            dataholder.CalculateNumbers();
            SimpleNode root = null;

            if (dataholder.IsPure)
            {
                root = new SimpleNode();
                root.initNode(dataholder.getPureClass(), "class", null, dataholder);
                return(root);
            }

            if (dataholder.Features_list != null)
            {
                /*if (dataholder.Featurestoexclude == null) {
                 *  default_class = dataholder.getMajorityClass();
                 *  root = new SimpleNode();
                 *  root.initNode(default_class, "class", null, dataholder);
                 *  //return root;
                 * }
                 * else */
                int lhs = dataholder.Featurestoexclude != null ? dataholder.Featurestoexclude.Count : 0;
                int rhs = dataholder.Features_list != null ? dataholder.Features_list.Count - 1 : 0;
                if (lhs == rhs)
                {
                    default_class = dataholder.getMajorityClass();
                    root          = new SimpleNode();
                    root.initNode(default_class, "class", null, dataholder);
                    //return root;
                }
                else
                {
                    root = new SimpleNode();
                    root.initNode(dataholder.Best_feature, "feature", null, dataholder);
                    foreach (string uniq in dataholder.Feature_uniqueValues[dataholder.Best_feature])
                    {
                        DataHolder new_dholder = new DataHolder(dataholder.getSubset(uniq, dataholder.Best_feature), dataholder.Featurestoexclude);
                        new_dholder.CalculateNumbers();
                        SimpleNode node = new SimpleNode();
                        node.initNode(uniq, "value", null, new_dholder);

                        if (new_dholder.IsEmpty())
                        {
                            node.addChild(dataholder.getMajorityClass(), "class");
                        }
                        else
                        {
                            if (features_to_exclude == null)
                            {
                                features_to_exclude = new List <string>();
                            }
                            features_to_exclude.Add(new_dholder.Best_feature);
                            new_dholder.removeFeatures(features_to_exclude);
                            node.addChild(buildtree(uniq, new_dholder, features_to_exclude, default_class), null);
                        }
                        root.addChild(node, node.Nodetype);
                    }
                }
            }
            return(root);
        }