KSquare Utilities
SvmWrapper.h
Go to the documentation of this file.
1 #ifndef _SVMWRAPPER_
2 #define _SVMWRAPPER_
3 
4 #include "SVMparam.h"
5 
6 namespace KKMLL
7 {
8  //typedef enum {NORMAL, BAGGING, BOOSTING, SUBSPACE, SAMPLESV} LearnType;
9  enum class LearnType
10  {
11  NORMAL,
12  BAGGING,
13  BOOSTING,
14  SUBSPACE,
15  SAMPLESV
16  };
17 
19  typedef std::vector<float> Fvector;
20  typedef std::vector<double> Dvector;
21 
22  void SvmSaveModel (ostream& o,
23  struct SvmModel233** model
24  );
25 
26 
27  struct SvmModel233** SvmLoadModel (istream& f,
28  RunLog& log
29  );
30 
31 
32  struct SvmModel233** SvmTrainModel (const struct svm_parameter& param,
33  struct svm_problem& subprob
34  );
35 
36  void EncodeProblem (const struct svm_paramater& param,
37  struct svm_problem& prob_in,
38  struct svm_problem& prob_out
39  );
40 
41 
42  /**
43  *@param[in] svmParam Structure that has all the parameters used for building the SVM.
44  *@param[in] subModel This is the model(classifier) returned by SvmTrainModel.
45  *@param[in] probabilities Array that must be as big as number of classes the probability
46  * of each class will be returned where there sum is 1.0
47  *@param[in] unknownClassFeatureData data structure you build that represents a sparse array of
48  * the feature data that is to be used for prediction.
49  *@param[out] probabilities array that will receive the predicted probability for each class.
50  *@param[in] knownClass If you happen to know hat the class really is you can specify it
51  * here so as to get the probability of it returned back to you.
52  *@param[out] predClass1 The prediction will be returned back in this field.
53  *@param[out] predClass2 The second most likely class based off either probability or number of votes.
54  *@param[out] predClass1Votes Number votes that class 'predClass1' received.
55  *@param[out] predClass2Votes Number votes that class 'predClass2' received.
56  *@param[out] predClass1Prob Probability that class 'predClass1' received.
57  *@param[out] predClass2Prob Probability that class 'predClass2' received.
58  *@param[out] probOfKnownClass Probability that 'knownClass' class receved.
59  *@param[out] winners If voting was specified in 'svmParam' and there was a tie
60  * between 2 or more classes; them the classes that ties
61  * will be in this vector.
62  *@param[in] crossClassProbTable A 2 dimensional table that will have the computed probabilities
63  * between all the possible 2 class combinations.
64  *@param[in] breakTie The difference in probability between the two most likely classes.
65  */
66  void SvmPredictClass (SVMparam& svmParam,
67  struct SvmModel233** subModel,
68  const struct svm_node* unknownClassFeatureData,
69  kkint32* votes,
70  double* probabilities,
71  kkint32 knownClass,
72  kkint32& predClass1,
73  kkint32& predClass2,
74  kkint32& predClass1Votes,
75  kkint32& predClass2Votes,
76  double& predClass1Prob,
77  double& predClass2Prob,
78  double& probOfKnownClass,
79  Ivector& winners,
80  double** crossClassProbTable,
81  double& breakTie
82  );
83 
84 
85 
86  kkint32 SvmPredictTwoClass (const struct svm_parameter& param,
87  SvmModel233** submodel,
88  const svm_node* unKnownData,
89  kkint32 desired,
90  double& dist,
91  double& probability,
92  kkint32 excludeSupportVectorIDX
93  );
94 
95 
96 void SvmPredictRaw (SvmModel233** submodel,
97  const svm_node* unKnownData,
98  double& label,
99  double& dist
100  );
101 
102 
103  void SvmDestroyModel (struct SvmModel233** subModel);
104 
105 } /* namespace KKMLL */
106 
107 #endif
std::vector< float > Fvector
Definition: SvmWrapper.h:19
std::vector< double > Dvector
Definition: SvmWrapper.h:20
void SvmPredictRaw(SvmModel233 **submodel, const svm_node *unKnownData, double &label, double &dist)
Definition: SvmWrapper.cpp:684
__int32 kkint32
Definition: KKBaseTypes.h:88
std::vector< kkint32 > Ivector
Definition: SvmWrapper.h:18
void SvmSaveModel(ostream &o, struct SvmModel233 **model)
Definition: SvmWrapper.cpp:711
LearnType
Definition: SvmWrapper.h:9
struct SvmModel233 ** SvmTrainModel(const struct svm_parameter &param, struct svm_problem &subprob)
Definition: SvmWrapper.cpp:543
This class encapsulates are the information necessary to build a SVMModel class.
Definition: SVMparam.h:74
kkint32 SvmPredictTwoClass(const struct svm_parameter &param, SvmModel233 **submodel, const svm_node *unKnownData, kkint32 desired, double &dist, double &probability, kkint32 excludeSupportVectorIDX)
void SvmDestroyModel(struct SvmModel233 **subModel)
Definition: SvmWrapper.cpp:742
Used for logging messages.
Definition: RunLog.h:49
void EncodeProblem(const struct svm_paramater &param, struct svm_problem &prob_in, struct svm_problem &prob_out)
struct SvmModel233 ** SvmLoadModel(istream &f, RunLog &log)
Definition: SvmWrapper.cpp:722
void SvmPredictClass(SVMparam &svmParam, struct SvmModel233 **subModel, const struct svm_node *unknownClassFeatureData, kkint32 *votes, double *probabilities, kkint32 knownClass, kkint32 &predClass1, kkint32 &predClass2, kkint32 &predClass1Votes, kkint32 &predClass2Votes, double &predClass1Prob, double &predClass2Prob, double &probOfKnownClass, Ivector &winners, double **crossClassProbTable, double &breakTie)
Definition: SvmWrapper.cpp:585