KSquare Utilities
ModelUsfCasCor.h
Go to the documentation of this file.
1 #if !defined(_MODELUSFCASCOR_)
2 #define _MODELUSFCASCOR_
3 //***********************************************************************
4 //* ModelUsfCasCor *
5 //* *
6 //* This will be the base model for implementations that utilize *
7 //* the Support Vector Machine. *
8 //***********************************************************************
9 
10 
11 #include "RunLog.h"
12 #include "KKStr.h"
13 
14 #include "Model.h"
15 #include "ModelParam.h"
17 
18 #include "UsfCasCor.h"
19 
20 
21 namespace KKMLL
22 {
23  class ModelUsfCasCor: public Model
24  {
25  public:
26 
28 
29 
30  ModelUsfCasCor ();
31 
32  ModelUsfCasCor (FactoryFVProducerPtr _factoryFVProducer);
33 
34  ModelUsfCasCor (const KKStr& _name,
35  const ModelParamUsfCasCor& _param, // Create new model from
36  FactoryFVProducerPtr _factoryFVProducer
37  );
38 
39  ModelUsfCasCor (const ModelUsfCasCor& _model);
40 
41 
42  virtual
43  ~ModelUsfCasCor ();
44 
45  virtual
47 
48  virtual ModelTypes ModelType () const {return ModelTypes::UsfCasCor;}
49 
50  virtual
52 
53  virtual
55 
57 
58  virtual
59  MLClassPtr Predict (FeatureVectorPtr example,
60  RunLog& log
61  );
62 
63  virtual
64  void Predict (FeatureVectorPtr example,
65  MLClassPtr knownClass,
66  MLClassPtr& predClass1,
67  MLClassPtr& predClass2,
68  kkint32& predClass1Votes,
69  kkint32& predClass2Votes,
70  double& probOfKnownClass,
71  double& predClass1Prob,
72  double& predClass2Prob,
73  kkint32& numOfWinners,
74  bool& knownClassOneOfTheWinners,
75  double& breakTie,
76  RunLog& log
77  );
78 
79 
80  virtual
81  ClassProbListPtr ProbabilitiesByClass (FeatureVectorPtr example,
82  RunLog& log
83  );
84 
85 
86  virtual
87  void ProbabilitiesByClass (FeatureVectorPtr example,
88  const MLClassList& _mlClasses,
89  kkint32* _votes,
90  double* _probabilities,
91  RunLog& log
92  );
93 
94  /**
95  *@brief Derives predicted probabilities by class.
96  *@details Will get the probabilities assigned to each class by the classifier. The
97  * '_mlClasses' parameter dictates the order of the classes. That is the
98  * probabilities for any given index in '_probabilities' will be for the class
99  * specified in the same index in '_mlClasses'.
100  *@param[in] _example FeatureVector object to calculate predicted probabilities for.
101  *@param[in] _mlClasses List classes that caller is aware of. This should be the same
102  * list that was used when constructing this Model object. The list must
103  * be the same but not necessarily in the same order as when Model was 1st
104  * constructed.
105  *@param[out] _probabilities An array that must be as big as the number of classes as in
106  * mlClasses. The probability of class in mlClasses[x] will be returned
107  * in probabilities[x].
108  */
109  virtual
110  void ProbabilitiesByClass (FeatureVectorPtr _example,
111  const MLClassList& _mlClasses,
112  double* _probabilities,
113  RunLog& log
114  );
115 
116 
117  virtual void TrainModel (FeatureVectorListPtr _trainExamples,
118  bool _alreadyNormalized,
119  bool _takeOwnership, /**< Model will take ownership of these examples */
120  VolConstBool& _cancelFlag,
121  RunLog& _log
122  );
123 
124 
125  virtual void ReadXML (XmlStream& s,
126  XmlTagConstPtr tag,
127  VolConstBool& cancelFlag,
128  RunLog& log
129  );
130 
131 
132  virtual void WriteXML (const KKStr& varName,
133  ostream& o
134  ) const;
135 
136  protected:
137  UsfCasCorPtr usfCasCorClassifier;
138  ModelParamUsfCasCorPtr param; /**< We will NOT own this instance. It will point to same instance defined in parent class Model. */
139  }; /* ModelUsfCasCor */
140 
141  typedef ModelUsfCasCor::ModelUsfCasCorPtr ModelUsfCasCorPtr;
142 
143 #define _ModelUsfCasCor_Defined_
144 
145 
148 } /* namespace KKMLL */
149 
150 #endif
Base class to all Learning Algorithms.
Definition: Model.h:82
XmlElementModelUsfCasCor * XmlElementModelUsfCasCorPtr
__int32 kkint32
Definition: KKBaseTypes.h:88
ModelParamUsfCasCorPtr Param()
UsfCasCorPtr usfCasCorClassifier
virtual kkint32 MemoryConsumedEstimated() const
virtual void ProbabilitiesByClass(FeatureVectorPtr _example, const MLClassList &_mlClasses, double *_probabilities, RunLog &log)
Derives predicted probabilities by class.
virtual void Predict(FeatureVectorPtr example, MLClassPtr knownClass, MLClassPtr &predClass1, MLClassPtr &predClass2, kkint32 &predClass1Votes, kkint32 &predClass2Votes, double &probOfKnownClass, double &predClass1Prob, double &predClass2Prob, kkint32 &numOfWinners, bool &knownClassOneOfTheWinners, double &breakTie, RunLog &log)
virtual ModelTypes ModelType() const
virtual void ProbabilitiesByClass(FeatureVectorPtr example, const MLClassList &_mlClasses, kkint32 *_votes, double *_probabilities, RunLog &log)
XmlTag const * XmlTagConstPtr
Definition: KKStr.h:45
Manages the reading and writing of objects in a simple XML format. For a class to be supported by Xml...
Definition: XmlStream.h:46
This class encapsulates are the information necessary to build a UsfCasCor class. ...
virtual ModelUsfCasCorPtr Duplicate() const
ModelUsfCasCor(const KKStr &_name, const ModelParamUsfCasCor &_param, FactoryFVProducerPtr _factoryFVProducer)
static KKStr Concat(const std::vector< std::string > &values)
Concatenates the list of &#39;std::string&#39; strings.
Definition: KKStr.cpp:1082
ModelUsfCasCor(const ModelUsfCasCor &_model)
XmlElementModelTemplate< ModelUsfCasCor > XmlElementModelUsfCasCor
virtual ~ModelUsfCasCor()
Frees any memory allocated by, and owned by the ModelUsfCasCor.
virtual ClassProbListPtr ProbabilitiesByClass(FeatureVectorPtr example, RunLog &log)
ModelParamUsfCasCor * ModelParamUsfCasCorPtr
virtual MLClassPtr Predict(FeatureVectorPtr example, RunLog &log)
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)
virtual kkint32 NumOfSupportVectors() const
ModelParamUsfCasCorPtr param
ModelUsfCasCor * ModelUsfCasCorPtr
ModelUsfCasCor(FactoryFVProducerPtr _factoryFVProducer)
Maintains a list of MLClass instances.
Definition: MLClass.h:233
virtual void ReadXML(XmlStream &s, XmlTagConstPtr tag, VolConstBool &cancelFlag, RunLog &log)
To be implemented by derived classes; the parent classes fields will be updated by the derived class ...
virtual void TrainModel(FeatureVectorListPtr _trainExamples, bool _alreadyNormalized, bool _takeOwnership, VolConstBool &_cancelFlag, RunLog &_log)
Performs operations such as FeatureEncoding, and Normalization. The actual training of models occurs ...
virtual void WriteXML(const KKStr &varName, ostream &o) const
volatile const bool VolConstBool
Definition: KKBaseTypes.h:163