Machine Learning Library
CSVMLight.h
Go to the documentation of this file.
1 #ifndef CSVMLIGHT_H
2 #define CSVMLIGHT_H
3 
4 
5 /*
6  COPYRIGHT (C) 2003 APPLIED NEUROINFORMATIC GROUP - UNIVERSITY OF BIELEFELD.
7 
8  ALL RIGHTS RESERVED.
9 
10  REDISTRIBUTION AND USE IN SOURCE AND BINARY FORM, WITH OR WITHOUT
11  MODIFICATION, REQUIRE THE PERMISSION OF THE COPYRIGHT HOLDERS.
12 
13  COMMERCIAL USE WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT HOLDERS
14  IS FORBIDDEN
15 
16  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
17  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
20  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 
28 
29 #include "CClassifier.h"
30 #include "CSVCandidate.h"
31 #include "CKernel.h"
32 #include "CArchiv.h"
33 #include "CSVMModel.h"
34 
38 template<class Type>
39 class CSVMLight : public CClassifier<Type> {
40 protected:
41  vector< CSVCandidate<Type> > m_tSupportVectors;
42  Type m_tBias;
43  Type m_tC;
44  Type m_tEpsilon;
55 
56 public:
58  CSVMLight();
59 
61  ~CSVMLight();
62 
63 
64  void train(const CDataset<Type>& rtDs);
65 
66 
67  void classify(const CVector<Type>&, Type&, Type&) const;
68 
69 
71  void setKernel(CKernel<Type>* ptKernel);
72 
74  void setCacheSize(int iSize);
75 
77  void setMaxQPSize(int iSize);
78 
80  void setRegularization(Type tC);
81 
83  void setCalibrationFolds(int iFolds);
84 
86  void setMaxTerminationError(Type tError);
87 
89  void setCostPositiveFactor(Type tCost);
90 
91 
93  CSVMModel<Type> getModel() const;
94 
95 
97  void setCalibratedOutput(bool bSwitch);
98 
99  const CKernel<Type>* kernel() {
100  return m_ptKernel;
101  };
102 
103  bool serialize2(CArchiv&);
104 
105  int classify(const CVector<Type>&) const;
106 
107 
108  string className() const { return string("CSVMLight");};
109 
110 
111  bool isA(const char* acClass) const { if(string(acClass) == "CSVMLight") return true; else return CClassifier<Type>::isA(acClass);};
112 
113 protected:
114  void solveQP(const CDataset<Type>& rtDs);
115  bool calibrate(CDenseVector<double> tIsPositive, CDenseVector<double> tConfidence, Type& tSigmoidA, Type& tSigmoidB);
116 
117 };
118 
119 
120 #endif
bool m_bLinearCached
Definition: CSVMLight.h:52
bool m_bCalibrated
Definition: CSVMLight.h:51
Type m_tBias
Definition: CSVMLight.h:42
Definition: CSVMModel.h:12
CSVMLight()
Constructor.
vector< CSVCandidate< Type > > m_tSupportVectors
Definition: CSVMLight.h:41
void solveQP(const CDataset< Type > &rtDs)
Wrapper for SVMLight library written by T. Joachims ....
Definition: CSVMLight.h:39
Type m_tC
Definition: CSVMLight.h:43
int m_iCalibrationFolds
Definition: CSVMLight.h:50
bool isA(const char *acClass) const
Definition: CSVMLight.h:111
void setCostPositiveFactor(Type tCost)
Set cost factor, by which error on postive items outweight errors for negative items.
CDenseVector< Type > m_tWeight
Definition: CSVMLight.h:54
CSVMModel< Type > getModel() const
Get model of trained svm.
~CSVMLight()
Destructor.
CKernel< Type > * m_ptKernel
Definition: CSVMLight.h:53
int m_iCacheSize
Definition: CSVMLight.h:48
string className() const
Definition: CSVMLight.h:108
void setCacheSize(int iSize)
Set size if cache in MByte.
int m_iMaxQPSize
Definition: CSVMLight.h:49
const CKernel< Type > * kernel()
Definition: CSVMLight.h:99
void classify(const CVector< Type > &, Type &, Type &) const
void setMaxQPSize(int iSize)
Set maximal size of quadratic program (>=2)
void setKernel(CKernel< Type > *ptKernel)
Set kernel object.
void setRegularization(Type tC)
Set regularization value.
Base class of object serialization.
Definition: CArchiv.h:19
Base class for kernel functions Base class for kernel function used for example by the support vector...
Definition: CKernel.h:46
Template object for vectors of single and double precision and integer.
Definition: CDenseVector.h:37
void train(const CDataset< Type > &rtDs)
bool calibrate(CDenseVector< double > tIsPositive, CDenseVector< double > tConfidence, Type &tSigmoidA, Type &tSigmoidB)
bool serialize2(CArchiv &)
templatized vector for numerical applications
Definition: CMatrix.h:39
Type m_tSigmoidA
Definition: CSVMLight.h:46
Type m_tPositiveCost
Definition: CSVMLight.h:45
Manages pairs of input and output vectors.
Definition: CDataset.h:110
Type m_tSigmoidB
Definition: CSVMLight.h:47
Type m_tEpsilon
Definition: CSVMLight.h:44
void setMaxTerminationError(Type tError)
Set maximal termination error.
void setCalibratedOutput(bool bSwitch)
Activate output calibration.
void setCalibrationFolds(int iFolds)
Set number of calibration folds.