public DecisionTreeDNANode(int p_num_inputs, Range <float> p_threshold_range, int p_num_outputs, Range <float> p_outputs_range) { m_input_index = RandomCalc.Rand(new Range <int>(0, p_num_inputs - 1)); m_min_input = RandomCalc.Rand(p_threshold_range); m_max_input = RandomCalc.Rand(new Range <float>(m_min_input, p_threshold_range.Max)); m_output_values = ArrayCalc.functionInitialize(p_num_outputs, () => { return(RandomCalc.Rand(p_outputs_range)); }); }
///<summary>Returns a random object with fitter objects more likely to be chosen.</summary> public T getRandomObject() { float indexNum = Mathf.Pow(RandomCalc.Rand(new Range <float>(0f, 1f)), 2); int index = (int)Mathf.Round(indexNum * (m_objects.Count - 1)); return(m_objects[index].Object); }
void spawnResource() { GameObject obj = Instantiate(m_resource_prefab, Vector3Calc.randomDirection() * 8f, Quaternion.identity); obj.GetComponent <Resource>().Initalize(RandomCalc.Rand(new Range <float>(10f, 100f))); ObjectLogger.log(obj, "RESOURCE"); }
public Gene mutate() { Gene clone = this.Clone(); for (int i = 0; i < m_mutation_iterations; i++) { int index = ArrayCalc.randomIndex(clone.m_genes); clone.m_genes[index] += RandomCalc.Rand(m_mutation_range); } return(clone); }
public Gene(int p_number, Range <float> p_range, int p_mutation_iterations, Range <float> p_mutation_range) { m_genes = new float[p_number]; for (int i = 0; i < m_genes.Length; i++) { m_genes[i] = RandomCalc.Rand(p_range); } m_mutation_iterations = p_mutation_iterations; m_mutation_range = p_mutation_range; }
public DecisionTreeDNANode mutate(int p_num_inputs, Range <float> p_mutation_mult) { int mut_input_index = RandomCalc.Rand(new Range <int>(0, p_num_inputs - 1)); float mut_min_input = m_min_input * RandomCalc.Rand(p_mutation_mult); float mut_max_input = m_max_input * RandomCalc.Rand(p_mutation_mult); if (mut_max_input < mut_min_input) { mut_max_input = mut_min_input; } float[] mut_output_values = ArrayCalc.shallowClone(m_output_values); for (int i = 0; i < mut_output_values.Length; i++) { mut_output_values[i] *= RandomCalc.Rand(p_mutation_mult); } return(new DecisionTreeDNANode(mut_input_index, mut_min_input, mut_max_input, mut_output_values)); }
public ADNA <DecisionNetDNA <T> > randomInstance() { return(new DecisionNetDNA <T>(m_id, m_inputs, m_outputs, Matrix <float> .Build.Dense(m_inputs.Length, m_outputs.Length, (i, j) => { return RandomCalc.Rand(m_weight_range); }), m_mutation_multiplier)); }
public NeuralNetDNA(int p_id, DInputFactory <T>[] p_inputs, DOutputFactory <T>[] p_outputs, int p_hidden_number, int p_hidden_size, Range <float> p_weight_range, Range <float> p_mutation_multiplier) { m_id = p_id; m_inputs = ArrayCalc.shallowClone(p_inputs); m_outputs = ArrayCalc.shallowClone(p_outputs); m_weights = new Matrix <float> [p_hidden_number + 1]; m_weights[0] = Matrix <float> .Build.Dense(m_inputs.Length, p_hidden_size, (i, j) => { return(RandomCalc.Rand(p_weight_range)); }); for (int i = 1; i < m_weights.Length - 1; i++) { m_weights[i] = Matrix <float> .Build.Dense(p_hidden_size, p_hidden_size, (x, y) => { return(RandomCalc.Rand(p_weight_range)); }); } m_weights[m_weights.Length - 1] = Matrix <float> .Build.Dense(p_hidden_size, m_outputs.Length, (i, j) => { return(RandomCalc.Rand(p_weight_range)); }); m_mutation_multiplier = p_mutation_multiplier; }