-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlstm_single.cpp
More file actions
78 lines (74 loc) · 2.2 KB
/
lstm_single.cpp
File metadata and controls
78 lines (74 loc) · 2.2 KB
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
#include "ALHead.h"
#include <iostream>
#include <fstream>
#include "math/ALFloatMatrix.h"
#include "learn/ALLearnFactory.h"
#include "learn/ALRNNLearner.h"
#include <math.h>
#include <sstream>
#include "cJSON/cJSON.h"
#include "core/ALARStructure.h"
#include "core/ALExpanderFactory.h"
#include "loader/ALStandardLoader.h"
#include <iostream>
#include "package/ALPackage.h"
using namespace std;
static std::string readAll(const char* file)
{
std::ostringstream output;
std::ifstream input(file);
output << input.rdbuf();
return output.str();
}
int test_main(int argc, char* argv[])
{
ALStandardLoader s;
ALSp<ALFloatDataChain> train_raw = s.load("./bao_normal.txt");
ALSp<ALLabeldData> train = ALPackageLabled(train_raw.get(), 1.0);
ALSp<ALFloatDataChain> test_raw = s.load("./bao_predict_normal.txt");
ALSp<ALLabeldData> test = ALPackageLabled(test_raw.get(), 1.0);
auto jsonString = readAll(argv[1]);
auto jsonObject = cJSON_Parse(jsonString.c_str());
ALSp<ALIChainLearner> learner = new ALRNNLearner(jsonObject);
//ALSp<ALISuperviseLearner> learner = new ALRandomForestMatrix(55);
ALSp<ALFloatPredictor> predictor = learner->vLearn(train.get());
ALFLOAT sumError = 0.0f;
{
std::ofstream outputP("output/ALRNNLearnerTest.txt");
for (auto p : test->get())
{
auto real = p.first;
auto pre = predictor->vPredict(p.second);
if (ZERO(pre))
{
continue;
}
auto error = real - pre;
sumError += error*error;
outputP << real <<"\t"<<pre<<"\n";
}
}
{
std::ofstream outputP("output/ALRNNLearnerTrain.txt");
for (auto p : train->get())
{
auto real = p.first;
auto pre = predictor->vPredict(p.second);
if (ZERO(pre))
{
continue;
}
auto error = real - pre;
sumError += error*error;
outputP << real <<"\t"<<pre<<"\n";
}
}
std::cout << sumError << "/"<<test->get().size()<<"\n";
return 1;
}
int main(int argc, char* argv[])
{
ALAUTOTIME;
test_main(argc, argv);
return 1;
}