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 + ""); }
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:"); }