-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.cpp
68 lines (54 loc) · 1.68 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
65
66
67
68
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <stdio.h>
#include <cmath>
#include <vector>
#include "data.h"
#include <algorithm>
#include "hp.h"
#include "onlinetree.h"
#include "randomerf.h"
using namespace std;
int main()
{
// Load the hyperparameters
string confFileName="config.txt";
Hyperparameters hp(confFileName); // Read config-file
fstream fout;
fout.open("result.txt",ios::out); // Save the results
// Starts
DataSet *dataset_train, *dataset_test;
string trainfile, testfile, basetr0, basetr1, basete0, basete1;
basete0 = "test\\01samples";
basete1 = ".txt";
int sample_groupsnum = 9; // Training exploits 10 samples
trainfile = "train\\01samples0.txt";
dataset_test = new DataSet;
(*dataset_train).loadLIBSVM(trainfile); // Load initial train data to start On-line training
OnlineRF model(hp, (*dataset_train).m_numClasses);
model.train(*dataset_train, *dataset_test);
vector<double> result;
// Samples arrive one-by-one
for(int i = 1 ; i < sample_groupsnum ; i++){
stringstream s0;
s0 << i;
string str0 = s0.str();
trainfile = basete0 + str0 + basete1;
(*dataset_train).loadLIBSVM(trainfile);
model.train(*dataset_train, *dataset_test);
}
for(int i = 1 ; i < 5 ; i = i + 2){ // Testing uses 5 samples
stringstream s0;
s0 << i;
string str0 = s0.str();
testfile = basete0 + str0 + basete1;
(*dataset_test).loadLIBSVM(testfile);
result = model.test(*dataset_test);
fout<<"prediction: "<<result[0]<<" "<<result[1]<<" "<<result[2]<<" "<<result[3]<<" "<<result[4]<<" "<<result[5]<<" "<<endl;
}
delete dataset_train;
delete dataset_test;
f.close();
}