KSquare Utilities
KKMLL::ModelSvmBase Class Reference

#include <ModelSvmBase.h>

+ Inheritance diagram for KKMLL::ModelSvmBase:

Public Types

typedef ModelSvmBaseModelSvmBasePtr
 
- Public Types inherited from KKMLL::Model
typedef ModelModelPtr
 
enum  ModelTypes : int {
  ModelTypes::Null = 0, ModelTypes::OldSVM = 1, ModelTypes::SvmBase = 2, ModelTypes::KNN = 3,
  ModelTypes::UsfCasCor = 4, ModelTypes::Dual = 5
}
 

Public Member Functions

 ModelSvmBase ()
 
 ModelSvmBase (FactoryFVProducerPtr _factoryFVProducer)
 
 ModelSvmBase (const KKStr &_name, const ModelParamSvmBase &_param, FactoryFVProducerPtr _factoryFVProducer)
 
 ModelSvmBase (const ModelSvmBase &_model)
 
virtual ~ModelSvmBase ()
 Frees any memory allocated by, and owned by the ModelSvmBase. More...
 
virtual KKStr Description () const
 
virtual ModelSvmBasePtr Duplicate () const
 
virtual kkint32 MemoryConsumedEstimated () const
 
virtual ModelTypes ModelType () const
 
virtual kkint32 NumOfSupportVectors () const
 
ModelParamSvmBasePtr Param ()
 
virtual MLClassPtr Predict (FeatureVectorPtr image, RunLog &log)
 
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 ClassProbListPtr ProbabilitiesByClass (FeatureVectorPtr example, RunLog &log)
 
virtual void ProbabilitiesByClass (FeatureVectorPtr example, const MLClassList &_mlClasses, kkint32 *_votes, double *_probabilities, RunLog &_log)
 
virtual void ProbabilitiesByClass (FeatureVectorPtr _example, const MLClassList &_mlClasses, double *_probabilities, RunLog &_log)
 Derives predicted probabilities by class. More...
 
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 calling ReadXMLModelToken. More...
 
virtual void RetrieveCrossProbTable (MLClassList &classes, double **crossProbTable, RunLog &log)
 
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 in the specific derived implementation of 'Model'. More...
 
virtual void WriteXML (const KKStr &varName, ostream &o) const
 
- Public Member Functions inherited from KKMLL::Model
 Model ()
 
 Model (FactoryFVProducerPtr _factoryFVProducer)
 Use this when you are planning on creating a empty model without parameters. More...
 
 Model (const KKStr &_name, const ModelParam &_param, FactoryFVProducerPtr _factoryFVProducer)
 Construct a instance of 'Model' using the parameters specified in '_param'. More...
 
 Model (const Model &_madel)
 Copy Constructor. More...
 
virtual ~Model ()
 Frees any memory allocated by, and owned by the Model. More...
 
bool AlreadyNormalized () const
 
const FeatureEncoder2Encoder () const
 
FactoryFVProducerPtr FactoryFVProducer () const
 
virtual FeatureNumListConstPtr GetFeatureNums () const
 
MLClassListPtr MLClasses () const
 
MLClassListPtr MLClassesNewInstance () const
 
virtual KKStr ModelTypeStr () const
 
const KKStrName () const
 
void Name (const KKStr &_name)
 
virtual bool NormalizeNominalAttributes () const
 
ModelParamPtr Param () const
 
virtual void PredictRaw (FeatureVectorPtr example, MLClassPtr &predClass, double &dist)
 
virtual FeatureVectorPtr PrepExampleForPrediction (FeatureVectorPtr fv, bool &newExampleCreated)
 Every prediction method in every class that is inherited from this class should call this method before performing there prediction. Such things as Normalization and Feature Encoding. More...
 
virtual void ProbabilitiesByClassDual (FeatureVectorPtr example, KKStr &classifier1Desc, KKStr &classifier2Desc, ClassProbListPtr &classifier1Results, ClassProbListPtr &classifier2Results, RunLog &log)
 Only applied to ModelDual classifier. More...
 
const KKStrRootFileName () const
 
void RootFileName (const KKStr &_rootFileName)
 
virtual FeatureNumListConstPtr SelectedFeatures () const
 
const KKB::DateTimeTimeSaved () const
 
double TrainingTime () const
 
void TrainingTimeEnd ()
 Derived classes call this method to stop the clock for 'trainingTime'. More...
 
void TrainingTimeStart ()
 Derived classes call this method to start the clock for 'trainingTime'. More...
 
double TrianingPrepTime () const
 
bool ValidModel () const
 
void WriteModelXMLFields (std::ostream &o) const
 The "WriteXML" method in Derived classes call this method to include the parents classes fields in the XML data. More...
 
virtual void WriteXML (const KKStr &varName, std::ostream &o) const =0
 

Protected Attributes

ModelParamSvmBasePtr param
 
SVM289_MFS::Svm_ModelsvmModel
 
- Protected Attributes inherited from KKMLL::Model
bool alreadyNormalized
 
MLClassListPtr classes
 
MLClassIndexListPtr classesIndex
 
double * classProbs
 
double ** crossClassProbTable
 
kkint32 crossClassProbTableSize
 
FeatureEncoder2Ptr encoder
 
VectorKKStr errors
 
FactoryFVProducerPtr factoryFVProducer
 
FileDescPtr fileDesc
 
NormalizationParmsPtr normParms
 
kkint32 numOfClasses
 
ModelParamPtr param
 
KKStr rootFileName
 
FeatureVectorListPtr trainExamples
 
bool validModel
 
kkint32votes
 
bool weOwnTrainExamples
 

Additional Inherited Members

- Static Public Member Functions inherited from KKMLL::Model
static ModelPtr CreateAModel (ModelTypes _modelType, const KKStr &_name, const ModelParam &_param, FactoryFVProducerPtr _factoryFVProducer, VolConstBool &_cancelFlag, RunLog &_log)
 A factory method that will instantiate the appropriate class of training model based off '_modelType'. More...
 
static ModelTypes ModelTypeFromStr (const KKStr &_modelingTypeStr)
 
static KKStr ModelTypeToStr (ModelTypes _modelingType)
 
- Protected Member Functions inherited from KKMLL::Model
void AddErrorMsg (const KKStr &errMsg, kkint32 lineNum)
 
void AllocatePredictionVariables ()
 
void DeAllocateSpace ()
 
void NormalizeProbabilitiesWithAMinumum (kkint32 numClasses, double *probabilities, double minProbability)
 
void ReadXMLModelPost (RunLog &log)
 
