Beispiel #1
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);
                }
Beispiel #2
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);
                }
Beispiel #3
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);
                    }
                }
Beispiel #4
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);
                }