-
Notifications
You must be signed in to change notification settings - Fork 0
/
tester.cpp
80 lines (73 loc) · 2.08 KB
/
tester.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
#include "tester.h"
void Tester::testSolver()
{
const std::vector<size_t> sizes{300, 200};
Eigen::VectorXd funcParams(1);
funcParams<<0.001;
Eigen::VectorXd q0iParams(sizes.size());
q0iParams<<2, 4;
Eigen::VectorXd params(q0iParams.size() + funcParams.size());
params<<q0iParams, funcParams;
Solver solver(std::make_unique<RegressionModelLn1>(generateTaskData<Function1>(sizes, q0iParams, funcParams)));
solver.SolverInit();
if(!solver.Solve())
{
std::cout<<"Solution not found"<<std::endl;
tassert(false);
}
Eigen::VectorXd res = solver.GetResult();
std::cout<<"Aaand solution iiiis..."<<res.transpose()<<std::endl;
Eigen::VectorXd delta = res - Eigen::VectorXd(params);
//works only with integrate defined //tassert(delta.lpNorm<Eigen::Infinity>()<1e-1);
std::cout<<"test passed"<<std::endl;
}
void Tester::testRealWorld()
{
CSVDataImporter dataImporter;
Solver solver(std::make_unique<RegressionModelLn1>(dataImporter.read("/mnt/windows/Users/user/Documents/projects/GPTestTask/taskData.csv")));
solver.SolverInit();
if(!solver.Solve())
{
std::cout<<"Solution not found"<<std::endl;
tassert(false);
}
std::cout<<"Result model params"<<solver.GetResult().transpose()<<std::endl;
std::cout<<"test passed"<<std::endl;
}
template<class TFunc>
class fhlp
{
public:
static Eigen::VectorXd GetDefaultParams()
{
size_t n = TFunc::nParams;
Eigen::VectorXd params(n);
for(size_t i=0; i< n; ++i)
params[i] = TFunc::GetDefaultParam(i);
return params;
}
};
void Tester::Test()
{
try
{
testExactSolution<Function1>(fhlp<Function1>::GetDefaultParams(), true);
testExactSolution<Function2>(fhlp<Function2>::GetDefaultParams());
testExactSolution<Function3>(fhlp<Function3>::GetDefaultParams());
testExactSolution<Function4>(fhlp<Function4>::GetDefaultParams());
testSolver();
testRealWorld();
}
catch(...)
{
std::cout<<"Test error"<<std::endl;
}
}
void Tester::tassert(bool val)
{
if(!val)
{
std::cout<<"error"<<std::endl;
throw std::logic_error("Assertion failed");
}
}