-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
executable file
·64 lines (51 loc) · 1.82 KB
/
main.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
#include <mlpack/core.hpp>
#include <iostream>
#include <armadillo>
#include "hypergraph.h"
#include "subgradient.h"
int main(int argc, char* argv[])
{
//read parameters for the learning
//run example: ./main_para mushroom.csv 1 0.001 20 x x mushtemp
string datasetname = argv[1];
bool front = atoi(argv[2]);
double precision = atof(argv[3]);
int train_size = atoi(argv[4]);
char actfunc = *argv[5];
char lossfunc = *argv[6];
string resFile = argv[7];
//stream to write log file
ofstream myfile;
struct timeval tp;
Hypergraph *hg = new Hypergraph;
myfile.open ("log/"+resFile+".txt", ios::out | ios::app);
//myfile << "[Precision] "+to_string(precision)<<endl;
//myfile << "[Number of labeled data] " + to_string(train_size) <<endl;
bool res = hg->constructHMat("dataset/"+datasetname, front);
mlpack::data::Save("log/oh_fea.txt", hg->hMat);
mlpack::data::Save("log/oh_la.txt", hg->lMat);
Subgradient *sg = new Subgradient;
//record the start time
gettimeofday(&tp, NULL);
long int starttime = tp.tv_sec * 1000 + tp.tv_usec / 1000;
//core work here
Mat<unsigned int> result = sg->fitPredict(hg, train_size, precision, actfunc, lossfunc);
//record the end time of the task
gettimeofday(&tp, NULL);
long int endtime = tp.tv_sec * 1000 + tp.tv_usec / 1000;
//write accuracy to the log file
//myfile << "[accuracy] " <<sg->accuracy<<endl;
myfile <<sg->accuracy<<endl;
//write result to log
mlpack::data::Save("log/result.txt", result);
//change the time to minutes and seconds' form
int sec = (endtime - starttime)/1000;
int min = sec / 60;
sec = sec % 60;
//write spent time to the log file
//myfile << "[time] "<<min<<" mins "<<sec<<" secs"<<endl;
printf("Spent time: %d minutes %d seconds\n", min, sec);
delete hg, sg;
hg = NULL;
return 0;
}