Пример #1
0
        public void Test_factorial()
        {
            var result   = Math_Utilities.factorial(3);
            var expected = 6;

            Assert.AreEqual(expected, result);
        }
        public override MEL_ArmRepertoire__Individual Generate_Offspring(
            Random randomness_provider,
            MEL_ArmRepertoire__Individual parent
            )
        {
            List <double> genome_copy = parent.genotype.DeepCopy();

            double value_range = max_gene_value - min_gene_value;

            for (int i = 0; i < genome_copy.Count; i++)
            {
                double mutation_value = Math_Utilities.Map_Value(
                    randomness_provider.NextDouble(),
                    0.0,
                    1.0,
                    -mutation_step,
                    mutation_step
                    );

                genome_copy[i] += mutation_value;

                if (genome_copy[i] > max_gene_value)
                {
                    genome_copy[i] -= value_range;
                }
                else if (genome_copy[i] < min_gene_value)
                {
                    genome_copy[i] += value_range;
                }
            }

            MEL_ArmRepertoire__Individual offspring = new MEL_ArmRepertoire__Individual(genome_copy);

            return(offspring);
        }
Пример #3
0
        public void Test_Bernstein()
        {
            var result   = Math_Utilities.Bernstein(0, 0.4);
            var expected = 0.216;

            Assert.IsTrue(Math.Abs(expected - result) < 0.0001d);
        }
Пример #4
0
        public void Test_Binomial_coef()
        {
            var    result   = Math_Utilities.binom_coef(1);
            double expected = 3;

            Assert.AreEqual(expected, result);
        }
Пример #5
0
    public void Cubic_curve(Point2d[] coordinates, int num_of_path_pts, Point2d[] path_pts)
    {
        int     icount, jcount;
        double  step, t;
        Point2d zero_point = new Point2d(0.0, 0.0);

        icount = 0;
        t      = 0;
        step   = (double)1.0 / (num_of_path_pts - 1);

        for (int k = 0; k != num_of_path_pts; k++)
        {
            if ((1.0 - t) < 0.000005)
            {
                t = 1.0;
            }

            jcount           = 0;
            path_pts[icount] = zero_point;
            for (int i = 0; i != 4; i++)
            {
                double basis = Math_Utilities.Bernstein(i, t);
                path_pts[icount] = path_pts[icount] + basis * coordinates[jcount];
                jcount           = jcount + 1;
            }

            icount += 1;
            t      += step;
        }
    }
Пример #6
0
        public static Bitmap To_HeatMap(
            this double[,] values_table,
            double min_value,
            double max_value,
            Color out_of_range__low__color,
            Color out_of_range__high__color,
            Color not_a_number__color
            )
        {
            int w = values_table.GetLength(0);
            int h = values_table.GetLength(1);

            Bitmap image = new Bitmap(w, h);

            for (int x = 0; x < w; x++)
            {
                for (int y = 0; y < h; y++)
                {
                    if (min_value == max_value)
                    {
                        double value = values_table[x, y];
                        if (Double.IsNaN(value))
                        {
                            image.SetPixel(x, y, not_a_number__color);
                        }
                        else
                        {
                            Color c = Color.FromArgb(0, 0, 0);
                            image.SetPixel(x, y, c);
                        }
                    }
                    else
                    {
                        double value = values_table[x, y];
                        if (Double.IsNaN(value))
                        {
                            image.SetPixel(x, y, not_a_number__color);
                        }
                        else if (value < min_value)
                        {
                            image.SetPixel(x, y, out_of_range__low__color);
                        }
                        else if (value > max_value)
                        {
                            image.SetPixel(x, y, out_of_range__high__color);
                        }
                        else
                        {
                            double cv = Math_Utilities.Map_Value(value, min_value, max_value, 0.0, 255.0);
                            int    ci = (int)cv;
                            Color  c  = Color.FromArgb(ci, ci, ci);
                            image.SetPixel(x, y, c);
                        }
                    }
                }
            }
            return(image);
        }
Пример #7
0
        public static Bitmap To_HeatMap(
            this int[,] values_table,
            int min_value,
            int max_value,
            Color out_of_range__low__color,
            Color out_of_range__high__color
            )
        {
            Bitmap image = new Bitmap(values_table.GetLength(0), values_table.GetLength(1));

            for (int x = 0; x < values_table.GetLength(0); x++)
            {
                for (int y = 0; y < values_table.GetLength(1); y++)
                {
                    double value = values_table[x, y];
                    if (value < min_value)
                    {
                        image.SetPixel(x, y, out_of_range__low__color);
                    }
                    else if (value > max_value)
                    {
                        image.SetPixel(x, y, out_of_range__high__color);
                    }
                    else
                    {
                        if (min_value == max_value)
                        {
                            Color c = Color.FromArgb(0, 0, 0);
                            image.SetPixel(x, y, c);
                        }
                        else
                        {
                            double cv = Math_Utilities.Map_Value(value, min_value, max_value, 0.0, 255.0);
                            int    ci = (int)cv;
                            Color  c  = Color.FromArgb(ci, ci, ci);
                            image.SetPixel(x, y, c);
                        }
                    }
                }
            }
            return(image);
        }
        public override MEL_Rastrigin__Individual Generate_Individual(Random randomness_provider)
        {
            List <double> genotype = new List <double>();

            for (int i = 0; i < num_dimensions; i++)
            {
                double this_gene_value = Math_Utilities.Map_Value(
                    randomness_provider.NextDouble(),
                    0.0,
                    1.0,
                    min_gene_value,
                    max_gene_value
                    );
                genotype.Add(this_gene_value);
            }

            MEL_Rastrigin__Individual individual = new MEL_Rastrigin__Individual(
                genotype
                );

            return(individual);
        }