-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathsvm_solver.h
More file actions
executable file
·82 lines (66 loc) · 1.49 KB
/
svm_solver.h
File metadata and controls
executable file
·82 lines (66 loc) · 1.49 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
79
80
81
82
/**
*******************************************************************************
*
* Copyright (c) 2015 Baidu.com, Inc. All Rights Reserved
*
*******************************************************************************
*
* @file: svm_solver.h
* @author: mazefeng(mazefeng01@baidu.com)
* @date: 2015/06/30 11:10:00
*
*/
#include <iostream>
#include <fstream>
#include <strstream>
#include <sstream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdlib>
#include <unistd.h>
#include <string.h>
#include <iomanip>
#include "svm_common.h"
#include "svm_option.h"
#ifndef SVM_SOLVER_H
#define SVM_SOLVER_H
#define TOLERANCE 1e-6
class SVMSolver{
public:
SVMSolver(SVMOption *opt);
~SVMSolver();
int train();
int predict();
protected:
float error_rate();
int load_model(std::ifstream& is);
int dump_model(std::ofstream& os);
float kernel(int i1, int i2);
float learned_func(int k);
int examine_example(int i1);
int take_step(int i1, int i2);
protected:
// input options
float _c;
float _eps;
float _sig;
bool _is_linear_kernel;
const char *_fname_train;
const char *_fname_valid;
const char *_fname_model;
// internal options
int _n;
int _n_sv;
TVectorArray _x_array;
TFloatArray _y_array;
TVector _w;
TFloatArray _alpha;
TFloatArray _d;
TFloatArray _error_cache;
float _b;
float _delta_b;
};
#endif