-
Notifications
You must be signed in to change notification settings - Fork 31
/
main.cpp
84 lines (78 loc) · 2.7 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
* @Author: Xinyu Tu
* @Date: 2021-12-07 09:52:08
* @LastEditors: Xinyu Tu
* @LastEditTime: 2022-02-22 15:46:06
*/
#include <iostream>
#include "json/json.h"
#include "util/SocketManager.h"
#include "core/Player.h"
#include "util/IOManager.h"
#include "machine_learning/BPGraph.h"
#include "machine_learning/LSTMGraph.h"
#include <iostream>
int main(int argc, char** argv) {
srand(time(NULL)); // random seed
DBGtest=0;
if (argc < 2) {
DBGprint("Please enter party index:\n");
scanf("%d", &node_type);
}
else {
node_type = argv[1][0] - '0';
}
DBGprint("party index: %d\n", node_type);
Config::config = Config::init("constant.json");
Player::init();
IOManager::init_local_data();
for(int i = 0; i < IOManager::train_label.cols(); i++){
if(IOManager::train_label(0,i) > Config::config->IE){
IOManager::train_label(0,i) = Config::config->IE;
}
}
for(int i = 0; i < IOManager::test_label.cols(); i++){
if(IOManager::test_label(0,i) > Config::config->IE){
IOManager::test_label(0,i) = Config::config->IE;
}
}
// normalization
IOManager::train_data = IOManager::train_data/256;
IOManager::test_data = IOManager::test_data/256;
SocketManager::SMMLF tel;
if (!Config::config->LOCAL_TEST) {
tel.init(Config::config->IP,Config::config->PORT);
} else {
tel.init();
}
if(Config::config->GRAPH_TYPE == 0){
// Logistic regression
DBGprint("Logistic Regression begins:");
BPGraph::LR *bp = new BPGraph::LR(&IOManager::train_data, &IOManager::train_label, &IOManager::test_data, &IOManager::test_label);
bp->logistic_graph();
bp->train();
}
else if(Config::config->GRAPH_TYPE == 1){
// Linear regression
DBGprint("Linear Regression begins:");
BPGraph::LR *bp = new BPGraph::LR(&IOManager::train_data, &IOManager::train_label, &IOManager::test_data, &IOManager::test_label);
bp->linear_graph();
bp->train();
}
else if(Config::config->GRAPH_TYPE == 2){
// Three-layer model
DBGprint("Three-layer model begins:");
BPGraph::LR *bp = new BPGraph::LR(&IOManager::train_data, &IOManager::train_label, &IOManager::test_data, &IOManager::test_label);
bp->graph();
bp->train();
}
else if(Config::config->GRAPH_TYPE == 3){
// LSTM
LSTMGraph::LSTM *lstm = new LSTMGraph::LSTM(&IOManager::train_data, &IOManager::train_label, &IOManager::test_data, &IOManager::test_label);
DBGprint("LSTM constructing ...\n");
lstm->graph();
DBGprint("LSTM constructed ...\n");
lstm->train();
}
return 0;
}