MCPcopy Create free account
hub / github.com/Xtra-Computing/thundersvm / main

Function main

src/thundersvm/thundersvm-predict.cpp:18–106  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16using std::fstream;
17
18int main(int argc, char **argv) {
19 try {
20 CMDParser parser;
21 parser.parse_command_line(argc, argv);
22 fstream file;
23 file.open(parser.svmpredict_model_file_name, fstream::in);
24 if(!file.is_open()){
25 LOG(INFO)<<"file "<<parser.svmpredict_model_file_name<<" not found";
26 exit(1);
27 }
28 //CHECK(file.is_open())<<"file "<<parser.svmpredict_model_file_name<<" not found";
29 string feature, svm_type;
30 file >> feature >> svm_type;
31 CHECK_EQ(feature, "svm_type");
32 std::shared_ptr<SvmModel> model;
33 std::shared_ptr<Metric> metric;
34 if (svm_type == "c_svc") {
35 model.reset(new SVC());
36 metric.reset(new Accuracy());
37 } else if (svm_type == "nu_svc") {
38 model.reset(new NuSVC());
39 metric.reset(new Accuracy());
40 } else if (svm_type == "one_class") {
41 model.reset(new OneClassSVC());
42 //todo determine a metric
43 } else if (svm_type == "epsilon_svr") {
44 model.reset(new SVR());
45 metric.reset(new MSE());
46 } else if (svm_type == "nu_svr") {
47 model.reset(new NuSVR());
48 metric.reset(new MSE());
49 }
50
51#ifdef USE_CUDA
52 CUDA_CHECK(cudaSetDevice(parser.gpu_id));
53#endif
54
55 model->set_max_memory_size_Byte(parser.param_cmd.max_mem_size);
56 model->load_from_file(parser.svmpredict_model_file_name);
57 file.close();
58 file.open(parser.svmpredict_output_file, fstream::out);
59 DataSet predict_dataset;
60 predict_dataset.load_from_file(parser.svmpredict_input_file);
61
62 vector<float_type> predict_y;
63 predict_y = model->predict(predict_dataset.instances(), -1);
64
65 if(model->is_prob() == 1) {
66 vector<int> label;
67 label = model->get_label();
68 vector<float> prob_predict;
69 prob_predict = model->get_prob_predict();
70 file << "labels ";
71 for (int i = 0; i < label.size(); i++) {
72 file << label[i] << " ";
73 }
74 file << std::endl;
75 for (int i = 0; i < predict_y.size(); i++) {

Callers

nothing calls this directly

Calls 9

parse_command_lineMethod · 0.80
instancesMethod · 0.80
is_probMethod · 0.80
nameMethod · 0.80
scoreMethod · 0.80
load_from_fileMethod · 0.45
predictMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected