int main(){ Gaussian_cdf normal_cdf(0,1); typedef Non_param_cdf<> non_parametric_cdf; std::vector<double> uniform_values; non_parametric_cdf from; for(int i=1; i<=1000; i++) uniform_values.push_back( uniform_random() ); std::vector<double> tmp(uniform_values); // add two extreme values tmp.push_back(-4.0); tmp.push_back(4.0); build_cdf(tmp.begin(), tmp.end(), from, 100); // don't transform the extremes of the data set tmp cdf_transform(tmp.begin()+1, tmp.end()-1, from, normal_cdf); // second method std::vector<double> tmp2(uniform_values); uniform_cdf reference_cdf; cdf_transform(tmp2.begin(), tmp2.end(), reference_cdf, normal_cdf); std::cout << "transform\n3\nunif\nnormal1\nnormal2" << std::endl; for(int i=1; i<=1000; i++) std::cout << uniform_values[i-1] << " " << tmp[i-1] << " " << tmp2[i-1] << std::endl; }
int main() { std::cout << "____________________________________" << std::endl << " Testing transformations from cdf to pdf and inversely" <<std::endl; int zval[5] = {1,2,3,4,5}; double prob[5] = {0.2, 0.3, 0.6, 0.8, 1}; typedef Non_param_pdf<int> Pdf; typedef Categ_non_param_cdf<int> Cdf; Cdf categ_cdf( 5, prob); Pdf pdf(zval, zval+5); cdf_to_pdf(pdf, categ_cdf); for(int i=0; i<=4; i++) std::cout << pdf.prob(i) << " " ; std::cout << std::endl; Cdf back(5); pdf_to_cdf(back,pdf); for(int i=0; i<=4; i++) std::cout << back.prob(i) << " " ; std::cout << std::endl; cdf_to_pdf(pdf, back); for(int i=0; i<=4; i++) std::cout << pdf.prob(i) << " " ; std::cout << std::endl; Pdf new_pdf(categ_cdf); for(int i=0; i<=4; i++) std::cout << new_pdf.prob(i) << " " ; std::cout << std::endl; std::cout << std::endl << "____________________________________" << std::endl << " Testing transformations from cdf to pdf and inversely "<<std::endl; Gaussian_cdf normal(0,1); std::vector<double> range(1000); for(std::vector<double>::iterator it=range.begin(); it!=range.end(); it++) *it = drand48()*100; std::ofstream out1( "uniform.dbg" ); std::copy( range.begin(), range.end(), std::ostream_iterator<double>( out1, "\n" ) ); cdf_transform(range.begin(), range.end(), normal); std::ofstream out2( "nscore.dbg" ); std::copy( range.begin(), range.end(), std::ostream_iterator<double>( out2, "\n" ) ); std::cout << std::endl << "____________________________________" << std::endl << " Testing cdf correction "<<std::endl; double order_relation[5] = {0.2, 0.3, -0.2, 0.1, 1.2}; Cdf bad_cdf(5, order_relation); std::cout << "Is bad cdf ok? " << is_valid_cdf(bad_cdf) << std::endl; make_cdf_valid(bad_cdf); std::cout << "Corrected cdf: " << std::endl; for(int i=0; i<bad_cdf.size(); i++) std::cout << bad_cdf.prob(i) << " " ; std::cout << std::endl; std::cout << std::endl << "____________________________________" << std::endl << " Testing cdf construction "<<std::endl; double val_range[9] = {1,1,1,4,7,12,31,55,60}; double z_values[7] = {1,4,7,12,31,55,60}; Non_param_cdf<> new_cdf( z_values, z_values+7); build_cdf( val_range, val_range+9, new_cdf.z_begin(), new_cdf.z_end(), new_cdf.p_begin() ); Non_param_cdf<>::z_iterator z_it = new_cdf.z_begin(); for( ; z_it != new_cdf.z_end(); z_it++ ) { std::cout << "P( " << *z_it << " ) = " << new_cdf.prob( *z_it ) << std::endl; } std::cout << std::endl; build_cdf( val_range, val_range+9, new_cdf, true ); z_it = new_cdf.z_begin(); for( ; z_it != new_cdf.z_end(); z_it++ ) { std::cout << "P( " << *z_it << " ) = " << new_cdf.prob( *z_it ) << std::endl; } }
int main(int argc, char *argv[]) { for ( int i = 0; i < argc; i++ ) { std::string v(argv[i]); size_t split_pos = v.find('='); if ( split_pos == -1 ) { g_cmd_args.insert(std::make_pair(v, "")); } else { std::pair<string, string> ap = std::make_pair(v.substr(0, split_pos), v.substr(split_pos+1, v.size())); g_cmd_args.insert(ap); //printf("%s = %s\n", ap.first.c_str(), ap.second.c_str()); } } // global args if ( !g_cmd_args["-log"].empty() ) { s_process_log = g_cmd_args["-log"]; } if ( !g_cmd_args["-logpath"].empty() ) { s_log_path = g_cmd_args["-logpath"]; } if ( !g_cmd_args["-hashsuffix"].empty() ) { s_hash_suffix = g_cmd_args["-hashsuffix"]; } if ( !g_cmd_args["-cdfsuffix"].empty() ) { s_cdf_suffix = g_cmd_args["-cdfsuffix"]; } // help if ( argc < 2 || strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0 ) { print_help(); } // build else if ( strcmp(argv[1], "--build") == 0 || strcmp(argv[1], "-b") == 0 ) { string input_path = g_cmd_args["-i"]; if ( input_path.empty() ) { error_msg("-i input path can't be null!"); } string output_path = g_cmd_args["-o"]; if ( output_path.empty() ) { error_msg("-o output path can't be null!"); } bool compress = g_cmd_args.find("-z") != g_cmd_args.end(); int compress_level = -1; if ( !g_cmd_args["-z"].empty() ) { compress_level = CUtils::atoi(g_cmd_args["-z"].c_str()); } if ( s_process_log.empty() ) { s_process_log = s_build_process_log; } build_cells(input_path, output_path, compress, compress_level); } // cdf else if ( strcmp(argv[1], "--cdf") == 0 || strcmp(argv[1], "-c") == 0 ) { string input_path = g_cmd_args["-i"]; if ( input_path.empty() ) { error_msg("-i input path can't be null!"); } string output_path = g_cmd_args["-o"]; if ( output_path.empty() ) { error_msg("-o output path can't be null!"); } bool compress = g_cmd_args.find("-z") != g_cmd_args.end(); int compress_level = -1; if ( !g_cmd_args["-z"].empty() ) { compress_level = CUtils::atoi(g_cmd_args["-z"].c_str()); } if ( !g_cmd_args["-cdfidx"].empty() ) { s_cdf_input_idxfile = g_cmd_args["-cdfidx"]; } if ( !g_cmd_args["-freecdf"].empty() ) { s_freefiles_cdf_name = g_cmd_args["-freecdf"]; } if ( s_process_log.empty() ) { s_process_log = s_cdf_process_log; } build_cdf(input_path, output_path, compress, compress_level); } // version else if ( strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-v") == 0 ) { string input_path1 = g_cmd_args["-io"]; if ( input_path1.empty() ) { error_msg("-io old version path can't be null!"); } string input_path2 = g_cmd_args["-in"]; if ( input_path2.empty() ) { error_msg("-in new version path can't be null!"); } string output_path = g_cmd_args["-o"]; if ( output_path.empty() ) { error_msg("-o patch output path can't be null!"); } if ( s_process_log.empty() ) { s_process_log = s_version_process_log; } build_version_patch(input_path1, input_path2, output_path); } else { error_msg("invalid command!"); } return 0; }