Пример #1
0
    private static void test01()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST01 tests COMB by generating all 3-subsets of a 5 set.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    01 April 2016
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        const int k = 3;
        int       l;
        const int n = 5;

        int lmax = FullertonLib.i4_binom(n, k);

        Console.WriteLine("");
        Console.WriteLine("TEST01");
        Console.WriteLine("  Generate all K-subsets of an N set.");
        Console.WriteLine("  K = " + k + "");
        Console.WriteLine("  N = " + n + "");
        Console.WriteLine("  LMAX =" + lmax + "");

        if (!typeMethods.i4_choose_check(n, k))
        {
            Console.WriteLine("");
            Console.WriteLine("TEST01 - Warning!");
            Console.WriteLine("  The binomial coefficient cannot be");
            Console.WriteLine("  computed in integer arithmetic for");
            Console.WriteLine("  this choice of parameters.");
            return;
        }

        Console.WriteLine("");

        for (l = 1; l <= lmax; l++)
        {
            int[]  c    = Comb.comb(n, k, l);
            string cout = "  " + l.ToString().PadLeft(4) + ":  ";
            int    i;
            for (i = 0; i < k; i++)
            {
                cout += "  " + c[i].ToString().PadLeft(4);
            }

            Console.WriteLine(cout);
        }
    }
Пример #2
0
    public static CorrelationResult correlation_besselj(FullertonLib.BesselData globaldata, FullertonLib.r8BESJ0Data data, int n, double[] rho, double rho0)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    CORRELATION_BESSELJ evaluates the Bessel J correlation function.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    11 November 2012
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Reference:
    //
    //    Petter Abrahamsen,
    //    A Review of Gaussian Random Fields and Correlation Functions,
    //    Norwegian Computing Center, 1997.
    //
    //  Parameters:
    //
    //    Input, int N, the number of arguments.
    //
    //    Input, double RHO[N], the arguments.
    //
    //    Input, double RHO0, the correlation length.
    //
    //    Output, double C[N], the correlations.
    //
    {
        int i;

        double[] c = new double[n];

        for (i = 0; i < n; i++)
        {
            double rhohat = Math.Abs(rho[i]) / rho0;
            c[i] = FullertonLib.r8_besj0(ref globaldata, ref data, rhohat);
        }

        CorrelationResult result = new() { result = c, data = globaldata, j0data = data };

        return(result);
    }
Пример #3
0
    private static void test05()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST05 tests COMB by generating 10 random 10-subsets of a 100 set.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    01 April 2016
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int       j;
        const int k = 10;
        const int n = 100;

        int lmax = FullertonLib.i4_binom(n, k);

        Console.WriteLine("");
        Console.WriteLine("TEST05");
        Console.WriteLine("  Generate 10 random K-subsets of an N set.");
        Console.WriteLine("  K = " + k + "");
        Console.WriteLine("  N = " + n + "");
        Console.WriteLine("  LMAX =" + lmax + "");
        Console.WriteLine("");
        Console.WriteLine("  Note that this function is already");
        Console.WriteLine("  failing because LMAX is negative.");
        Console.WriteLine("  The combinatorial coefficient C(100,10)");
        Console.WriteLine("  is too large to store in an integer.");
        Console.WriteLine("");
        Console.WriteLine("  Although the program continues to give");
        Console.WriteLine("  results, they cannot be relied on.");

        if (!typeMethods.i4_choose_check(n, k))
        {
            Console.WriteLine("");
            Console.WriteLine("TEST05 - Warning!");
            Console.WriteLine("  The binomial coefficient cannot be");
            Console.WriteLine("  computed in integer arithmetic for");
            Console.WriteLine("  this choice of parameters.");
            return;
        }

        Console.WriteLine("");

        int seed = 123456789;

        for (j = 1; j <= 10; j++)
        {
            int    l    = UniformRNG.i4_uniform_ab(1, lmax, ref seed);
            int[]  c    = Comb.comb(n, k, l);
            string cout = "  " + l.ToString().PadLeft(4) + ":  ";
            int    i;
            for (i = 0; i < k; i++)
            {
                cout += "  " + c[i].ToString().PadLeft(4);
            }

            Console.WriteLine(cout);
        }
    }
Пример #4
0
    private static void test04()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST04 tests COMB by generating 10 random 3-subsets of a 100 set.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    01 April 2016
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int       j;
        const int k = 3;
        const int n = 100;

        int lmax = FullertonLib.i4_binom(n, k);

        Console.WriteLine("");
        Console.WriteLine("TEST04");
        Console.WriteLine("  Generate 10 random K-subsets of an N set.");
        Console.WriteLine("  K = " + k + "");
        Console.WriteLine("  N = " + n + "");
        Console.WriteLine("  LMAX =" + lmax + "");

        if (!typeMethods.i4_choose_check(n, k))
        {
            Console.WriteLine("");
            Console.WriteLine("TEST04 - Warning!");
            Console.WriteLine("  The binomial coefficient cannot be");
            Console.WriteLine("  computed in integer arithmetic for");
            Console.WriteLine("  this choice of parameters.");
            return;
        }

        Console.WriteLine("");

        int seed = 123456789;

        for (j = 1; j <= 10; j++)
        {
            int    l    = UniformRNG.i4_uniform_ab(1, lmax, ref seed);
            int[]  c    = Comb.comb(n, k, l);
            string cout = "  " + l.ToString().PadLeft(4) + ":  ";
            int    i;
            for (i = 0; i < k; i++)
            {
                cout += "  " + c[i].ToString().PadLeft(4);
            }

            Console.WriteLine(cout);
        }
    }
Пример #5
0
    public static CorrelationResult correlation_matern(FullertonLib.BesselData globaldata, FullertonLib.r8BESKData data, int n, double[] rho, double rho0)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    CORRELATION_MATERN evaluates the Matern correlation function.
    //
    //  Discussion:
    //
    //    In order to call this routine under a dummy name, I had to drop NU from
    //    the parameter list.
    //
    //    The Matern correlation is
    //
    //      rho1 = 2 * sqrt ( nu ) * rho / rho0
    //
    //      c(rho) = ( rho1 )^nu * BesselK ( nu, rho1 )
    //               / gamma ( nu ) / 2 ^ ( nu - 1 )
    //
    //    The Matern covariance has the form:
    //
    //      K(rho) = sigma^2 * c(rho)
    //
    //    A Gaussian process with Matern covariance has sample paths that are
    //    differentiable (nu - 1) times.
    //
    //    When nu = 0.5, the Matern covariance is the exponential covariance.
    //
    //    As nu goes to +oo, the correlation converges to exp ( - (rho/rho0)^2 ).
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    03 November 2012
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, int N, the number of arguments.
    //
    //    Input, double RHO[N], the arguments.
    //    0.0 <= RHO.
    //
    //    Input, double RHO0, the correlation length.
    //    0.0 < RHO0.
    //
    //    Output, double C[N], the correlations.
    //
    {
        int i;

        const double nu = 2.5;

        double[] c = new double[n];

        for (i = 0; i < n; i++)
        {
            double rho1 = 2.0 * Math.Sqrt(nu) * Math.Abs(rho[i]) / rho0;

            c[i] = rho1 switch
            {
                0.0 => 1.0,
                _ => Math.Pow(rho1, nu) * FullertonLib.r8_besk(ref globaldata, ref data, nu, rho1) / r8_gamma(nu) /
                Math.Pow(2.0, nu - 1.0)
            };
        }
        return(new CorrelationResult {
            result = c, data = globaldata, kdata = data
        });
    }
}