int main(int argc, char *argv[]) { paracel::main_env comm_main_env(argc, argv); paracel::Comm comm(MPI_COMM_WORLD); google::SetUsageMessage("[options]\n\t--server_info\n\t--cfg_file\n"); google::ParseCommandLineFlags(&argc, &argv, true); paracel::json_parser pt(FLAGS_cfg_file); std::string rating_input = pt.check_parse<std::string>("rating_input"); std::string factor_input = pt.check_parse<std::string>("factor_input"); std::string validate_input = pt.check_parse<std::string>("validate_input"); std::string output = pt.parse<std::string>("output"); std::string pattern = pt.parse<std::string>("pattern"); double lambda = pt.parse<double>("lambda"); paracel::alg::alternating_least_square_standard H_solver(comm, FLAGS_server_info, rating_input, factor_input, validate_input, output, pattern, lambda); H_solver.solve(); H_solver.dump_result(); double train_err = H_solver.cal_rmse(); if(comm.get_rank() == 0) std::cout << "train error: " << train_err << std::endl; double test_err = H_solver.validate(); if(comm.get_rank() == 0) std::cout << "test error:" << test_err << std::endl; return 0; }
int main(int argc, char *argv[]) { paracel::main_env comm_main_env(argc, argv); paracel::Comm comm(MPI_COMM_WORLD); google::SetUsageMessage("[options]\n\t--server_info\n\t--cfg_file\n"); google::ParseCommandLineFlags(&argc, &argv, true); paracel::json_parser pt(FLAGS_cfg_file); std::string rating_input = pt.check_parse<std::string>("rating_input"); std::string factor_input = pt.check_parse<std::string>("factor_input"); std::string validate_input = pt.check_parse<std::string>("validate_input"); std::string output = pt.parse<std::string>("output"); std::string pattern = pt.parse<std::string>("pattern"); std::vector<double> lambdas = pt.parse_v<double>("lambdas"); // model selection { std::vector<double> validate_errs, train_errs; paracel::alg::alternating_least_square_validate H_solver(comm, FLAGS_server_info, rating_input, factor_input, validate_input, output, pattern); H_solver.init(); for(auto & lambda : lambdas) { H_solver.learning(lambda); train_errs.push_back(H_solver.cal_rmse()); validate_errs.push_back(H_solver.validate()); } if(comm.get_rank() == 0) { for(size_t i = 0; i < train_errs.size(); ++i) { std::cout << "###################################" << std::endl; std::cout << "lambda: " << lambdas[i] << std::endl; std::cout << "train error: " << train_errs[i] << std::endl; std::cout << "validate error: " << validate_errs[i] << std::endl; std::cout << "###################################" << std::endl; } } } return 0; }