void thundersvm_predict_sub(DataSet& predict_dataset, CMDParser& parser, char* model_file_path, char* output_file_path){ fstream file; file.open(model_file_path, std::fstream::in); string feature, svm_type; file >> feature >> svm_type; CHECK_EQ(feature, "svm_type"); SvmModel *model = nullptr; Metric *metric = nullptr; if (svm_type == "c_svc") { model = new SVC(); metric = new Accuracy(); } else if (svm_type == "nu_svc") { model = new NuSVC(); metric = new Accuracy(); } else if (svm_type == "one_class") { model = new OneClassSVC(); //todo determine a metric } else if (svm_type == "epsilon_svr") { model = new SVR(); metric = new MSE(); } else if (svm_type == "nu_svr") { model = new NuSVR(); metric = new MSE(); } #ifdef USE_CUDA CUDA_CHECK(cudaSetDevice(parser.gpu_id)); #endif model->set_max_memory_size_Byte(parser.param_cmd.max_mem_size); model->load_from_file(model_file_path); file.close(); file.open(output_file_path, fstream::out); vector<float_type> predict_y; predict_y = model->predict(predict_dataset.instances(), -1); for (int i = 0; i < predict_y.size(); ++i) { file << predict_y[i] << std::endl; } file.close(); if (metric) { LOG(INFO) << metric->name() << " = " << metric->score(predict_y, predict_dataset.y()); } }
void thundersvm_predict_matlab(int argc, char **argv){ CMDParser parser; parser.parse_command_line(argc, argv); char model_file_path[1024] = DATASET_DIR; char predict_file_path[1024] = DATASET_DIR; char output_file_path[1024] = DATASET_DIR; strcat(model_file_path, parser.svmpredict_model_file_name); strcat(predict_file_path, parser.svmpredict_input_file); strcat(output_file_path, parser.svmpredict_output_file); std::fstream file; //FILE *fp; //fp = fopen("model_file_path", "rb"); file.open(model_file_path, std::fstream::in); string feature, svm_type; //char feature[20]; //char svm_type[20]; //fscanf(fp, "%s", feature); //fscanf(fp, "%s", svm_type); file >> feature >> svm_type; CHECK_EQ(feature, "svm_type"); SvmModel *model = nullptr; Metric *metric = nullptr; if (svm_type == "c_svc") { model = new SVC(); metric = new Accuracy(); } else if (svm_type == "nu_svc") { model = new NuSVC(); metric = new Accuracy(); } else if (svm_type == "one_class") { model = new OneClassSVC(); //todo determine a metric } else if (svm_type == "epsilon_svr") { model = new SVR(); metric = new MSE(); } else if (svm_type == "nu_svr") { model = new NuSVR(); metric = new MSE(); } #ifdef USE_CUDA CUDA_CHECK(cudaSetDevice(parser.gpu_id)); #endif model->load_from_file(model_file_path); //fclose(fp); file.close(); //fp = fopen("output_file_path", "wb"); file.open(output_file_path, std::fstream::out); DataSet predict_dataset; predict_dataset.load_from_file(predict_file_path); vector<float_type> predict_y; predict_y = model->predict(predict_dataset.instances(), 10000); for (int i = 0; i < predict_y.size(); ++i) { //fprintf(fp, "%s\n", predict_y[i]); file << predict_y[i] << std::endl; } //fclose(fp); file.close(); if (metric) { LOG(INFO) << metric->name() << " = " << metric->score(predict_y, predict_dataset.y()); } }