Beispiel #1
0
    private static void wishart_test03()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    WISHART_TEST03 compares the unit Wishart and Bartlett sample matrices.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    02 August 2013
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        Console.WriteLine("");
        Console.WriteLine("WISHART_TEST03:");
        Console.WriteLine("  Verify that, if using the same set of random numbers,");
        Console.WriteLine("    W = T' * T,");
        Console.WriteLine("  where");
        Console.WriteLine("    W = Wishart.wishart_unit_sample ( n, df );");
        Console.WriteLine("    T = Bartlett.bartlett_unit_sample ( n, df );");
        //
        //   Set the parameters.
        //
        int n  = 5;
        int df = 8;

        double[] w = Wishart.wishart_unit_sample(n, df);
        double[] t = Bartlett.bartlett_unit_sample(n, df);
        //
        //   Compute T' * T.
        //
        double[] tt = typeMethods.r8mat_mtm_new(n, n, n, t, t);
        //
        //   Compare T'T to W.
        //
        double diff = typeMethods.r8mat_norm_fro_affine(n, n, w, tt);

        Console.WriteLine("");
        Console.WriteLine("  Frobenius norm of error is " + diff + "");
    }
Beispiel #2
0
    private static void wishart_test06()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    WISHART_TEST06 compares the Wishart and Bartlett sample matrices.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    02 August 2013
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        //
        //  Note that R is an upper triangular matrix,
        //  whose entries here are listed in column major order.
        //
        double[] r =
        {
            5.0, 0.0, 0.0,
            1.0, 4.0, 0.0,
            3.0, 2.0, 6.0
        }

        ;

        Console.WriteLine("");
        Console.WriteLine("WISHART_TEST06:");
        Console.WriteLine("  Verify that, if using the same set of random numbers,");
        Console.WriteLine("    W = T'' * T,");
        Console.WriteLine("  where");
        Console.WriteLine("    W = Wishart.wishart_sample ( n, df, sigma );");
        Console.WriteLine("    T = Bartlett.bartlett_sample ( n, df, sigma );");
        //
        //   Set the parameters.
        //
        int n  = 3;
        int df = 5;

        double[] sigma = typeMethods.r8mat_mtm_new(n, n, n, r, r);
        typeMethods.r8mat_print(n, n, sigma, "  Covariance SIGMA:");
        //
        //   Initialize the random number package and compute W.
        //
        double[] w = Wishart.wishart_sample(n, df, sigma);
        //
        //   Initialize the random number package again, and compute T.
        //
        double[] t = Bartlett.bartlett_sample(n, df, sigma);
        //
        //   Compute T' * T.
        //
        double[] tt = typeMethods.r8mat_mtm_new(n, n, n, t, t);
        //
        //   Compare T'T to W.
        //
        double diff = typeMethods.r8mat_norm_fro_affine(n, n, w, tt);

        Console.WriteLine("");
        Console.WriteLine("  Frobenius norm of error is " + diff + "");
    }
