Exemple #1
0
        /**
         * Creates a child rule to this node by applying the rule to its current entries
         * Open to method name suggestions.
         */
        internal Node ChildByRule(Rule rule)
        {
            List <CollisionEntry> passed = new List <CollisionEntry>();
            List <CollisionEntry> failed = new List <CollisionEntry>();

            CollisionEntry.EvaluateEntries(currentEntries, failed, passed, rule);

            List <Rule> childRules = new List <Rule>(usedRules)
            {
                rule
            };

            headersToIgnore.Add(rule.v1);
            Node child = new Node(passed, depth + 1, childRules, this, headersToIgnore);

            if (children == null)
            {
                children = new List <Node>()
                {
                    child
                }
            }
            ;
            else
            {
                children.Add(child);
            }
            return(child);
        }
Exemple #2
0
        public void createChildrenFromRule(Rule rule)
        {
            List <CollisionEntry> failed = new List <CollisionEntry>();
            List <CollisionEntry> passed = new List <CollisionEntry>();

            CollisionEntry.EvaluateEntries(currentEntries, failed, passed, rule);
            if (failed.Count < 1)
            {
                return;
            }
            currentEntries = null;
            Rule        failedRule  = rule.Invert();
            List <Rule> failedRules = new List <Rule>(usedRules)
            {
                failedRule
            };
            List <Rule> passedRules = new List <Rule>(usedRules)
            {
                rule
            };

            children = new List <Node>();
            Node c1 = new Node(failed, depth + 1, failedRules, this, this.headersToIgnore);
            Node c2 = new Node(passed, depth + 1, passedRules, this, this.headersToIgnore);

            children.Add(c1); children.Add(c2);
            C4p5.nextIterationNodes.Add(c1);
            C4p5.nextIterationNodes.Add(c2);
        }
Exemple #3
0
        internal void ApplyAllRules(List <Rule> rules)
        {
            List <CollisionEntry> passed;
            List <CollisionEntry> failed;

            foreach (Rule rule in rules)
            {
                headersToIgnore.Add(rule.v1);
                passed = new List <CollisionEntry>();
                failed = new List <CollisionEntry>();
                //Console.WriteLine("Applying rule " + rule.ToString());
                CollisionEntry.EvaluateEntries(currentEntries, failed, passed, rule);
                currentEntries = passed;
            }
        }
Exemple #4
0
        public void createChildrenFromEntropy()
        {
            if (C4p5.Header_To_Predict == -1)
            {
                throw new Exception("You forgot to se the Header to predict");
            }
            //If they are all the same class we are done
            if (Helper.AllSame(currentEntries, C4p5.Header_To_Predict))
            {
                return;
            }

            int Header_To_Split = Helper.AttributeWithBestInfoGain(currentEntries, C4p5.Header_To_Predict);

            int[] values = Helper.GetValuesOfHeaders(currentEntries)[Header_To_Split];

            children = new List <Node>();
            foreach (int v in values)
            {
                Rule rule = new Rule(Header_To_Split, v, HValType.HeaderCompVal, Operator.Equals);
                List <CollisionEntry> passed = new List <CollisionEntry>();
                List <CollisionEntry> failed = new List <CollisionEntry>();
                CollisionEntry.EvaluateEntries(currentEntries, failed, passed, rule);
                if (passed.Count < 1)
                {
                    continue;
                }
                List <Rule> passedRules = new List <Rule>(usedRules)
                {
                    rule
                };
                Node n = new Node(passed, depth + 1, passedRules, this, this.headersToIgnore);
                children.Add(n);
                C4p5.nextIterationNodes.Add(n);
            }
            if (children.Count == 0)
            {
                children = null;
            }
            return;
        }