XmlTokenPtr ReadXMLModelToken (XmlTokenPtr t, RunLog &log)
 Will process any tokens that belong to 'ModelParam' and return NULL ones that are not will be passed back. More...
 
void ReduceTrainExamples (RunLog &log)
 Reduces the Training Images down to the size dictated by the 'examplesPerClass' parameter. More...
 

Detailed Description

Definition at line 22 of file ModelSvmBase.h.

Member Typedef Documentation

Constructor & Destructor Documentation

ModelSvmBase::ModelSvmBase ( )

Definition at line 35 of file ModelSvmBase.cpp.

References KKMLL::Model::Model(), param, and svmModel.

35  :
36  Model (),
37  param (NULL),
38  svmModel (NULL)
39 {
40 }
ModelParamSvmBasePtr param
Definition: ModelSvmBase.h:144
SVM289_MFS::Svm_Model * svmModel
Definition: ModelSvmBase.h:143
ModelSvmBase::ModelSvmBase ( FactoryFVProducerPtr  _factoryFVProducer)

Definition at line 43 of file ModelSvmBase.cpp.

References KKMLL::Model::Model(), param, and svmModel.

43  :
44  Model (_factoryFVProducer),
45  param (NULL),
46  svmModel (NULL)
47 {
48 }
ModelParamSvmBasePtr param
Definition: ModelSvmBase.h:144
SVM289_MFS::Svm_Model * svmModel
Definition: ModelSvmBase.h:143
ModelSvmBase::ModelSvmBase ( const KKStr _name,
const ModelParamSvmBase _param,
FactoryFVProducerPtr  _factoryFVProducer 
)

Definition at line 52 of file ModelSvmBase.cpp.

References KKMLL::Model::Model(), param, KKMLL::Model::param, and svmModel.

Referenced by KKMLL::Model::CreateAModel().

55  :
56  Model (_name, _param, _factoryFVProducer),
57  param (NULL),
58  svmModel (NULL)
59 {
60  param = dynamic_cast<ModelParamSvmBasePtr> (Model::param);
61 }
ModelParamPtr param
Definition: Model.h:412
ModelParamSvmBasePtr param
Definition: ModelSvmBase.h:144
SVM289_MFS::Svm_Model * svmModel
Definition: ModelSvmBase.h:143
ModelSvmBase::ModelSvmBase ( const ModelSvmBase _model)

Definition at line 66 of file ModelSvmBase.cpp.

References KKMLL::Model::fileDesc, KKMLL::Model::Model(), param, KKMLL::Model::param, SVM289_MFS::Svm_Model::Svm_Model(), and svmModel.

Referenced by Duplicate().

66  :
67  Model (_model),
68  param (NULL),
69  svmModel (NULL)
70 {
71  param = dynamic_cast<ModelParamSvmBasePtr> (Model::param);
72  if (_model.svmModel)
73  {
75  }
76 }
ModelParamPtr param
Definition: Model.h:412
ModelParamSvmBasePtr param
Definition: ModelSvmBase.h:144
FileDescPtr fileDesc
Definition: Model.h:406
SVM289_MFS::Svm_Model * svmModel
Definition: ModelSvmBase.h:143
ModelSvmBase::~ModelSvmBase ( )
virtual

Frees any memory allocated by, and owned by the ModelSvmBase.

Definition at line 85 of file ModelSvmBase.cpp.

References SVM289_MFS::svm_destroy_model(), and svmModel.

86 {
87  // The base class owns param, so we do not delete it.
88  // delete param;
89  if (svmModel)
90  {
91  svm_destroy_model (svmModel); // 'svm_destroy_model' will also delete 'svmModel'.
92  delete svmModel;
93  svmModel = NULL;
94  }
95 }
void svm_destroy_model(struct SvmModel233 *model)
Definition: svm.cpp:4442
SVM289_MFS::Svm_Model * svmModel
Definition: ModelSvmBase.h:143

Member Function Documentation

KKStr ModelSvmBase::Description ( ) const
virtual

Return short user readable description of model.

Reimplemented from KKMLL::Model.

Definition at line 121 of file ModelSvmBase.cpp.

References KKB::KKStr::Concat(), KKMLL::Model::Name(), KKB::KKStr::operator+(), KKB::operator+(), param, and KKMLL::ModelParamSvmBase::SvmParam().

122 {
123  KKStr result = "SvmBase(" + Name () + ")";
124 
125  if (param)
126  {
127  const SVM289_MFS::svm_parameter& svmParam = param->SvmParam ();
128 
129  //result << " " << MachineTypeToStr (svmParam.MachineType ())
130  // << " " << SelectionMethodToStr (svmParam.SelectionMethod ());
131  }
132  return result;
133 }
const KKStr & Name() const
Definition: Model.h:178
const SVM289_MFS::svm_parameter & SvmParam()
ModelParamSvmBasePtr param
Definition: ModelSvmBase.h:144
ModelSvmBasePtr ModelSvmBase::Duplicate ( ) const
virtual

Implements KKMLL::Model.

Definition at line 113 of file ModelSvmBase.cpp.

References ModelSvmBase().

114 {
115  return new ModelSvmBase (*this);
116 }
kkint32 ModelSvmBase::MemoryConsumedEstimated ( ) const
virtual

Reimplemented from KKMLL::Model.

Definition at line 99 of file ModelSvmBase.cpp.

References KKMLL::Model::MemoryConsumedEstimated(), SVM289_MFS::Svm_Model::MemoryConsumedEstimated(), and svmModel.

100 {
101  kkint32 memoryConsumedEstimated = Model::MemoryConsumedEstimated () +
102  sizeof (SVM289_MFS::Svm_Model*) +
103  sizeof (ModelParamSvmBasePtr);
104 
105  if (svmModel)
106  memoryConsumedEstimated += svmModel->MemoryConsumedEstimated ();
107  return memoryConsumedEstimated;
108 }
__int32 kkint32
Definition: KKBaseTypes.h:88
virtual kkint32 MemoryConsumedEstimated() const
Definition: Model.cpp:208
kkint32 MemoryConsumedEstimated() const
Definition: svm2.cpp:4284
SVM289_MFS::Svm_Model * svmModel
Definition: ModelSvmBase.h:143
virtual ModelTypes KKMLL::ModelSvmBase::ModelType ( ) const
inlinevirtual

Implements KKMLL::Model.

Definition at line 48 of file ModelSvmBase.h.

References KKMLL::Model::SvmBase.

kkint32 ModelSvmBase::NumOfSupportVectors ( ) const
virtual