Beispiel #3
0
    private static void wishart_test05()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    WISHART_TEST05 demonstrates the Bartlett sampling function.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    02 August 2013
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int it_num = 0;

        //
        //  Note that R is an upper triangular matrix,
        //  whose entries here are listed in column major order.
        //
        double[] r =
        {
            5.0, 0.0, 0.0,
            1.0, 4.0, 0.0,
            3.0, 2.0, 6.0
        }

        ;
        int rot_num = 0;

        double[] sigma_diag =
        {
            1.0, 2.0, 3.0, 4.0, 5.0
        }

        ;

        Console.WriteLine("");
        Console.WriteLine("WISHART_TEST05:");
        Console.WriteLine("  We can compute sample Bartlett matrices by:");
        Console.WriteLine("    T = Bartlett.bartlett_sample ( n, df, sigma );");
        //
        //   Set the parameters and call.
        //
        int n  = 5;
        int df = 8;

        double[] sigma = typeMethods.r8mat_identity_new(n);
        double[] t     = Bartlett.bartlett_sample(n, df, sigma);
        typeMethods.r8mat_print(n, n, t, "  Bartlett.bartlett_sample ( 5, 8, Identity ):");
        //
        //   Calling again yields a new matrix.
        //
        t = Bartlett.bartlett_sample(n, df, sigma);
        typeMethods.r8mat_print(n, n, t, "  Bartlett.bartlett_sample ( 5, 8, Identity ):");
        //
        //   Try a diagonal matrix.
        //
        sigma = typeMethods.r8mat_diagonal_new(n, sigma_diag);
        t     = Bartlett.bartlett_sample(n, df, sigma);
        typeMethods.r8mat_print(n, n, t, "  Bartlett.bartlett_sample ( 5, 8, diag(1,2,3,4,5) ):");
        //
        //   Try a smaller matrix.
        //
        n     = 3;
        df    = 3;
        sigma = typeMethods.r8mat_mtm_new(n, n, n, r, r);
        typeMethods.r8mat_print(n, n, sigma, "  Set covariance SIGMA:");
        t = Bartlett.bartlett_sample(n, df, sigma);
        typeMethods.r8mat_print(n, n, t, "  Bartlett.bartlett_sample ( 3, 3, sigma ):");
        //
        //   What is the eigendecomposition of T' * T?
        //
        double[] w      = typeMethods.r8mat_mtm_new(n, n, n, t, t);
        int      it_max = 50;

        double[] v      = new double[n * n];
        double[] lambda = new double[n];

        Jacobi.jacobi_eigenvalue(n, w, it_max, ref v, ref lambda, ref it_num, ref rot_num);
        typeMethods.r8mat_print(n, n, v, "  Eigenvectors of previous matrix:");
        typeMethods.r8vec_print(n, lambda, "  Eigenvalues of previous matrix:");
    }
Beispiel #4
0
    private static void bartlett_unit_sample_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    BARTLETT_UNIT_SAMPLE_TEST demonstrates the unit Bartlett sampling function.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    02 August 2013
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int it_num  = 0;
        int rot_num = 0;

        Console.WriteLine("");
        Console.WriteLine("BARTLETT_UNIT_SAMPLE_TEST:");
        Console.WriteLine("  BARTLETT_UNIT_SAMPLE samples unit Bartlett matrices by:");
        Console.WriteLine("  T = Bartlett.bartlett_unit_sample ( n, df );");
        //
        //   Set the parameters and call.
        //
        int n  = 5;
        int df = 8;

        double[] t = Bartlett.bartlett_unit_sample(n, df);
        typeMethods.r8mat_print(n, n, t, "  Bartlett.bartlett_unit_sample ( 5, 8 ):");
        //
        //   Calling again yields a new matrix.
        //
        t = Bartlett.bartlett_unit_sample(n, df);
        typeMethods.r8mat_print(n, n, t, "  Bartlett.bartlett_unit_sample ( 5, 8 ):");
        //
        //   Reduce DF.
        //
        n  = 5;
        df = 5;
        t  = Bartlett.bartlett_unit_sample(n, df);
        typeMethods.r8mat_print(n, n, t, "  Bartlett.bartlett_unit_sample ( 5, 5 ):");
        //
        //   Try a smaller matrix.
        //
        n  = 3;
        df = 5;
        t  = Bartlett.bartlett_unit_sample(n, df);
        typeMethods.r8mat_print(n, n, t, "  Bartlett.bartlett_unit_sample ( 3, 5 ):");
        //
        //   What is the eigendecomposition of the matrix T' * T?
        //
        double[] w = typeMethods.r8mat_mtm_new(n, n, n, t, t);

        int it_max = 50;

        double[] v      = new double[n * n];
        double[] lambda = new double[n];

        Jacobi.jacobi_eigenvalue(n, w, it_max, ref v, ref lambda, ref it_num, ref rot_num);
        typeMethods.r8mat_print(n, n, v, "  Eigenvectors of previous matrix:");
        typeMethods.r8vec_print(n, lambda, "  Eigenvalues of previous matrix:");
    }