示例#1
0
 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)); });
 }
示例#2
0
 //Constructor
 public DecisionTreeNode(int p_input_index, float p_min_input, float p_max_input, float[] p_output_values)
 {
     m_input_index   = p_input_index;
     m_min_input     = p_min_input;
     m_max_input     = p_max_input > p_min_input ? p_max_input : p_min_input;
     m_output_values = ArrayCalc.shallowClone(p_output_values);
 }
示例#3
0
 //Express
 public DecisionTree express(T controller)
 {
     return(new DecisionTree(
                recExpress(Root),
                ArrayCalc.map(m_inputs, (DInputFactory <T> p_fact) => { return p_fact(controller); }),
                ArrayCalc.map(m_outputs, (DOutputFactory <T> p_fact) => { return p_fact(controller); })
                ));
 }
                //Private constructor for cloning
                private NeuralNetDNA(int p_id, DInputFactory <T>[] p_inputs, DOutputFactory <T>[] p_outputs, Range <float> p_mutation_multiplier)
                {
                    m_id      = p_id;
                    m_inputs  = ArrayCalc.shallowClone(p_inputs);
                    m_outputs = ArrayCalc.shallowClone(p_outputs);

                    m_mutation_multiplier = p_mutation_multiplier;
                }
示例#5
0
        static void Main(string[] args)
        {
            ArrayCalc calc = new ArrayCalc();

            double[] n = { 1.0, 2.0, 3.3, 5.5, 6.3, -4.5, 12.0 };
            Console.WriteLine(calc.Sum(n));
            Console.WriteLine(calc.AVG(n));
            Console.WriteLine(calc.Max(n));
            Console.WriteLine(calc.Min(n));
        }
示例#6
0
                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 DecisionNetDNA(int p_id, DInputFactory <T>[] p_inputs, DOutputFactory <T>[] p_outputs, Matrix <float> p_weights, Range <float> p_mutation_multiplier)
                {
                    if (!MatrixCalc.isSize(p_weights, p_inputs.Length, p_outputs.Length))
                    {
                        Debug.LogError("DecisionNetDNA requires Matrix input size inputs by outputs");
                    }

                    m_id                  = p_id;
                    m_inputs              = ArrayCalc.shallowClone(p_inputs);
                    m_outputs             = ArrayCalc.shallowClone(p_outputs);
                    m_weights             = MatrixCalc.shallowClone(MatrixCalc.columnNormalize(p_weights));
                    m_mutation_multiplier = p_mutation_multiplier;
                }
        public void MaxTest()
        {
            ArrayCalc calc = new ArrayCalc();

            double[] n        = { 1.0, 2.0, 3.3, 5.5, 6.3, -4.5, 12.0 };
            double   expected = 12.0;

            // act
            double actual = calc.Max(n);

            //assert
            Assert.AreEqual(expected, actual);
        }
示例#9
0
                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));
                }
示例#10
0
                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 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;
                }
示例#12
0
 //Mutation
 public DecisionTreeDNA <T> mutate()
 {
     return(new DecisionTreeDNA <T>(recMutate(Root), ArrayCalc.shallowClone(m_inputs), ArrayCalc.shallowClone(m_outputs), m_mutation_mult));
 }
示例#13
0
 //Crossover
 public DecisionTreeDNA <T> crossover(DecisionTreeDNA <T> p_crossover_object)
 {
     return(new DecisionTreeDNA <T>(recCrossover(Root, p_crossover_object.Root), ArrayCalc.shallowClone(m_inputs), ArrayCalc.shallowClone(m_outputs), m_mutation_mult));
 }