Definition at line 608 of file ModelSvmBase.cpp.

References SVM289_MFS::Svm_Model::numSVs, and svmModel.

609 {
610  kkint32 numOfSupportVectors = 0;
611  if (!svmModel)
612  return 0;
613 
614  return svmModel->numSVs;
615 } /* NumOfSupportVectors */
__int32 kkint32
Definition: KKBaseTypes.h:88
kkint32 numSVs
Definition: svm2.h:206
SVM289_MFS::Svm_Model * svmModel
Definition: ModelSvmBase.h:143
ModelParamSvmBasePtr ModelSvmBase::Param ( )

Definition at line 137 of file ModelSvmBase.cpp.

References param.

138 {
139  return param;
140 }
ModelParamSvmBasePtr param
Definition: ModelSvmBase.h:144
MLClassPtr ModelSvmBase::Predict ( FeatureVectorPtr  image,
RunLog log 
)
virtual

Implements KKMLL::Model.

Definition at line 252 of file ModelSvmBase.cpp.

References KKMLL::Model::classesIndex, KKMLL::MLClassIndexList::GetMLClass(), KKMLL::Model::PrepExampleForPrediction(), SVM289_MFS::svm_predict(), and svmModel.

255 {
256  if (!svmModel)
257  {
258  log.Level (-1) << endl << endl << "ModelSvmBase::Predict ***ERROR*** (svmModel == NULL)" << endl << endl;
259  return NULL;
260  }
261 
262  if (!classesIndex)
263  {
264  log.Level (-1) << endl << endl << "ModelSvmBase::Predict ***ERROR*** (classesIndex == NULL)" << endl << endl;
265  return NULL;
266  }
267 
268  bool newExampleCreated = false;
269  FeatureVectorPtr encodedExample = PrepExampleForPrediction (example, newExampleCreated);
270  double y = (kkint32)SVM289_MFS::svm_predict (svmModel, *encodedExample);
271  if (newExampleCreated)
272  {
273  delete encodedExample;
274  encodedExample = NULL;
275  }
276 
277  kkint16 label = (kkint16)y;
278 
279  MLClassPtr ic = classesIndex->GetMLClass (label);
280  if (!ic)
281  log.Level (-1) << endl << endl << "ModelSvmBase::Predict ***ERROR*** Label[" << y << "] Returned from the SVM was not in the ClassAssignments list." << endl << endl;
282 
283  return ic;
284 } /* Predict */
__int16 kkint16
16 bit signed integer.
Definition: KKBaseTypes.h:85
HTMLReport &__cdecl endl(HTMLReport &htmlReport)
Definition: HTMLReport.cpp:240
__int32 kkint32
Definition: KKBaseTypes.h:88
Represents a "Class" in the Machine Learning Sense.
Definition: MLClass.h:52
RunLog & Level(kkint32 _level)
Definition: RunLog.cpp:220
MLClassPtr GetMLClass(kkint16 classIndex)
Locates the MLClass that was assigned classIndex.
Definition: MLClass.cpp:1636
virtual FeatureVectorPtr PrepExampleForPrediction(FeatureVectorPtr fv, bool &newExampleCreated)
Every prediction method in every class that is inherited from this class should call this method befo...
Definition: Model.cpp:574
double svm_predict(const struct Svm_Model *model, const FeatureVector &x)
Represents a Feature Vector of a single example, labeled or unlabeled.
Definition: FeatureVector.h:59
MLClassIndexListPtr classesIndex
Definition: Model.h:392
SVM289_MFS::Svm_Model * svmModel
Definition: ModelSvmBase.h:143
void ModelSvmBase::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

Implements KKMLL::Model.

Definition at line 289 of file ModelSvmBase.cpp.

References KKMLL::Model::classesIndex, KKMLL::Model::classProbs, KKB::KKStr::Concat(), KKMLL::MLClassIndexList::GetClassIndex(), KKMLL::MLClassIndexList::GetMLClass(), KKB::KKException::KKException(), KKMLL::Model::numOfClasses, KKMLL::Model::PrepExampleForPrediction(), SVM289_MFS::svm_predict_probability(), svmModel, and KKMLL::Model::votes.

303 {
304  if (!svmModel)
305  {
306  KKStr errMsg = "ModelSvmBase::Predict ***ERROR*** (svmModel == NULL)";
307  log.Level (-1) << endl << endl << errMsg << endl << endl;
308  throw KKException (errMsg);
309  }
310 
311  if (!classesIndex)
312  {
313  KKStr errMsg = "ModelSvmBase::Predict ***ERROR*** (classesIndex == NULL)";
314  log.Level (-1) << endl << endl << errMsg << endl << endl;
315  throw KKException (errMsg);
316  }
317 
318  kkint32 knownClassIdx = classesIndex->GetClassIndex (knownClass);
319 
320  bool newExampleCreated = false;
321  FeatureVectorPtr encodedExample = PrepExampleForPrediction (example, newExampleCreated);
322 
323  double y = SVM289_MFS::svm_predict_probability (svmModel, *encodedExample, classProbs, votes);
324 
325  if (newExampleCreated)
326  {
327  delete encodedExample;
328  encodedExample = NULL;
329  }
330 
331  kkint32 maxIndex1 = 0;
332  kkint32 maxIndex2 = 0;
333 
334  double maxProb1 = -1.0;
335  double maxProb2 = -1.0;
336 
337  numOfWinners = 0;
338  kkint32 winnerNumVotes = 0;
339 
340  for (kkint32 idx = 0; idx < numOfClasses; ++idx)
341  {
342  if (classProbs[idx] > maxProb1)
343  {
344  maxProb2 = maxProb1;
345  maxIndex2 = maxIndex1;
346  maxProb1 = classProbs[idx];
347  maxIndex1 = idx;
348  }
349  else if (classProbs[idx] > maxProb2)
350  {
351  maxProb2 = classProbs[idx];
352  maxIndex2 = idx;
353  }
354 
355  if (votes[idx] > winnerNumVotes)
356  {
357  // We have a new winner.
358  knownClassOneOfTheWinners = false;
359  numOfWinners = 1;
360  winnerNumVotes = votes[idx];
361  if (knownClassIdx == idx)
362  knownClassOneOfTheWinners = true;
363  }
364  else if (votes[idx] == winnerNumVotes)
365  {
366  numOfWinners++;
367  if (knownClassIdx == idx)
368  knownClassOneOfTheWinners = true;
369  }
370  }
371 
372  predClass1 = classesIndex->GetMLClass (maxIndex1);
373  predClass2 = classesIndex->GetMLClass (maxIndex2);
374  predClass1Votes = votes[maxIndex1];
375  predClass2Votes = votes[maxIndex2];
376  predClass1Prob = maxProb1;
377  predClass2Prob = maxProb2;
378 
379  breakTie = predClass1Prob - predClass2Prob;
380 
381  if ((knownClassIdx < 0) || (knownClassIdx >= numOfClasses))
382  {
383  probOfKnownClass = 0.0;
384  knownClassOneOfTheWinners = false;
385  }
386  else
387  {
388  probOfKnownClass = (float)classProbs[knownClassIdx];
389  }
390 
391  return;
392 } /* Predict */
double svm_predict_probability(Svm_Model *model, const FeatureVector &x, double *prob_estimates, kkint32 *votes)
Definition: svm2.cpp:3988
HTMLReport &__cdecl endl(HTMLReport &htmlReport)
Definition: HTMLReport.cpp:240
kkint32 * votes
Definition: Model.h:428
__int32 kkint32
Definition: KKBaseTypes.h:88
kkint16 GetClassIndex(MLClassPtr c)
Returns the corresponding index to the class &#39;c&#39;; if not in list will return -1.
Definition: MLClass.cpp:1621
double * classProbs
Definition: Model.h:394
RunLog & Level(kkint32 _level)
Definition: RunLog.cpp:220
kkint32 numOfClasses
Definition: Model.h:410
MLClassPtr GetMLClass(kkint16 classIndex)
Locates the MLClass that was assigned classIndex.
Definition: MLClass.cpp:1636
virtual FeatureVectorPtr PrepExampleForPrediction(FeatureVectorPtr fv, bool &newExampleCreated)
Every prediction method in every class that is inherited from this class should call this method befo...
Definition: Model.cpp:574
Represents a Feature Vector of a single example, labeled or unlabeled.
Definition: FeatureVector.h:59
MLClassIndexListPtr classesIndex
Definition: Model.h:392
SVM289_MFS::Svm_Model * svmModel
Definition: ModelSvmBase.h:143
ClassProbListPtr ModelSvmBase::ProbabilitiesByClass ( FeatureVectorPtr  example,
RunLog log 
)
virtual

