-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathsvm_option.cpp
More file actions
executable file
·108 lines (100 loc) · 3.21 KB
/
svm_option.cpp
File metadata and controls
executable file
·108 lines (100 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/**
*******************************************************************************
*
* Copyright (c) 2015 Baidu.com, Inc. All Rights Reserved
*
*******************************************************************************
*
* @file: svm_option.cpp
* @author: mazefeng(mazefeng01@baidu.com)
* @date: 2015/06/30 11:10:00
*
*/
#include "svm_common.h"
#include "svm_option.h"
using std::cout;
using std::cerr;
using std::endl;
SVMOption::SVMOption(){
_c = SVM_OPTION_C;
_eps = SVM_OPTION_EPSILON;
_sig = SVM_OPTION_SIGMA;
_is_linear_kernel = false;
_fname_train[0] = '\0';
_fname_valid[0] = '\0';
_fname_model[0] = '\0';
_flags = 0;
}
SVMOption::~SVMOption(){}
void SVMOption::print(){
cerr <<
"#========================================================\n"
"# SVM Option: \n"
"#========================================================\n"
"# [c = " << _c << "]\n"
"# [epsilon = " << _eps << "]\n"
"# [sigma = " << _sig << "]\n"
"# [is_linear_kernel = " << _is_linear_kernel << "]\n"
"# [fname_train = " << _fname_train << "]\n"
"# [fname_model = " << _fname_model << "]\n"
"# [fname_valid = " << _fname_valid << "]\n"
"#========================================================\n"
<< endl;
}
int SVMOption::parse_command_line(int argc, char *argv[]){
int option;
const char *opt_string = "";
struct option long_opts[] = {
{"train", 1, NULL, 0},
{"model", 1, NULL, 1},
{"validate", 1, NULL, 2},
{"linear_kernel", 0, NULL, 3},
{"c", 1, NULL, 4},
{"epsilon", 1, NULL, 5},
{"sigma", 1, NULL, 6},
{"help", 0, NULL, 7},
{0, 0, 0, 0}
};
while ((option = getopt_long_only(argc, argv, opt_string, long_opts, NULL)) != -1){
switch (option) {
case 0:
_flags |= FLAG_TRAIN;
memcpy(_fname_train, optarg, strlen(optarg));
_fname_train[strlen(optarg)] = '\0';
break;
case 1:
_flags |= FLAG_MODEL;
memcpy(_fname_model, optarg, strlen(optarg));
_fname_model[strlen(optarg)] = '\0';
break;
case 2:
_flags |= FLAG_VALID;
memcpy(_fname_valid, optarg, strlen(optarg));
_fname_valid[strlen(optarg)] = '\0';
break;
case 3:
_flags |= FLAG_LINEAR_KERNEL;
_is_linear_kernel = true;
break;
case 4:
_flags |= FLAG_C;
_c = atof(optarg);
break;
case 5:
_flags |= FLAG_EPSILON;
_eps = atof(optarg);
break;
case 6:
_flags |= FLAG_SIGMA;
_sig = atof(optarg);
break;
case 7:
_flags |= FLAG_HELP;
break;
}
}
if (!(_flags & FLAG_TRAIN)) return FLAG_TRAIN;
if (!(_flags & FLAG_VALID)) return FLAG_VALID;
if (!(_flags & FLAG_MODEL)) return FLAG_MODEL;
return 0;
}