Beispiel #1
0
    private static void test03( )

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST03 tests the improved distributed hypercube sampling algorithm.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    10 April 2003
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        const int dim_num     = 2;
        const int duplication = 5;

        Console.WriteLine();
        Console.WriteLine("TEST03");
        Console.WriteLine("  IHS implements the IHS Algorithm");
        Console.WriteLine("  (Improved Distributed Hypercube Sampling)");
        Console.WriteLine();
        Console.WriteLine("  Demonstrate the code for a fixed dimension");
        Console.WriteLine("  and duplication value, and increasing number of points.");

        Console.WriteLine();
        Console.WriteLine("  Spatial dimension =        " + dim_num);
        Console.WriteLine("  Duplication factor =       " + duplication);

        int point_num = 5;

        for (int k = 1; k <= 5; k++)
        {
            point_num = 2 * point_num;

            double opt = point_num /
                         Math.Pow(point_num,
                                  1.0E+00 / dim_num);

            int seed = 17;

            Console.WriteLine();
            Console.WriteLine("  Random number seed =       " + seed);
            Console.WriteLine("  Number of points =         " + point_num);
            Console.WriteLine("  Desired minimum distance = " + opt);
            //
            //  Get the points.
            //
            int[] x = IHS.ihs(dim_num, point_num, duplication, ref seed);
            //
            //  Compute the covariance.
            //
            covariance c = new(dim_num, point_num, x);

            Console.WriteLine();
            Console.WriteLine("  Average minimum distance " + c.average);
            Console.WriteLine("  Standard deviation:      " + c.std);
            Console.WriteLine("  Covariance:              " + c.covc);

            Console.WriteLine();

            for (int j = 0; j < point_num; j++)
            {
                if (j <= 10 || point_num - 10 <= j)
                {
                    string t    = j + 1 + "    ";
                    string line = t.PadLeft(4);
                    for (int i = 0; i < dim_num; i++)
                    {
                        t     = x[i + j * dim_num] + "  ";
                        line += t.PadLeft(4);
                    }
                    Console.WriteLine(line);
                    Console.WriteLine();
                }
                else
                {
                    switch (j)
                    {
                    case 11:
                        Console.WriteLine("....    ........");
                        break;
                    }
                }
            }
        }
    }
Beispiel #2
0
    private static void test02()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST02 tests the improved distributed hypercube sampling algorithm.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    10 April 2003
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        const int dim_num   = 2;
        const int point_num = 10;

        Console.WriteLine();
        Console.WriteLine("TEST02");
        Console.WriteLine("  IHS implements the IHS Algorithm");
        Console.WriteLine("  (Improved Distributed Hypercube Sampling)");
        Console.WriteLine();
        Console.WriteLine("  Demonstrate the code for a fixed number of points");
        Console.WriteLine("  and dimension, but vary the duplication value.");

        double opt = point_num /
                     Math.Pow(point_num,
                              1.0E+00 / dim_num);

        Console.WriteLine();
        Console.WriteLine("  Spatial dimension =        " + dim_num);
        Console.WriteLine("  Number of points =         " + point_num);
        Console.WriteLine("  Desired minimum distance = " + opt);

        for (int duplication = 1; duplication <= 5; duplication++)
        {
            int seed = 17;

            Console.WriteLine();
            Console.WriteLine("  Random number seed =       " + seed);
            Console.WriteLine("  Duplication factor =       " + duplication);
            //
            //  Get the points.
            //
            int[] x = IHS.ihs(dim_num, point_num, duplication, ref seed);
            //
            //  Compute the covariance.
            //
            covariance c = new(dim_num, point_num, x);

            Console.WriteLine();
            Console.WriteLine("  Average minimum distance " + c.average);
            Console.WriteLine("  Standard deviation:      " + c.std);
            Console.WriteLine("  Covariance:              " + c.covc);

            typeMethods.i4mat_transpose_print(dim_num, point_num, x, "  X:");
        }
    }
