-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTHREE.h
58 lines (47 loc) · 1.27 KB
/
THREE.h
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
#pragma once
#include "Dataset.h"
namespace nn {
class THREE : public Dataset {
public:
static const int INPUTS = 64, OUTPUTS = 3;
THREE(const char* train_file, const char* test_file)
: train(train_file), test(test_file)
{}
std::vector<DataEntry> get_train_set() {
int label;
FILE* three_train = fopen(train, "r");
std::vector<DataEntry> dataset;
while (fscanf(three_train, "%d $", &label) > 0) {
DataEntry entry(INPUTS, OUTPUTS);
for (int i = 0; i < OUTPUTS; i++) {
entry.label[i] = (label == i) ? 1 : 0;
}
for (int i = 0; i < INPUTS; i++) {
fscanf(three_train, "%lf", &entry.data[i]);
}
fscanf(three_train, "%*d");
dataset.push_back(std::move(entry));
}
return dataset;
}
std::vector<DataEntry> get_test_set() {
int label;
FILE* three_test = fopen(test, "r");
std::vector<DataEntry> dataset;
while (fscanf(three_test, "%d $", &label) > 0) {
DataEntry entry(INPUTS, OUTPUTS);
for (int i = 0; i < OUTPUTS; i++) {
entry.label[i] = (label == i) ? 1 : 0;
}
for (int i = 0; i < INPUTS; i++) {
fscanf(three_test, "%lf", &entry.data[i]);
}
fscanf(three_test, "%*d");
dataset.push_back(std::move(entry));
}
return dataset;
}
private:
const char *train, *test;
};
}