public Gene crossover(Gene p_crossover_object) { Gene new_gene = new Gene(m_genes.Length, new Range <float>(0, 0), m_mutation_iterations, m_mutation_range); for (int i = 0; i < new_gene.m_genes.Length; i++) { new_gene.m_genes[i] = BoolCalc.random() ? m_genes[i] : p_crossover_object.m_genes[i]; } return(new_gene); }
public override NeuralNetDNA <T> mutate() { NeuralNetDNA <T> mutated = Clone(); for (int i = 0; i < m_weights.Length; i++) { bool test = BoolCalc.random(); Range <float> mut = test ? m_mutation_multiplier : new Range <float>(-m_mutation_multiplier.Min, -m_mutation_multiplier.Max); mutated.m_weights[i] = MatrixCalc.elementwiseRandomMultiply(m_weights[i], mut); } return(mutated); }
public DecisionTreeDNANode crossover(DecisionTreeDNANode p_crossover_object) { int cross_input_index = BoolCalc.random() ? m_input_index : p_crossover_object.m_input_index; float cross_min_input = BoolCalc.random() ? m_min_input : p_crossover_object.m_min_input; float cross_max_input = BoolCalc.random() ? m_max_input : p_crossover_object.m_max_input; if (cross_max_input < cross_min_input) { cross_max_input = cross_min_input; } float[] cross_output_values = ArrayCalc.crossover(m_output_values, p_crossover_object.m_output_values); return(new DecisionTreeDNANode(cross_input_index, cross_min_input, cross_max_input, cross_output_values)); }
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); } }
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); }
public void add(string p_type, float p_priority, DPriorityDelegate p_callback) { if (!m_list.ContainsKey(p_type)) { m_list.Add(p_type, new PriorityElement(p_priority, p_callback)); return; } if (m_list[p_type].Priority > p_priority) { return; } if (m_list[p_type].Priority == p_priority) { if (!BoolCalc.random()) { return; } } m_list.Remove(p_type); m_list.Add(p_type, new PriorityElement(p_priority, p_callback)); }