Implements KKMLL::Model.

Definition at line 398 of file ModelSvmBase.cpp.

References KKMLL::Model::classesIndex, KKMLL::ClassProb::ClassProb(), KKMLL::ClassProbList::ClassProbList(), KKMLL::Model::classProbs, KKB::KKStr::Concat(), KKMLL::MLClassIndexList::GetMLClass(), KKB::KKException::KKException(), KKMLL::Model::numOfClasses, KKMLL::Model::PrepExampleForPrediction(), KKMLL::ClassProbList::PushOnBack(), KKMLL::ClassProbList::SortByVotes(), SVM289_MFS::svm_predict_probability(), svmModel, and KKMLL::Model::votes.

401 {
402  if (!svmModel)
403  {
404  KKStr errMsg = "ModelSvmBase::ProbabilitiesByClass ***ERROR*** (svmModel == NULL)";
405  log.Level (-1) << endl << endl << errMsg << endl << endl;
406  throw KKException (errMsg);
407  }
408 
409  if (!classesIndex)
410  {
411  KKStr errMsg = "ModelSvmBase::ProbabilitiesByClass ***ERROR*** (classesIndex == NULL)";
412  log.Level (-1) << endl << endl << errMsg << endl << endl;
413  throw KKException (errMsg);
414  }
415 
416  bool newExampleCreated = false;
417  FeatureVectorPtr encodedExample = PrepExampleForPrediction (example, newExampleCreated);
418 
419  double y = SVM289_MFS::svm_predict_probability (svmModel, *encodedExample, classProbs, votes);
420 
421  if (newExampleCreated)
422  {
423  delete encodedExample;
424  encodedExample = NULL;
425  }
426 
427  ClassProbListPtr results = new ClassProbList ();
428  kkint32 idx = 0;
429  for (idx = 0; idx < numOfClasses; idx++)
430  {
431  MLClassPtr ic = classesIndex->GetMLClass (idx);
432  results->PushOnBack (new ClassProb (ic, classProbs[idx], (float)votes[idx]));
433  }
434 
435  results->SortByVotes (true);
436 
437  return results;
438 } /* ProbabilitiesByClass */
double svm_predict_probability(Svm_Model *model, const FeatureVector &x, double *prob_estimates, kkint32 *votes)
Definition: svm2.cpp:3988
HTMLReport &__cdecl endl(HTMLReport &htmlReport)
Definition: HTMLReport.cpp:240
kkint32 * votes
Definition: Model.h:428
__int32 kkint32
Definition: KKBaseTypes.h:88
virtual void PushOnBack(ClassProbPtr cp)
Definition: ClassProb.cpp:212
Represents a "Class" in the Machine Learning Sense.
Definition: MLClass.h:52
double * classProbs
Definition: Model.h:394
RunLog & Level(kkint32 _level)
Definition: RunLog.cpp:220
kkint32 numOfClasses
Definition: Model.h:410
MLClassPtr GetMLClass(kkint16 classIndex)
Locates the MLClass that was assigned classIndex.
Definition: MLClass.cpp:1636
virtual FeatureVectorPtr PrepExampleForPrediction(FeatureVectorPtr fv, bool &newExampleCreated)
Every prediction method in every class that is inherited from this class should call this method befo...
Definition: Model.cpp:574
Used to record probability for a specified class; and a list of classes.
Definition: ClassProb.h:25
void SortByVotes(bool highToLow=true)
Definition: ClassProb.cpp:151
Represents a Feature Vector of a single example, labeled or unlabeled.
Definition: FeatureVector.h:59
MLClassIndexListPtr classesIndex
Definition: Model.h:392
SVM289_MFS::Svm_Model * svmModel
Definition: ModelSvmBase.h:143
void ModelSvmBase::ProbabilitiesByClass ( FeatureVectorPtr  example,
const MLClassList _mlClasses,
kkint32 _votes,
double *  _probabilities,
RunLog _log 
)
virtual

Implements KKMLL::Model.

Definition at line 443 of file ModelSvmBase.cpp.

References KKMLL::Model::classesIndex, KKMLL::Model::classProbs, KKB::KKStr::Concat(), KKMLL::MLClassIndexList::GetClassIndex(), KKB::KKException::KKException(), KKMLL::MLClass::Name(), KKMLL::Model::numOfClasses, KKMLL::Model::PrepExampleForPrediction(), SVM289_MFS::svm_predict_probability(), svmModel, and KKMLL::Model::votes.