Beispiel #3
0
    private static void Main()
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    MAIN is the main program for IHS_DATASET.
    //
    //  Discussion:
    //
    //    IHS_DATASET generates an IHS dataset and writes it to a file.
    //
    //    This program is meant to be used interactively.  It's also
    //    possible to prepare a simple input file beforehand and use it
    //    in batch mode.
    //
    //    The program requests input values from the user:
    //
    //    * M, the spatial dimension,
    //    * N, the number of points to generate,
    //    * D, the duplication factor,
    //    * SEED, a seed for the random number generator.
    //
    //    The program generates the data, writes it to the file
    //
    //      ihs_M_N_D_SEED.txt
    //
    //    where "M" and "N" are the numeric values specified by the user,
    //    and then asks the user for more input.   To indicate that no further
    //    computations are desired, it is enough to input a nonsensical
    //    value, such as -1.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    12 April 2007
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        string output_filename = "";

        //
        //  Print introduction and options.
        //

        Console.WriteLine("");
        Console.WriteLine("IHS_DATASET");

        Console.WriteLine("  Generate an IHS dataset.");
        Console.WriteLine("");
        Console.WriteLine("  This program is meant to be used interactively.");
        Console.WriteLine("  It is also possible to prepare a simple input");
        Console.WriteLine("  file beforehand and use it in batch mode.");
        Console.WriteLine("");
        Console.WriteLine("  The program requests input values from the user:"******"");
        Console.WriteLine("  * M, the spatial dimension,");
        Console.WriteLine("  * N, the number of points to generate,");
        Console.WriteLine("  * D, the duplication factor,");
        Console.WriteLine("  * SEED, a seed for the random number generator.");
        Console.WriteLine("");
        Console.WriteLine("  The program generates the data, writes it to the file");
        Console.WriteLine("");
        Console.WriteLine("    ihs_M_N_D_SEED.txt");
        Console.WriteLine("");
        Console.WriteLine("  where \"M\" and \"N\" are the numeric values specified");
        Console.WriteLine("  by the user, and then asks the user for more input.");
        Console.WriteLine("");
        Console.WriteLine("  To indicate that no further computations are");
        Console.WriteLine("  desired, it is enough to input a nonsensical value,");
        Console.WriteLine("  such as -1.");

        for (;;)
        {
            Console.WriteLine("  *");
            Console.WriteLine(" *");
            Console.WriteLine("*  Ready to generate a new dataset:");
            Console.WriteLine(" *");
            Console.WriteLine("  *");
            Console.WriteLine("  Enter M, the spatial dimension:");
            Console.WriteLine("  (2 is a small typical value).");
            Console.WriteLine("  (0 or any negative value terminates execution).");

            int m;
            try
            {
                m = Convert.ToInt32(Console.ReadLine());
            }
            catch (Exception)
            {
                Console.WriteLine("");
                Console.WriteLine("IHS_DATASET - Fatal error!");
                Console.WriteLine("  An I/O error occurred while trying to read M.");
                Console.WriteLine("  Abnormal end of execution.");
                return;
            }

            Console.WriteLine("  User input M = " + m + "");

            switch (m)
            {
            case < 1:
                Console.WriteLine("");
                Console.WriteLine("IHS_DATASET");
                Console.WriteLine("  The input value of M = " + m + "");
                Console.WriteLine("  is interpreted as a request for termination.");
                Console.WriteLine("  Normal end of execution.");
                return;
            }

            Console.WriteLine("");
            Console.WriteLine("  Enter N, the number of points to generate:");
            Console.WriteLine("  (10 is a small typical value).");
            Console.WriteLine("  (0 or any negative value terminates execution).");

            int n;
            try
            {
                n = Convert.ToInt32(Console.ReadLine());
            }
            catch (Exception)
            {
                Console.WriteLine("");
                Console.WriteLine("IHS_DATASET - Fatal error!");
                Console.WriteLine("  An I/O error occurred while trying to read N.");
                Console.WriteLine("  Abnormal end of execution.");
                break;
            }

            Console.WriteLine("  User input N = " + n + "");

            switch (n)
            {
            case < 1:
                Console.WriteLine("");
                Console.WriteLine("IHS_DATASET");
                Console.WriteLine("  The input value of N = " + n + "");
                Console.WriteLine("  is interpreted as a request for termination.");
                Console.WriteLine("  Normal end of execution.");
                return;
            }


            Console.WriteLine("");
            Console.WriteLine("  Enter D, the duplication factor:");
            Console.WriteLine("  This must be at least 1, but not too large.");
            Console.WriteLine("  (5 is a typical value).");
            Console.WriteLine("  (0 or any negative value terminates execution).");

            int d;
            try
            {
                d = Convert.ToInt32(Console.ReadLine());
            }
            catch (Exception)
            {
                Console.WriteLine("");
                Console.WriteLine("IHS_DATASET - Fatal error!");
                Console.WriteLine("  An I/O error occurred while trying to read D.");
                Console.WriteLine("  Abnormal end of execution.");
                return;
            }

            Console.WriteLine("  User input D = " + d + "");

            if (d < 1)
            {
                Console.WriteLine("");
                Console.WriteLine("IHS_DATASET");
                Console.WriteLine("  The input value of D = " + d + "");
                Console.WriteLine("  is interpreted as a request for termination.");
                Console.WriteLine("  Normal end of execution.");
                break;
            }

            Console.WriteLine("");
            Console.WriteLine("  Enter SEED, a seed for the random number generator:");
            Console.WriteLine("  (Try '123456789' if you have no preference.)");
            Console.WriteLine("  (0 indicates you want a seed to be chosen for you.)");
            Console.WriteLine("  (Any negative value terminates execution).");

            int seed;
            try
            {
                seed = Convert.ToInt32(Console.ReadLine());
            }
            catch (Exception)
            {
                Console.WriteLine("");
                Console.WriteLine("IHS_DATASET - Fatal error!");
                Console.WriteLine("  An I/O error occurred while trying to read SEED.");
                Console.WriteLine("  Abnormal end of execution.");
                return;
            }

            Console.WriteLine("  User input SEED = " + seed + "");

            switch (seed)
            {
            case < 0:
                Console.WriteLine("");
                Console.WriteLine("IHS_DATASET");
                Console.WriteLine("  The input value of SEED = " + seed + "");
                Console.WriteLine("  is interpreted as a request for termination.");
                Console.WriteLine("  Normal end of execution.");
                return;

            case 0:
                seed = entropyRNG.RNG.nextint();
                Console.WriteLine("");
                Console.WriteLine("  The actual value of SEED will be = " + seed + "");
                break;
            }

            //
            //  Compute the integer data.
            //
            int   seed_init = seed;
            int[] i4_ihs    = IHS.ihs(m, n, d, ref seed);
            //
            //  Convert from integer to real.
            //
            double[] r8_ihs = new double[m * n];
            int      j;
            for (j = 0; j < n; j++)
            {
                int i;
                for (i = 0; i < m; i++)
                {
                    r8_ihs[i + j * m] = (2 * i4_ihs[i + j * m] - 1)
                                        / (double)(2 * n);
                }
            }

            //
            //  Write the data to a file.
            //
            output_filename += "ihs_"
                               + m + "_"
                               + n + "_"
                               + d + "_"
                               + seed_init + ".txt";

            typeMethods.r8mat_write(output_filename, m, n, r8_ihs);

            Console.WriteLine("");
            Console.WriteLine("  The data was written to the file \""
                              + output_filename + "\"");
        }

        Console.WriteLine("");
    }