-
Notifications
You must be signed in to change notification settings - Fork 0
/
LinearRegression.h
38 lines (35 loc) · 1.03 KB
/
LinearRegression.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
#pragma warning(push)
#pragma warning(disable : 4459)
#pragma warning(disable : 4458)
#pragma warning(disable : 4121)
#pragma warning(disable : 4127)
#pragma warning(disable : 4456)
#include <dlib/svm.h>
#pragma warning(pop)
#include <iostream>
#include <vector>
#include <Log.h>
typedef std::pair<std::vector<double>, double> DataPoint;
typedef std::vector<DataPoint> DataSet;
inline std::vector<double> runLeastSquares(DataSet const& dataSet)
{
try
{
auto a = dlib::rls();
for (auto const& dataPoint : dataSet) {
dlib::matrix<double> data(dataPoint.first.size(), 1);
for (int i = 0; i < int(dataPoint.first.size()); ++i) {
data(i, 0) = dataPoint.first[i];
}
a.train(data, dataPoint.second);
}
auto const& weights = a.get_w();
std::vector<double> returnVal(weights.begin(), weights.end());
return returnVal;
}
catch (std::exception& e)
{
logger << e.what() << "\n";
return std::vector<double>();
}
}