449 {
450  if (!svmModel)
451  {
452  KKStr errMsg = "ModelSvmBase::ProbabilitiesByClass ***ERROR*** (svmModel == NULL)";
453  _log.Level (-1) << endl << errMsg << endl << endl;
454  throw KKException (errMsg);
455  }
456 
457  if (!classesIndex)
458  {
459  KKStr errMsg = "ModelSvmBase::ProbabilitiesByClass ***ERROR*** (classesIndex == NULL)";
460  _log.Level (-1) << endl << errMsg << endl << endl;
461  throw KKException (errMsg);
462  }
463 
464  bool newExampleCreated = false;
465  FeatureVectorPtr encodedExample = PrepExampleForPrediction (example, newExampleCreated);
466 
467  double y = SVM289_MFS::svm_predict_probability (svmModel, *encodedExample, classProbs, votes);
468 
469  if (newExampleCreated)
470  {
471  delete encodedExample;
472  encodedExample = NULL;
473  }
474 
475  kkuint32 idx;
476  for (idx = 0; idx < _mlClasses.size (); idx++)
477  {
478  MLClassPtr ic = _mlClasses.IdxToPtr (idx);
479  kkint32 classIndex = classesIndex->GetClassIndex (ic);
480  if ((classIndex < 0) || (classIndex >= (kkint32)numOfClasses))
481  {
482  KKStr errMsg = "ModelSvmBase::Predict ***ERROR*** ";
483  errMsg << "Class[" << ic->Name () << "] was asked for but is not defined in this instance of 'ModelSvmBase'.";
484  _log.Level (-1) << endl << errMsg << endl << endl;
485  _votes [idx] = 0;
486  _probabilities [idx] = 0.0f;
487  }
488  else
489  {
490  _votes [idx] = votes [classIndex];
491  _probabilities [idx] = classProbs [classIndex];
492  }
493  }
494 
495  return;
496 } /* ProbabilitiesByClass */
double svm_predict_probability(Svm_Model *model, const FeatureVector &x, double *prob_estimates, kkint32 *votes)
Definition: svm2.cpp:3988
HTMLReport &__cdecl endl(HTMLReport &htmlReport)
Definition: HTMLReport.cpp:240
kkint32 * votes
Definition: Model.h:428
__int32 kkint32
Definition: KKBaseTypes.h:88
kkint16 GetClassIndex(MLClassPtr c)
Returns the corresponding index to the class &#39;c&#39;; if not in list will return -1.
Definition: MLClass.cpp:1621
Represents a "Class" in the Machine Learning Sense.
Definition: MLClass.h:52
EntryPtr IdxToPtr(kkuint32 idx) const
Definition: KKQueue.h:732
double * classProbs
Definition: Model.h:394
unsigned __int32 kkuint32
Definition: KKBaseTypes.h:89
RunLog & Level(kkint32 _level)
Definition: RunLog.cpp:220
kkint32 numOfClasses
Definition: Model.h:410
virtual FeatureVectorPtr PrepExampleForPrediction(FeatureVectorPtr fv, bool &newExampleCreated)
Every prediction method in every class that is inherited from this class should call this method befo...
Definition: Model.cpp:574
Represents a Feature Vector of a single example, labeled or unlabeled.
Definition: FeatureVector.h:59
MLClassIndexListPtr classesIndex
Definition: Model.h:392
SVM289_MFS::Svm_Model * svmModel
Definition: ModelSvmBase.h:143
void ModelSvmBase::ProbabilitiesByClass ( FeatureVectorPtr  _example,
const MLClassList _mlClasses,
double *  _probabilities,
RunLog _log 
)
virtual

Derives predicted probabilities by class.

Will get the probabilities assigned to each class by the classifier. The '_mlClasses' parameter dictates the order of the classes. That is the probabilities for any given index in '_probabilities' will be for the class specified in the same index in '_mlClasses'.

Parameters
[in]_exampleFeatureVector object to calculate predicted probabilities for.
[in]_mlClassesList image classes that caller is aware of. This should be the same list that was used when constructing this Model object. The list must be the same but not necessarily in the same order as when Model was 1st constructed.
[out]_probabilitiesAn array that must be as big as the number of classes as in mlClasses. The probability of class in mlClasses[x] will be returned in probabilities[x].

Implements KKMLL::Model.

Definition at line 502 of file ModelSvmBase.cpp.

References KKMLL::Model::classesIndex, KKMLL::Model::classProbs, KKB::KKStr::Concat(), KKMLL::MLClassIndexList::GetClassIndex(), KKB::KKException::KKException(), KKMLL::MLClass::Name(), KKMLL::Model::numOfClasses, KKMLL::Model::PrepExampleForPrediction(), SVM289_MFS::svm_predict_probability(), svmModel, and KKMLL::Model::votes.

