-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
DomainAdaptationSVM.h
125 lines (100 loc) · 2.73 KB
/
DomainAdaptationSVM.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
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* Written (W) 2007-2011 Christian Widmer
* Copyright (C) 2007-2011 Max-Planck-Society
*/
#ifdef USE_SVMLIGHT
#ifndef _DomainAdaptation_SVM_H___
#define _DomainAdaptation_SVM_H___
#include <shogun/lib/common.h>
#include <shogun/classifier/svm/SVMLight.h>
#include <stdio.h>
namespace shogun
{
/** @brief class DomainAdaptationSVM */
class CDomainAdaptationSVM : public CSVMLight
{
public:
/** default constructor */
CDomainAdaptationSVM();
/** constructor
*
* @param C cost constant C
* @param k kernel
* @param lab labels
* @param presvm trained SVM to regularize against
* @param B trade-off constant B
*/
CDomainAdaptationSVM(float64_t C, CKernel* k, CLabels* lab, CSVM* presvm, float64_t B);
/** destructor */
virtual ~CDomainAdaptationSVM();
/** init SVM
*
* @param presvm trained SVM to regularize against
* @param B trade-off constant B
* */
void init(CSVM* presvm, float64_t B);
/** get classifier type
*
* @return classifier type
*/
virtual inline EClassifierType get_classifier_type() { return CT_DASVM; }
/** classify objects
*
* @param data (test)data to be classified
* @return classified labels
*/
virtual CLabels* apply(CFeatures* data);
/** returns SVM that is used as prior information
*
* @return presvm
*/
virtual CSVM* get_presvm();
/** getter for regularization parameter B
*
* @return regularization parameter B
*/
virtual float64_t get_B();
/** getter for train_factor
*
* @return train_factor
*/
virtual float64_t get_train_factor();
/** setter for train_factor
*
*/
virtual void set_train_factor(float64_t factor);
/** @return object name */
inline virtual const char* get_name() const { return "DomainAdaptationSVM"; }
protected:
/** check sanity of presvm
*
* @return true if sane, throws SG_ERROR otherwise
*/
virtual bool is_presvm_sane();
/** train SVM classifier
*
* @param data training data (parameter can be avoided if distance or
* kernel-based classifiers are used and distance/kernels are
* initialized with train data)
*
* @return whether training was successful
*/
virtual bool train_kernel_machine(CFeatures* data=NULL);
private:
void init();
protected:
/** SVM to regularize against */
CSVM* presvm;
/** regularization parameter B */
float64_t B;
/** flag to switch off regularization in training */
float64_t train_factor;
};
}
#endif //_DomainAdaptation_SVM_H___
#endif //USE_SVMLIGHT