# include "sandia_rules.hpp" # include "sgmga.hpp" # include # include # include # include int main ( ); void sgmga_aniso_balance_tests ( ); void sgmga_aniso_balance_test ( double alpha_max, int dim_num, double level_weight[] ); void sgmga_aniso_normalize_tests ( ); void sgmga_aniso_normalize_test ( int dim_num, double level_weight[] ); void sgmga_importance_to_aniso_tests ( ); void sgmga_importance_to_aniso_test ( int dim_num, double importance[], double level_weight[] ); //****************************************************************************80 int main ( ) //****************************************************************************80 // // Purpose: // // MAIN is the main program for SGMGA_ANISO_NORMALIZE_PRB. // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 03 February 2010 // // Author: // // John Burkardt // { webbur::timestamp ( ); std::cout << "\n"; std::cout << "SGMGA_ANISO_NORMALIZE_PRB:\n"; std::cout << " C++ version\n"; std::cout << " Test the SGMGA_ANISO_NORMALIZE and\n"; std::cout << " SGMGA_IMPORTANCE_TO_ANISO functions.\n"; sgmga_aniso_balance_tests ( ); sgmga_aniso_normalize_tests ( ); sgmga_importance_to_aniso_tests ( ); std::cout << "\n"; std::cout << "SGMGA_ANISO_NORMALIZE_PRB:\n"; std::cout << " Normal end of execution.\n"; std::cout << "\n"; webbur::timestamp ( ); return 0; } //****************************************************************************80 void sgmga_aniso_balance_tests ( ) //****************************************************************************80 // // Purpose: // // SGMGA_ANISO_BALANCE_TESTS call SGMGA_ANISO_BALANCE_TEST. // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 13 November 2009 // // Author: // // John Burkardt // { double alpha_max; int dim; int dim_num; double *level_weight; int seed; int test; int test_num; std::cout << "\n"; std::cout << "SGMGA_ANISO_BALANCE_TESTS\n"; std::cout << " Call SGMGA_ANISO_BALANCE_TEST with various arguments.\n"; test_num = 5; dim_num = 5; level_weight = new double[dim_num]; alpha_max = 10.0; seed = 123456789; for ( test = 1; test <= test_num; test++ ) { webbur::r8vec_uniform_01 ( dim_num, &seed, level_weight ); for ( dim = 0; dim < dim_num; dim++ ) { level_weight[dim] = 10.0 * level_weight[dim]; } sgmga_aniso_balance_test ( alpha_max, dim_num, level_weight ); } alpha_max = 5.0; seed = 123456789; for ( test = 1; test <= test_num; test++ ) { webbur::r8vec_uniform_01 ( dim_num, &seed, level_weight ); for ( dim = 0; dim < dim_num; dim++ ) { level_weight[dim] = 10.0 * level_weight[dim]; } sgmga_aniso_balance_test ( alpha_max, dim_num, level_weight ); } delete [] level_weight; return; } //****************************************************************************80 void sgmga_aniso_balance_test ( double alpha_max, int dim_num, double level_weight[] ) //****************************************************************************80 // // Purpose: // // SGMGA_ANISO_BALANCE_TEST calls SGMGA_ANISO_BALANCE. // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 03 February 2010 // // Author: // // John Burkardt // { int dim; double *level_weight2; std::cout << "\n"; std::cout << "SGMGA_ANISO_BALANCE_TEST\n"; std::cout << " ALPHA_MAX = " << alpha_max << "\n"; std::cout << " Input weight sum: " << webbur::r8vec_sum ( dim_num, level_weight ) << "\n"; for ( dim = 0; dim < dim_num; dim++ ) { std::cout << " " << std::setw(12) << level_weight[dim]; } std::cout << "\n"; level_weight2 = webbur::sgmga_aniso_balance ( alpha_max, dim_num, level_weight ); std::cout << " Output weight sum: " << webbur::r8vec_sum ( dim_num, level_weight2 ) << "\n"; for ( dim = 0; dim < dim_num; dim++ ) { std::cout << " " << std::setw(12) << level_weight2[dim]; } std::cout << "\n"; delete [] level_weight2; return; } //****************************************************************************80 void sgmga_aniso_normalize_tests ( ) //****************************************************************************80 // // Purpose: // // SGMGA_ANISO_NORMALIZE_TESTS call SGMGA_ANISO_NORMALIZE_TEST. // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 13 November 2009 // // Author: // // John Burkardt // { int dim_num; double *level_weight; std::cout << "\n"; std::cout << "SGMGA_ANISO_NORMALIZE_TESTS\n"; std::cout << " Call SGMGA_ANISO_NORMALIZE_TEST with various arguments.\n"; dim_num = 2; level_weight = new double[dim_num]; level_weight[0] = 1.0; level_weight[1] = 1.0; sgmga_aniso_normalize_test ( dim_num, level_weight ); delete [] level_weight; dim_num = 2; level_weight = new double[dim_num]; level_weight[0] = 10.0; level_weight[1] = 10.0; sgmga_aniso_normalize_test ( dim_num, level_weight ); delete [] level_weight; dim_num = 2; level_weight = new double[dim_num]; level_weight[0] = 10.0; level_weight[1] = 2.0; sgmga_aniso_normalize_test ( dim_num, level_weight ); delete [] level_weight; dim_num = 2; level_weight = new double[dim_num]; level_weight[0] = 1.0; level_weight[1] = 2.0; sgmga_aniso_normalize_test ( dim_num, level_weight ); delete [] level_weight; dim_num = 3; level_weight = new double[dim_num]; level_weight[0] = 1.0; level_weight[1] = 2.0; level_weight[2] = 3.0; sgmga_aniso_normalize_test ( dim_num, level_weight ); delete [] level_weight; // // Try a case in which one variable has 0 weight. // dim_num = 3; level_weight = new double[dim_num]; level_weight[0] = 2.0; level_weight[1] = 0.0; level_weight[2] = 1.5; sgmga_aniso_normalize_test ( dim_num, level_weight ); delete [] level_weight; dim_num = 4; level_weight = new double[dim_num]; level_weight[0] = 1.0; level_weight[1] = 2.0; level_weight[2] = 3.0; level_weight[3] = 4.0; sgmga_aniso_normalize_test ( dim_num, level_weight ); delete [] level_weight; return; } //****************************************************************************80 void sgmga_aniso_normalize_test ( int dim_num, double level_weight[] ) //****************************************************************************80 // // Purpose: // // SGMGA_ANISO_NORMALIZE_TEST calls SGMGA_ANISO_NORMALIZE. // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 27 November 2009 // // Author: // // John Burkardt // { int dim; int option; std::cout << "\n"; std::cout << "SGMGA_ANISO_NORMALIZE_TEST\n"; std::cout << " Input weight sum: " << webbur::r8vec_sum ( dim_num, level_weight ) << "\n"; for ( dim = 0; dim < dim_num; dim++ ) { std::cout << " " << std::setw(12) << level_weight[dim]; } std::cout << "\n"; for ( option = 0; option <= 2; option++ ) { webbur::sgmga_aniso_normalize ( option, dim_num, level_weight ); std::cout << " For OPTION = " << option << " Normalized weight sum: " << webbur::r8vec_sum ( dim_num, level_weight ) << "\n"; for ( dim = 0; dim < dim_num; dim++ ) { std::cout << " " << std::setw(12) << level_weight[dim]; } std::cout << "\n"; } return; } //****************************************************************************80 void sgmga_importance_to_aniso_tests ( ) //****************************************************************************80 // // Purpose: // // SGMGA_IMPORTANCE_TO_ANISO_TESTS call SGMGA_IMPORTANCE_TO_ANISO_TEST. // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 22 September 2009 // // Author: // // John Burkardt // { int dim_num; double *importance; double *level_weight; std::cout << "\n"; std::cout << "SGMGA_IMPORTANCE_TO_ANISO_TESTS\n"; std::cout << " Call SGMGA_IMPORTANCE_TO_ANISO_TEST with various arguments.\n"; dim_num = 2; importance = new double[dim_num]; level_weight = new double[dim_num]; importance[0] = 1.0; importance[1] = 1.0; sgmga_importance_to_aniso_test ( dim_num, importance, level_weight ); delete [] importance; delete [] level_weight; dim_num = 2; importance = new double[dim_num]; level_weight = new double[dim_num]; importance[0] = 10.0; importance[1] = 10.0; sgmga_importance_to_aniso_test ( dim_num, importance, level_weight ); delete [] importance; delete [] level_weight; dim_num = 2; importance = new double[dim_num]; level_weight = new double[dim_num]; importance[0] = 10.0; importance[1] = 2.0; sgmga_importance_to_aniso_test ( dim_num, importance, level_weight ); delete [] importance; delete [] level_weight; dim_num = 2; importance = new double[dim_num]; level_weight = new double[dim_num]; importance[0] = 1.0; importance[1] = 2.0; sgmga_importance_to_aniso_test ( dim_num, importance, level_weight ); delete [] importance; delete [] level_weight; dim_num = 3; importance = new double[dim_num]; level_weight = new double[dim_num]; importance[0] = 1.0; importance[1] = 2.0; importance[2] = 3.0; sgmga_importance_to_aniso_test ( dim_num, importance, level_weight ); delete [] importance; delete [] level_weight; // // Try a case in which one variable has 0 importance. // dim_num = 3; importance = new double[dim_num]; level_weight = new double[dim_num]; importance[0] = 2.0; importance[1] = 0.0; importance[2] = 1.5; sgmga_importance_to_aniso_test ( dim_num, importance, level_weight ); delete [] importance; delete [] level_weight; dim_num = 4; importance = new double[dim_num]; level_weight = new double[dim_num]; importance[0] = 1.0; importance[1] = 2.0; importance[2] = 3.0; importance[3] = 4.0; sgmga_importance_to_aniso_test ( dim_num, importance, level_weight ); delete [] importance; delete [] level_weight; return; } //****************************************************************************80 void sgmga_importance_to_aniso_test ( int dim_num, double importance[], double level_weight[] ) //****************************************************************************80 // // Purpose: // // SGMGA_IMPORTANCE_TO_ANISO_TEST calls SGMGA_IMPORTANCE_TO_ANISO. // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 27 November 2009 // // Author: // // John Burkardt // { int dim; std::cout << "\n"; std::cout << "SGMGA_IMPORTANCE_TO_ANISO_TEST\n"; std::cout << " Importances:\n"; for ( dim = 0; dim < dim_num; dim++ ) { std::cout << " " << std::setw(12) << importance[dim]; } std::cout << "\n"; webbur::sgmga_importance_to_aniso ( dim_num, importance, level_weight ); std::cout << " Anisotropic coefficients:\n"; for ( dim = 0; dim < dim_num; dim++ ) { std::cout << " " << std::setw(12) << level_weight[dim]; } std::cout << "\n"; return; }