507 {
508  if (!svmModel)
509  {
510  KKStr errMsg = "ModelSvmBase::ProbabilitiesByClass ***ERROR*** (svmModel == NULL)";
511  _log.Level (-1) << endl << endl << errMsg << endl << endl;
512  throw KKException (errMsg);
513  }
514 
515  if (!classesIndex)
516  {
517  KKStr errMsg = "ModelSvmBase::ProbabilitiesByClass ***ERROR*** (classesIndex == NULL)";
518  _log.Level (-1) << endl << endl << errMsg << endl << endl;
519  throw KKException (errMsg);
520  }
521 
522  bool newExampleCreated = false;
523  FeatureVectorPtr encodedExample = PrepExampleForPrediction (_example, newExampleCreated);
524 
525  double y = SVM289_MFS::svm_predict_probability (svmModel, *encodedExample, classProbs, votes);
526 
527  if (newExampleCreated)
528  {
529  delete encodedExample;
530  encodedExample = NULL;
531  }
532 
533  kkuint32 idx;
534  for (idx = 0; idx < _mlClasses.size (); idx++)
535  {
536  MLClassPtr ic = _mlClasses.IdxToPtr (idx);
537  kkint32 classIndex = classesIndex->GetClassIndex (ic);
538  if ((classIndex < 0) || (classIndex >= (kkint32)numOfClasses))
539  {
540  KKStr errMsg = "ModelSvmBase::Predict ***ERROR*** ";
541  errMsg << "Class[" << ic->Name () << "] was asked for but is not defined in this instance of 'ModelSvmBase'.";
542  _log.Level (-1) << endl << endl << errMsg << endl << endl;
543  _probabilities [idx] = 0.0f;
544  }
545  else
546  {
547  _probabilities [idx] = classProbs [classIndex];
548  }
549  }
550 
551  return;
552 } /* ProbabilitiesByClass */
double svm_predict_probability(Svm_Model *model, const FeatureVector &x, double *prob_estimates, kkint32 *votes)
Definition: svm2.cpp:3988
HTMLReport &__cdecl endl(HTMLReport &htmlReport)
Definition: HTMLReport.cpp:240
kkint32 * votes
Definition: Model.h:428
__int32 kkint32
Definition: KKBaseTypes.h:88
kkint16 GetClassIndex(MLClassPtr c)
Returns the corresponding index to the class &#39;c&#39;; if not in list will return -1.
Definition: MLClass.cpp:1621
Represents a "Class" in the Machine Learning Sense.
Definition: MLClass.h:52
EntryPtr IdxToPtr(kkuint32 idx) const
Definition: KKQueue.h:732
double * classProbs
Definition: Model.h:394
unsigned __int32 kkuint32
Definition: KKBaseTypes.h:89
RunLog & Level(kkint32 _level)
Definition: RunLog.cpp:220
kkint32 numOfClasses
Definition: Model.h:410
virtual FeatureVectorPtr PrepExampleForPrediction(FeatureVectorPtr fv, bool &newExampleCreated)
Every prediction method in every class that is inherited from this class should call this method befo...
Definition: Model.cpp:574
Represents a Feature Vector of a single example, labeled or unlabeled.
Definition: FeatureVector.h:59
MLClassIndexListPtr classesIndex
Definition: Model.h:392
SVM289_MFS::Svm_Model * svmModel
Definition: ModelSvmBase.h:143
void ModelSvmBase::ReadXML ( XmlStream s,
XmlTagConstPtr  tag,
VolConstBool cancelFlag,
RunLog log 
)
virtual

To be implemented by derived classes; the parent classes fields will be updated by the derived class calling ReadXMLModelToken.

Implements KKMLL::Model.

Definition at line 648 of file ModelSvmBase.cpp.

References KKMLL::Model::AddErrorMsg(), KKB::KKStr::Concat(), KKB::XmlStream::GetNextToken(), KKB::KKStr::KKStr(), KKMLL::ModelParam::ModelParamTypeStr(), param, KKMLL::Model::param, KKMLL::Model::ReadXMLModelPost(), KKMLL::Model::ReadXMLModelToken(), and svmModel.

653 {
654  delete svmModel;
655  svmModel = NULL;
656  XmlTokenPtr t = s.GetNextToken (cancelFlag, log);
657  while (t)
658  {
659  t = ReadXMLModelToken (t, log); // 1st see if the base class has this data field.
660  if (t)
661  {
662  if ((t->VarName ().EqualIgnoreCase ("SvmModel")) && (typeid(*t) == typeid(XmlElementSvm_Model)))
663  {
664  delete svmModel;
665  svmModel = dynamic_cast<XmlElementSvm_ModelPtr> (t)->TakeOwnership ();
666  }
667  else
668  {
669  KKStr errMsg (128);
670  errMsg << "ModelSvmBase::ReadXML ***ERROR*** Unexpected Token; Section:" << t->SectionName () << " VarName: " << t->VarName ();
671  AddErrorMsg (errMsg, 0);
672  log.Level (-1) << endl << errMsg << endl << endl;
673  }
674  }
675 
676  delete t;
677  t = s.GetNextToken (cancelFlag, log);
678  }
679  delete t;
680  t = NULL;
681 
682  if (!cancelFlag)
683  {
684  if (!param)
685  param = dynamic_cast<ModelParamSvmBasePtr> (Model::param);
686 
687  if (Model::param == NULL)
688  {
689  KKStr errMsg (128);
690  errMsg << "ModelSvmBase::ReadXML ***ERROR*** Base class 'Model' does not have 'param' defined.";
691  AddErrorMsg (errMsg, 0);
692  log.Level (-1) << endl << errMsg << endl << endl;
693  }
694 
695  else if (typeid (*Model::param) != typeid(ModelParamSvmBase))
696  {
697  KKStr errMsg (128);
698  errMsg << "ModelSvmBase::ReadXML ***ERROR*** Base class 'Model' param parameter is of the wrong type; found: " << Model::param->ModelParamTypeStr ();
699  AddErrorMsg (errMsg, 0);
700  log.Level (-1) << endl << errMsg << endl << endl;
701  }
702 
703  else
704  {
705  param = dynamic_cast<ModelParamSvmBasePtr> (Model::param);
706  }
707 
708  ReadXMLModelPost (log);
709  }
710 } /* ReadXML */
HTMLReport &__cdecl endl(HTMLReport &htmlReport)
Definition: HTMLReport.cpp:240
XmlTokenPtr ReadXMLModelToken(XmlTokenPtr t, RunLog &log)
Will process any tokens that belong to &#39;ModelParam&#39; and return NULL ones that are not will be passed ...
Definition: Model.cpp:884
ModelParamPtr param
Definition: Model.h:412
void AddErrorMsg(const KKStr &errMsg, kkint32 lineNum)
Definition: Model.cpp:239
bool EqualIgnoreCase(const KKStr &s2) const
Definition: KKStr.cpp:1250
virtual const KKStr & SectionName() const
Definition: XmlStream.h:265
RunLog & Level(kkint32 _level)
Definition: RunLog.cpp:220
ModelParamSvmBasePtr param
Definition: ModelSvmBase.h:144
void ReadXMLModelPost(RunLog &log)
Definition: Model.cpp:987
virtual KKStr ModelParamTypeStr() const
Definition: ModelParam.h:108
virtual XmlTokenPtr GetNextToken(VolConstBool &cancelFlag, RunLog &log)
Definition: XmlStream.cpp:116
virtual const KKStr & VarName() const
Definition: XmlStream.h:269
XmlElementTemplate< Svm_Model > XmlElementSvm_Model
Definition: svm2.h:230
SVM289_MFS::Svm_Model * svmModel
Definition: ModelSvmBase.h:143
void ModelSvmBase::RetrieveCrossProbTable ( MLClassList classes,
double **  crossProbTable,
RunLog log 
)
virtual
Parameters
crossProbTabletwo dimension matrix that needs to be classes.QueueSize () squared.

Reimplemented from KKMLL::Model.

Definition at line 557 of file ModelSvmBase.cpp.

References KKMLL::Model::classesIndex, KKB::KKStr::Concat(), KKMLL::MLClassIndexList::GetClassIndex(), KKMLL::MLClass::Name(), KKMLL::Model::numOfClasses, SVM289_MFS::Svm_Model::PairwiseProb(), and svmModel.

