-
Notifications
You must be signed in to change notification settings - Fork 0
/
lr_classify.cpp
75 lines (68 loc) · 2 KB
/
lr_classify.cpp
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
/********************************************************************
* Logit Model (Softmax Regression) V0.20
* Implemented by Rui Xia([email protected])
* Last updated on 2013-05-04.
*********************************************************************/
#include <cstdlib>
#include <iostream>
#include <cstring>
#include "LR.h"
using namespace std;
void print_help()
{
cout << "\nOpenPR-LR classification module, " << VERSION << ", " << VERSION_DATE << "\n\n"
<< "usage: lr_classify [options] testing_file model_file output_file\n\n"
<< "options: -h -> help\n"
<< " -f [0..2] -> 0: only output class label (default)\n"
<< " -> 1: output class label with log-likelihood (weighted sum)\n"
<< " -> 2: output class label with soft probability\n"
<< endl;
}
void read_parameters(int argc, char *argv[], char *testing_file, char *model_file,
char *output_file, int *output_format)
{
// set default options
*output_format = 0;
int i;
for (i = 1; (i<argc) && (argv[i])[0]=='-'; i++)
{
switch ((argv[i])[1]) {
case 'h':
print_help();
exit(0);
case 'f':
*output_format = atoi(argv[++i]);
break;
default:
cout << "Unrecognized option: " << argv[i] << "!" << endl;
print_help();
exit(0);
}
}
if ((i+2)>=argc)
{
cout << "Not enough parameters!" << endl;
print_help();
exit(0);
}
strcpy(testing_file, argv[i]);
strcpy(model_file, argv[i+1]);
strcpy(output_file, argv[i+2]);
}
int lr_classify(int argc, char *argv[])
{
char testing_file[200];
char model_file[200];
char output_file[200];
int output_format;
read_parameters(argc, argv, testing_file, model_file, output_file, &output_format);
LR Logit;
Logit.load_model(model_file);
float acc = Logit.classify_testing_file(testing_file, output_file, output_format);
cout << "Accuracy: " << acc << endl;
return 0;
}
int main(int argc, char *argv[])
{
return lr_classify(argc, argv);
}