-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexample1.cpp
43 lines (36 loc) · 998 Bytes
/
example1.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
#include <iostream>
#include <Eigen/Core>
#include "rehline.h"
int main()
{
// The preferred matrix type is row-majored
using Matrix = Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;
using Vector = Eigen::VectorXd;
// Dimensions
const int n = 1000;
const int p = 10;
// Simulate data
std::srand(123);
Matrix X = Matrix::Random(n, p);
Vector y(n);
for (int i = 0; i < n; i++)
{
if (std::rand() % 2 == 0)
y[i] = 1;
else
y[i] = -1;
}
// Setting parameters
double C = 100.0;
int max_iter = 1000;
double tol = 1e-5;
int shrink = 1;
int verbose = 0;
int trace_freq = 100;
// Run the solver
rehline::ReHLineResult<Matrix> res;
rehline::rehline_svm(res, X, y, C, max_iter, tol, shrink, verbose, trace_freq);
// Print the estimated beta
std::cout << "niter = " << res.niter << "\nbeta =\n" << res.beta << std::endl;
return 0;
}