561 {
562  kkuint32 idx1, idx2;
563  VectorInt pairWiseIndexes (_classes.size (), 0);
564  for (idx1 = 0; idx1 < _classes.size (); idx1++)
565  {
566  MLClassPtr ic = _classes.IdxToPtr (idx1);
567  kkint32 pairWiseIndex = classesIndex->GetClassIndex (ic);
568  if ((pairWiseIndex < 0) || (pairWiseIndex >= (kkint32)numOfClasses))
569  {
570  KKStr errMsg = "ModelSvmBase::RetrieveCrossProbTable ***ERROR*** ";
571  errMsg << "Class[" << ic->Name () << "] was asked for but is not defined in this instance of 'ModelSvmBase'.";
572  _log.Level (-1) << endl << endl << errMsg << endl << endl;
573  pairWiseIndexes[idx1] = 0;
574  }
575  else
576  {
577  pairWiseIndexes[idx1] = pairWiseIndex;
578  }
579 
580  for (idx2 = 0; idx2 < _classes.size (); idx2++)
581  _crossProbTable[idx1][idx2] = 0.0;
582  }
583 
584  double** pairWiseProb = svmModel->PairwiseProb ();
585  if (!pairWiseProb)
586  return;
587 
588  for (idx1 = 0; idx1 < (_classes.size () - 1); idx1++)
589  {
590  kkint32 pairWiseIndex1 = pairWiseIndexes [idx1];
591  if ((pairWiseIndex1 >= 0) && (pairWiseIndex1 < (kkint32)numOfClasses))
592  {
593  for (idx2 = idx1 + 1; idx2 < _classes.size (); idx2++)
594  {
595  kkint32 pairWiseIndex2 = pairWiseIndexes [idx2];
596  if ((pairWiseIndex2 >= 0) && (pairWiseIndex2 < (kkint32)numOfClasses))
597  {
598  _crossProbTable[idx1][idx2] = pairWiseProb[pairWiseIndex1][pairWiseIndex2];
599  _crossProbTable[idx2][idx1] = pairWiseProb[pairWiseIndex2][pairWiseIndex1];
600  }
601  }
602  }
603  }
604 } /* RetrieveCrossProbTable */
HTMLReport &__cdecl endl(HTMLReport &htmlReport)
Definition: HTMLReport.cpp:240
__int32 kkint32
Definition: KKBaseTypes.h:88
kkint16 GetClassIndex(MLClassPtr c)
Returns the corresponding index to the class &#39;c&#39;; if not in list will return -1.
Definition: MLClass.cpp:1621
std::vector< int > VectorInt
Definition: KKBaseTypes.h:138
Represents a "Class" in the Machine Learning Sense.
Definition: MLClass.h:52
unsigned __int32 kkuint32
Definition: KKBaseTypes.h:89
kkint32 numOfClasses
Definition: Model.h:410
double ** PairwiseProb()
Definition: svm2.cpp:4319
MLClassIndexListPtr classesIndex
Definition: Model.h:392
SVM289_MFS::Svm_Model * svmModel
Definition: ModelSvmBase.h:143
void ModelSvmBase::TrainModel ( FeatureVectorListPtr  _trainExamples,
bool  _alreadyNormalized,
bool  _takeOwnership,
VolConstBool _cancelFlag,
RunLog _log 
)
virtual

Performs operations such as FeatureEncoding, and Normalization. The actual training of models occurs in the specific derived implementation of 'Model'.

Performs operations such as FeatureEncoding, and Normalization; the actual training of models occurs in the specific implementation of 'Model'.

Parameters
[in]_trainExamplesTraining data that classifier will be built from. If the examples need to be normalized or encoded and we are not taking ownership then a duplicate list of examples will be created that this method and class will be free to modify.
[in]_alreadyNormalizedIndicates if contents of '_trainExamples' are normalized already; if not they will be normalized.
[in]_takeOwnershipThis instance of Model will take ownership of '_examples' and is free to modify its contents.
Parameters
_takeOwnershipModel will take ownership of these examples

Reimplemented from KKMLL::Model.

Definition at line 144 of file ModelSvmBase.cpp.

References KKB::KKStr::Concat(), KKB::KKException::KKException(), KKB::KKStr::operator+(), KKB::operator+(), param, KKMLL::Model::rootFileName, KKMLL::ModelParam::SelectedFeatures(), SVM289_MFS::svm_destroy_model(), SVM289_MFS::svm_problem::svm_problem(), SVM289_MFS::svm_train(), svmModel, KKMLL::ModelParamSvmBase::SvmParam(), KKMLL::Model::trainExamples, KKMLL::Model::TrainingTimeEnd(), KKMLL::Model::TrainingTimeStart(), KKMLL::Model::TrainModel(), and KKMLL::Model::validModel.

