Ejemplo n.º 1
0
                //Assumes want random tree construction
                public DecisionTreeDNA(DecisionTreeDNANode p_root, DInputFactory <T>[] p_inputs, DOutputFactory <T>[] p_outputs, Range <float> p_mutation_mult, Range <float> p_threshold_range, Range <float> p_outputs_range, int p_max_depth) : base(p_root)
                {
                    m_inputs        = p_inputs;
                    m_outputs       = p_outputs;
                    m_mutation_mult = p_mutation_mult;

                    recRandom(Root, 0, p_max_depth, p_threshold_range, p_outputs_range);
                }
Ejemplo n.º 2
0
                private DecisionTreeNode recExpress(DecisionTreeDNANode p_express)
                {
                    DecisionTreeNode node = p_express.express();

                    if (p_express.hasLeft)
                    {
                        node.addChild(BinaryDirection.LEFT, recExpress(p_express.LeftChild), node);
                    }
                    if (p_express.hasRight)
                    {
                        node.addChild(BinaryDirection.RIGHT, recExpress(p_express.RightChild), node);
                    }

                    return(node);
                }
Ejemplo n.º 3
0
                private DecisionTreeDNANode recMutate(DecisionTreeDNANode p_mutate)
                {
                    DecisionTreeDNANode mutated = p_mutate.mutate(m_inputs.Length, m_mutation_mult);

                    if (p_mutate.hasLeft)
                    {
                        mutated.addChild(BinaryDirection.LEFT, recMutate(p_mutate.LeftChild), mutated);
                    }
                    if (p_mutate.hasRight)
                    {
                        mutated.addChild(BinaryDirection.RIGHT, recMutate(p_mutate.RightChild), mutated);
                    }

                    return(mutated);
                }
Ejemplo n.º 4
0
                private DecisionTreeDNANode recClone(DecisionTreeDNANode p_node)
                {
                    DecisionTreeDNANode clone = p_node.clone();

                    if (p_node.hasLeft)
                    {
                        clone.addChild(BinaryDirection.LEFT, recClone(p_node.LeftChild), clone);
                    }
                    if (p_node.hasRight)
                    {
                        clone.addChild(BinaryDirection.RIGHT, recClone(p_node.RightChild), clone);
                    }

                    return(clone);
                }
Ejemplo n.º 5
0
                private void recRandom(DecisionTreeDNANode p_current_node, int p_current_depth, int p_max_depth, Range <float> p_threshold_range, Range <float> p_outputs_range)
                {
                    if (p_current_depth == p_max_depth)
                    {
                        return;
                    }

                    if (BoolCalc.random())
                    {
                        p_current_node.addChild(BinaryDirection.LEFT, new DecisionTreeDNANode(m_inputs.Length, p_threshold_range, m_outputs.Length, p_outputs_range), p_current_node);
                        recRandom(p_current_node.LeftChild, p_current_depth + 1, p_max_depth, p_threshold_range, p_outputs_range);
                    }

                    if (BoolCalc.random())
                    {
                        p_current_node.addChild(BinaryDirection.RIGHT, new DecisionTreeDNANode(m_inputs.Length, p_threshold_range, m_outputs.Length, p_outputs_range), p_current_node);
                        recRandom(p_current_node.RightChild, p_current_depth + 1, p_max_depth, p_threshold_range, p_outputs_range);
                    }
                }
Ejemplo n.º 6
0
                private DecisionTreeDNANode recCrossover(DecisionTreeDNANode p_node1, DecisionTreeDNANode p_node2)
                {
                    DecisionTreeDNANode crossedover = p_node1.crossover(p_node2);

                    if (p_node1.hasLeft && p_node2.hasLeft)
                    {
                        crossedover.addChild(BinaryDirection.LEFT, recCrossover(p_node1.LeftChild, p_node2.LeftChild), crossedover);
                    }
                    else if (!p_node1.hasLeft && !p_node2.hasLeft)
                    {
                    }
                    else
                    {
                        DecisionTreeDNANode only_existing = p_node1.hasLeft ? p_node1.LeftChild : p_node2.LeftChild;
                        if (BoolCalc.random())
                        {
                            crossedover.addChild(BinaryDirection.LEFT, recClone(only_existing), crossedover);
                        }
                    }

                    if (p_node1.hasRight && p_node2.hasRight)
                    {
                        crossedover.addChild(BinaryDirection.RIGHT, recCrossover(p_node1.RightChild, p_node2.RightChild), crossedover);
                    }
                    else if (!p_node1.hasRight && !p_node2.hasRight)
                    {
                    }
                    else
                    {
                        DecisionTreeDNANode only_existing = p_node1.hasRight ? p_node1.RightChild : p_node2.RightChild;
                        if (BoolCalc.random())
                        {
                            crossedover.addChild(BinaryDirection.RIGHT, recClone(only_existing), crossedover);
                        }
                    }

                    return(crossedover);
                }
Ejemplo n.º 7
0
 //Assumes Tree is constructed
 public DecisionTreeDNA(DecisionTreeDNANode p_root, DInputFactory <T>[] p_inputs, DOutputFactory <T>[] p_outputs, Range <float> p_mutation_mult) : base(p_root)
 {
     m_inputs        = p_inputs;
     m_outputs       = p_outputs;
     m_mutation_mult = p_mutation_mult;
 }