150 {
151  _log.Level (10) << "ModelSvmBase::TrainModel[" << param->FileName () << "]." << endl;
152 
153  if (param == NULL)
154  {
155  validModel = false;
156  KKStr errMsg = "ModelSvmBase::TrainModel (param == NULL)";
157  _log.Level (-1) << endl << endl << errMsg << endl << endl;
158  throw KKException (errMsg);
159  }
160 
161  if (svmModel)
162  {
164  delete svmModel;
165  svmModel = NULL;
166  }
167 
168  try
169  {
170  Model::TrainModel (_trainExamples, _alreadyNormalized, _takeOwnership, _cancelFlag, _log);
171  }
172  catch (const KKException& e)
173  {
174  validModel = false;
175  KKStr errMsg = "ModelSvmBase::TrainModel ***ERROR*** Exception occurred calling 'Model::TrainModel'.";
176  _log.Level (-1) << endl << errMsg << endl << e.ToString () << endl << endl;
177  throw KKException (errMsg, e);
178  }
179  catch (const exception& e2)
180  {
181  validModel = false;
182  KKStr errMsg = "ModelSvmBase::TrainModel ***ERROR*** Exception occurred calling 'Model::TrainModel'.";
183  _log.Level (-1) << endl << errMsg << endl << e2.what () << endl << endl;
184  throw KKException (errMsg, e2);
185  }
186  catch (...)
187  {
188  validModel = false;
189  KKStr errMsg = "ModelSvmBase::TrainModel ***ERROR*** Exception occurred calling 'Model::TrainModel'.";
190  _log.Level (-1) << endl << errMsg << endl << endl;
191  throw KKException (errMsg);
192  }
193 
194 
195  // 'Model::TrainModel' Will have performed any Feature Encoding that needed to be done.
196  // Also the data structures 'classes', 'encoder', and 'fileDesc' will have been built.
197  // 'classes' will already be sorted in name order.
198  // The Prediction variables 'probabilities', 'votes', and 'crossClassProbTable' will
199  // have been built.
200 
201 
202  // Build the Label array that libSVM expects.
203  float* y = new float[trainExamples->QueueSize ()];
204  {
205  for (kkint32 labelIndex = 0; labelIndex < trainExamples->QueueSize (); labelIndex++)
206  {
207  kkint16 label = classesIndex->GetClassIndex (trainExamples->IdxToPtr (labelIndex)->MLClass ());
208  if (label < 0)
209  {
210  _log.Level (-1) << endl << " ModelSvmBase::TrainModel ***ERROR*** Label computed to -1; should not be able to happen." << endl << endl;
211  }
212  y[labelIndex] = (float)label;
213  }
214  }
215 
217  delete[] y; y = NULL;
218 
219  try
220  {
222  svmModel = SVM289_MFS::svm_train (prob, param->SvmParam (), _log);
223  TrainingTimeEnd ();
224  }
225  catch (const std::exception& e)
226  {
227  validModel = false;
228  KKStr errMsg = "ModelSvmBase::TrainModel ***ERROR*** Exception occurred in 'SVM289_MFS::svm_train' building training model[" + rootFileName + "].";
229  errMsg << endl << " Exception[" << e.what () << "]";
230  _log.Level (-1) << endl << endl << errMsg << endl << endl;
231  throw KKException (errMsg);
232  }
233  catch (...)
234  {
235  validModel = false;
236  KKStr errMsg = "ModelSvmBase::TrainModel ***ERROR*** Exception occurred in 'SVM289_MFS::svm_train' building training model[" + rootFileName + "].";
237  _log.Level (-1) << endl << endl << errMsg << endl << endl;
238  throw KKException (errMsg);
239  }
240 
241  if (svmModel == NULL)
242  {
243  validModel = false;
244  KKStr errMsg = "ModelSvmBase::TrainModel ***ERROR*** Building 'LibSVM' training model[" + rootFileName + "].";
245  _log.Level (-1) << endl << endl << errMsg << endl << endl;
246  throw KKException (errMsg);
247  }
248 } /* TrainModel */
__int16 kkint16
16 bit signed integer.
Definition: KKBaseTypes.h:85
HTMLReport &__cdecl endl(HTMLReport &htmlReport)
Definition: HTMLReport.cpp:240
__int32 kkint32
Definition: KKBaseTypes.h:88
Svm_Model * svm_train(const svm_problem &prob, const svm_parameter &param, RunLog &log)
Definition: svm2.cpp:3345
kkint16 GetClassIndex(MLClassPtr c)
Returns the corresponding index to the class &#39;c&#39;; if not in list will return -1.
Definition: MLClass.cpp:1621
FeatureVectorListPtr trainExamples
Definition: Model.h:424
EntryPtr IdxToPtr(kkuint32 idx) const
Definition: KKQueue.h:732
KKStr rootFileName
Definition: Model.h:414
const SVM289_MFS::svm_parameter & SvmParam()
RunLog & Level(kkint32 _level)
Definition: RunLog.cpp:220
virtual FeatureNumListConstPtr SelectedFeatures() const
Definition: ModelParam.h:116
bool validModel
Definition: Model.h:426
void TrainingTimeEnd()
Derived classes call this method to stop the clock for &#39;trainingTime&#39;.
Definition: Model.cpp:452
virtual const KKStr & FileName() const
Definition: ModelParam.h:114
ModelParamSvmBasePtr param
Definition: ModelSvmBase.h:144
void MLClass(MLClassPtr _mlClass)
Assign a class to this example.
Definition: FeatureVector.h:74
kkint32 QueueSize() const
Definition: KKQueue.h:313
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 ...
Definition: Model.cpp:467
void TrainingTimeStart()
Derived classes call this method to start the clock for &#39;trainingTime&#39;.
Definition: Model.cpp:445
void svm_destroy_model(struct SvmModel233 *model)
Definition: svm.cpp:4442
MLClassIndexListPtr classesIndex
Definition: Model.h:392
virtual const KKStr & ToString() const
Definition: KKException.cpp:98
SVM289_MFS::Svm_Model * svmModel
Definition: ModelSvmBase.h:143
void ModelSvmBase::WriteXML ( const KKStr varName,
ostream &  o 
) const
virtual

Definition at line 621 of file ModelSvmBase.cpp.

References KKB::XmlTag::AddAtribute(), KKB::KKStr::Empty(), svmModel, KKB::XmlTag::tagEnd, KKB::XmlTag::tagStart, KKMLL::Model::WriteModelXMLFields(), SVM289_MFS::Svm_Model::WriteXML(), KKB::XmlTag::WriteXML(), and KKB::XmlTag::XmlTag().

624 {
625  XmlTag startTag ("ModelSvmBase", XmlTag::TagTypes::tagStart);
626  if (!varName.Empty ())
627  startTag.AddAtribute ("VarName", varName);
628  startTag.WriteXML (o);
629 
630  WriteModelXMLFields (o); // Write the PArent class fields 1st.
631 
632  if (svmModel)
633  svmModel->WriteXML ("SvmModel", o);
634 
635  // Turns out the base class "Model" owns this data field and will also be writing it
636  // out so no point in re-reading again.
637  //if (param) param->WriteXML ("Param", o);
638 
639  XmlTag endTag ("ModelSvmBase", XmlTag::TagTypes::tagEnd);
640  endTag.WriteXML (o);
641  o << endl;
642 } /* WriteXML */
HTMLReport &__cdecl endl(HTMLReport &htmlReport)
Definition: HTMLReport.cpp:240
void WriteModelXMLFields(std::ostream &o) const
The "WriteXML" method in Derived classes call this method to include the parents classes fields in th...
Definition: Model.cpp:854
bool Empty() const
Definition: KKStr.h:241
virtual void WriteXML(const KKStr &varName, ostream &o) const
Definition: svm2.cpp:4332
SVM289_MFS::Svm_Model * svmModel
Definition: ModelSvmBase.h:143

Member Data Documentation

ModelParamSvmBasePtr KKMLL::ModelSvmBase::param
protected

We will NOT own this instance. It will point to same instance defined in parent class Model.

Definition at line 144 of file ModelSvmBase.h.

Referenced by Description(), ModelSvmBase(), Param(), ReadXML(), and TrainModel().


The documentation for this class was generated from the following files: