KSquare Utilities
KKMLL::Model Class Referenceabstract

Base class to all Learning Algorithms. More...

#include <Model.h>

+ Inheritance diagram for KKMLL::Model:

Public Types

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

 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
 
virtual KKStr Description () const
 
virtual ModelPtr Duplicate () const =0
 
const FeatureEncoder2Encoder () const
 
FactoryFVProducerPtr FactoryFVProducer () const
 
virtual FeatureNumListConstPtr GetFeatureNums () const
 
virtual kkint32 MemoryConsumedEstimated () const
 
MLClassListPtr MLClasses () const
 
MLClassListPtr MLClassesNewInstance () const
 
virtual ModelTypes ModelType () const =0
 
virtual KKStr ModelTypeStr () const
 
const KKStrName () const
 
void Name (const KKStr &_name)
 
virtual bool NormalizeNominalAttributes () const
 
ModelParamPtr Param () const
 
virtual MLClassPtr Predict (FeatureVectorPtr example, RunLog &log)=0
 
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)=0
 
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 ClassProbListPtr ProbabilitiesByClass (FeatureVectorPtr example, RunLog &log)=0
 
virtual void ProbabilitiesByClass (FeatureVectorPtr example, const MLClassList &_mlClasses, kkint32 *_votes, double *_probabilities, RunLog &_log)=0
 
virtual void ProbabilitiesByClass (FeatureVectorPtr _example, const MLClassList &_mlClasses, double *_probabilities, RunLog &_log)=0
 Derives predicted probabilities by class. More...
 
virtual void ProbabilitiesByClassDual (FeatureVectorPtr example, KKStr &classifier1Desc, KKStr &classifier2Desc, ClassProbListPtr &classifier1Results, ClassProbListPtr &classifier2Results, RunLog &log)
 Only applied to ModelDual classifier. More...
 
virtual void ReadXML (XmlStream &s, XmlTagConstPtr tag, VolConstBool &cancelFlag, RunLog &log)=0
 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)
 
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...
 
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...
 
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
 

Static Public Member Functions

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

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...
 

Protected Attributes

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
 

Detailed Description

Base class to all Learning Algorithms.

Author
Kurt Kramer

Base class to be used by all Learning Algorithm Models. The idea is that all learning algorithms all follow the same basic flow. The two obvious functions that they all support are Training from supplied labeled examples(List of FeatureVector objects), Prediction of an unlabeled example.

Definition at line 82 of file Model.h.

Member Typedef Documentation

Definition at line 85 of file Model.h.

Member Enumeration Documentation

enum KKMLL::Model::ModelTypes : int
strong
Enumerator
Null 
OldSVM 
SvmBase 
KNN 
UsfCasCor 
Dual 

Definition at line 87 of file Model.h.

87  : int
88  {
89  Null = 0,
90  OldSVM = 1,
91  SvmBase = 2,
92  KNN = 3,
93  UsfCasCor = 4,
94  Dual = 5
95  };

Constructor & Destructor Documentation

Model::Model ( )

Definition at line 43 of file Model.cpp.

References alreadyNormalized, classes, classesIndex, classProbs, crossClassProbTable, crossClassProbTableSize, encoder, factoryFVProducer, fileDesc, KKB::KKStr::KKStr(), normParms, numOfClasses, param, rootFileName, trainExamples, validModel, votes, and weOwnTrainExamples.

Referenced by KKMLL::ModelDual::ModelDual(), KKMLL::ModelKnn::ModelKnn(), KKMLL::ModelOldSVM::ModelOldSVM(), KKMLL::ModelSvmBase::ModelSvmBase(), and KKMLL::ModelUsfCasCor::ModelUsfCasCor().

43  :
44  alreadyNormalized (false),
45  classes (NULL),
46  classesIndex (NULL),
47  classProbs (NULL),
48  crossClassProbTable (NULL),
50  encoder (NULL),
51  factoryFVProducer (NULL),
52  fileDesc (NULL),
53  name (),
54  normParms (NULL),
55  numOfClasses (0),
56  param (NULL),
57  rootFileName (),
58  trainExamples (NULL),
59  trianingPrepTime (0.0),
60  trainingTime (0.0),
61  trainingTimeStart (0.0),
62  validModel (true),
63  votes (NULL),
64  weOwnTrainExamples (false)
65 {
66 }
kkint32 * votes
Definition: Model.h:428
bool alreadyNormalized
Definition: Model.h:388
NormalizationParmsPtr normParms
Definition: Model.h:408
ModelParamPtr param
Definition: Model.h:412
FeatureVectorListPtr trainExamples
Definition: Model.h:424
KKStr rootFileName
Definition: Model.h:414
FactoryFVProducerPtr factoryFVProducer
Definition: Model.h:404
double * classProbs
Definition: Model.h:394
kkint32 numOfClasses
Definition: Model.h:410
bool validModel
Definition: Model.h:426
double ** crossClassProbTable
Definition: Model.h:396
FileDescPtr fileDesc
Definition: Model.h:406
kkint32 crossClassProbTableSize
Definition: Model.h:398
FeatureEncoder2Ptr encoder
Definition: Model.h:400
bool weOwnTrainExamples
Definition: Model.h:430
MLClassIndexListPtr classesIndex
Definition: Model.h:392
MLClassListPtr classes
Definition: Model.h:390
Model::Model ( FactoryFVProducerPtr  _factoryFVProducer)

Use this when you are planning on creating a empty model without parameters.

Definition at line 117 of file Model.cpp.

References alreadyNormalized, classes, classesIndex, classProbs, crossClassProbTable, crossClassProbTableSize, encoder, factoryFVProducer, KKMLL::FactoryFVProducer::FileDesc(), fileDesc, KKB::KKStr::KKStr(), normParms, numOfClasses, param, rootFileName, trainExamples, validModel, votes, and weOwnTrainExamples.

Referenced by KKMLL::ModelDual::ModelDual(), KKMLL::ModelKnn::ModelKnn(), KKMLL::ModelOldSVM::ModelOldSVM(), KKMLL::ModelSvmBase::ModelSvmBase(), and KKMLL::ModelUsfCasCor::ModelUsfCasCor().

117  :
118  alreadyNormalized (false),
119  classes (NULL),
120  classesIndex (NULL),
121  classProbs (NULL),
122  crossClassProbTable (NULL),
124  encoder (NULL),
125  factoryFVProducer (_factoryFVProducer),
126  fileDesc (NULL),
127  name (),
128  normParms (NULL),
129  numOfClasses (0),
130  param (NULL),
131  rootFileName (),
132  trainExamples (NULL),
133  trianingPrepTime (0.0),
134  trainingTime (0.0),
135  trainingTimeStart (0.0),
136  validModel (true),
137  votes (NULL),
138  weOwnTrainExamples (false)
139 {
141 }
kkint32 * votes
Definition: Model.h:428
bool alreadyNormalized
Definition: Model.h:388
NormalizationParmsPtr normParms
Definition: Model.h:408
ModelParamPtr param
Definition: Model.h:412
FeatureVectorListPtr trainExamples
Definition: Model.h:424
KKStr rootFileName
Definition: Model.h:414
FactoryFVProducerPtr factoryFVProducer
Definition: Model.h:404
double * classProbs
Definition: Model.h:394
kkint32 numOfClasses
Definition: Model.h:410
bool validModel
Definition: Model.h:426
double ** crossClassProbTable
Definition: Model.h:396
FileDescPtr fileDesc
Definition: Model.h:406
kkint32 crossClassProbTableSize
Definition: Model.h:398
FeatureEncoder2Ptr encoder
Definition: Model.h:400
bool weOwnTrainExamples
Definition: Model.h:430
virtual FileDescPtr FileDesc() const =0
MLClassIndexListPtr classesIndex
Definition: Model.h:392
MLClassListPtr classes
Definition: Model.h:390
Model::Model ( const KKStr _name,
const ModelParam _param,
FactoryFVProducerPtr  _factoryFVProducer 
)

Construct a instance of 'Model' using the parameters specified in '_param'.

Creates a new svm model from the provided example data.

Parameters
[in]_nameName of training model.
[in]_paramParameters for learning algorithm; we will create a duplicate copy.
[in]_fileDescDescription of the dataset that will be used to train the classifier and examples that will be classified.
[in]_cancelFlagWill monitor; if at any point it turns true this instance is to terminate and return to caller.
[in,out]_logLogging file.
[in]_name
[in]_paramWill make own local copy.
[in]_fileDescA description of the data file.
[in]_logA log-file stream. All important events will be output to this stream

Definition at line 152 of file Model.cpp.

References alreadyNormalized, classes, classesIndex, classProbs, crossClassProbTable, crossClassProbTableSize, KKMLL::ModelParam::Duplicate(), encoder, factoryFVProducer, KKMLL::FactoryFVProducer::FileDesc(), fileDesc, KKB::KKStr::KKStr(), normParms, numOfClasses, param, rootFileName, trainExamples, validModel, votes, and weOwnTrainExamples.

Referenced by KKMLL::ModelDual::ModelDual(), KKMLL::ModelKnn::ModelKnn(), KKMLL::ModelOldSVM::ModelOldSVM(), KKMLL::ModelSvmBase::ModelSvmBase(), and KKMLL::ModelUsfCasCor::ModelUsfCasCor().

155  :
156  alreadyNormalized (false),
157  classes (NULL),
158  classesIndex (NULL),
159  classProbs (NULL),
160  crossClassProbTable (NULL),
162  encoder (NULL),
163  factoryFVProducer (_factoryFVProducer),
164  fileDesc (NULL),
165  name (_name),
166  normParms (NULL),
167  numOfClasses (0),
168  param (NULL),
169  rootFileName (),
170  trainExamples (NULL),
171  trianingPrepTime (0.0),
172  trainingTime (0.0),
173  trainingTimeStart (0.0),
174  validModel (true),
175  votes (NULL),
176  weOwnTrainExamples (false)
177 {
179  param = _param.Duplicate ();
180 }
kkint32 * votes
Definition: Model.h:428
bool alreadyNormalized
Definition: Model.h:388
NormalizationParmsPtr normParms
Definition: Model.h:408
ModelParamPtr param
Definition: Model.h:412
FeatureVectorListPtr trainExamples
Definition: Model.h:424
KKStr rootFileName
Definition: Model.h:414
FactoryFVProducerPtr factoryFVProducer
Definition: Model.h:404
double * classProbs
Definition: Model.h:394
virtual ModelParamPtr Duplicate() const =0
kkint32 numOfClasses
Definition: Model.h:410
bool validModel
Definition: Model.h:426
double ** crossClassProbTable
Definition: Model.h:396
FileDescPtr fileDesc
Definition: Model.h:406
kkint32 crossClassProbTableSize
Definition: Model.h:398
FeatureEncoder2Ptr encoder
Definition: Model.h:400
bool weOwnTrainExamples
Definition: Model.h:430
virtual FileDescPtr FileDesc() const =0
MLClassIndexListPtr classesIndex
Definition: Model.h:392
MLClassListPtr classes
Definition: Model.h:390
Model::Model ( const Model _madel)

Copy Constructor.

Definition at line 69 of file Model.cpp.

References AllocatePredictionVariables(), alreadyNormalized, classes, classesIndex, classProbs, crossClassProbTable, crossClassProbTableSize, KKMLL::ModelParam::Duplicate(), encoder, factoryFVProducer, KKMLL::FeatureEncoder2::FeatureEncoder2(), fileDesc, KKB::KKStr::KKStr(), KKMLL::MLClassIndexList::MLClassIndexList(), KKMLL::MLClassList::MLClassList(), normParms, numOfClasses, param, rootFileName, trainExamples, validModel, votes, and weOwnTrainExamples.

Referenced by KKMLL::ModelDual::ModelDual(), KKMLL::ModelKnn::ModelKnn(), KKMLL::ModelOldSVM::ModelOldSVM(), KKMLL::ModelSvmBase::ModelSvmBase(), and KKMLL::ModelUsfCasCor::ModelUsfCasCor().

69  :
70  alreadyNormalized (false),
71  classes (NULL),
72  classesIndex (NULL),
73  classProbs (NULL),
74  crossClassProbTable (NULL),
76  encoder (NULL),
77  factoryFVProducer (_model.factoryFVProducer),
78  fileDesc (_model.fileDesc),
79  name (_model.name),
80  normParms (NULL),
81  numOfClasses (_model.numOfClasses),
82  param (NULL),
83  rootFileName (_model.rootFileName),
84  trainExamples (NULL),
85  trianingPrepTime (0.0),
86  trainingTime (_model.trainingTime),
87  trainingTimeStart (_model.trainingTime),
88  validModel (_model.validModel),
89  votes (NULL),
90  weOwnTrainExamples (false)
91 {
92  numOfClasses = 0;
93  if (_model.param != NULL)
94  param = _model.param->Duplicate ();
95 
96  if (_model.classes)
97  {
98  classes = new MLClassList (*_model.classes);
100 
102  }
103 
104  if (_model.classesIndex)
105  classesIndex = new MLClassIndexList (*_model.classesIndex);
106 
107 
108  if (_model.encoder)
109  encoder = new FeatureEncoder2 (*_model.encoder);
110 }
kkint32 * votes
Definition: Model.h:428
bool alreadyNormalized
Definition: Model.h:388
Maintains a list of classes and their associated integer index.
Definition: MLClass.h:459
NormalizationParmsPtr normParms
Definition: Model.h:408
ModelParamPtr param
Definition: Model.h:412
FeatureVectorListPtr trainExamples
Definition: Model.h:424
KKStr rootFileName
Definition: Model.h:414
FactoryFVProducerPtr factoryFVProducer
Definition: Model.h:404
double * classProbs
Definition: Model.h:394
virtual ModelParamPtr Duplicate() const =0
kkint32 numOfClasses
Definition: Model.h:410
bool validModel
Definition: Model.h:426
double ** crossClassProbTable
Definition: Model.h:396
FileDescPtr fileDesc
Definition: Model.h:406
kkint32 QueueSize() const
Definition: KKQueue.h:313
kkint32 crossClassProbTableSize
Definition: Model.h:398
Maintains a list of MLClass instances.
Definition: MLClass.h:233
FeatureEncoder2Ptr encoder
Definition: Model.h:400
bool weOwnTrainExamples
Definition: Model.h:430
MLClassIndexListPtr classesIndex
Definition: Model.h:392
MLClassListPtr classes
Definition: Model.h:390
void AllocatePredictionVariables()
Definition: Model.cpp:343
Model::~Model ( )
virtual

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

Definition at line 188 of file Model.cpp.

References classes, classesIndex, DeAllocateSpace(), encoder, normParms, param, trainExamples, and weOwnTrainExamples.

189 {
190  DeAllocateSpace ();
191 
192  delete classesIndex; classesIndex = NULL;
193  delete classes; classes = NULL;
194  delete encoder; encoder = NULL;
195  delete normParms; normParms = NULL;
196 
197  if (weOwnTrainExamples)
198  {
199  delete trainExamples;
200  trainExamples = NULL;
201  }
202 
203  delete param;
204  param = NULL;
205 }
void DeAllocateSpace()
Definition: Model.cpp:383
NormalizationParmsPtr normParms
Definition: Model.h:408
ModelParamPtr param
Definition: Model.h:412
FeatureVectorListPtr trainExamples
Definition: Model.h:424
FeatureEncoder2Ptr encoder
Definition: Model.h:400
bool weOwnTrainExamples
Definition: Model.h:430
MLClassIndexListPtr classesIndex
Definition: Model.h:392
MLClassListPtr classes
Definition: Model.h:390

Member Function Documentation

void Model::AddErrorMsg ( const KKStr errMsg,
kkint32  lineNum 
)
protected
void Model::AllocatePredictionVariables ( )
protected

Definition at line 343 of file Model.cpp.

References classes, classProbs, crossClassProbTable, crossClassProbTableSize, DeAllocateSpace(), numOfClasses, validModel, and votes.

Referenced by Model(), and TrainModel().

344 {
345  kkint32 x = 0;
346  kkint32 y = 0;
347 
348  DeAllocateSpace ();
349 
350  if (classes == NULL)
351  {
352  cerr << endl << endl
353  << "Model::AllocatePredictionVariables ***ERROR*** (classes == NULL)" << endl
354  << endl;
355 
356  validModel = false;
357  return;
358  }
359 
361 
362  if (numOfClasses > 0)
363  {
365  classProbs = new double[numOfClasses];
366  votes = new kkint32 [numOfClasses];
367  crossClassProbTable = new double*[numOfClasses];
368  for (x = 0; x < numOfClasses; x++)
369  {
370  classProbs [x] = 0.0;
371  votes [x] = 0;
372  crossClassProbTable[x] = new double[numOfClasses];
373  for (y = 0; y < numOfClasses; y++)
374  crossClassProbTable[x][y] = 0.0f;
375  }
376  }
377 } /* AllocatePredictionVariables*/
void DeAllocateSpace()
Definition: Model.cpp:383
HTMLReport &__cdecl endl(HTMLReport &htmlReport)
Definition: HTMLReport.cpp:240
kkint32 * votes
Definition: Model.h:428
__int32 kkint32
Definition: KKBaseTypes.h:88
double * classProbs
Definition: Model.h:394
kkint32 numOfClasses
Definition: Model.h:410
bool validModel
Definition: Model.h:426
double ** crossClassProbTable
Definition: Model.h:396
kkint32 QueueSize() const
Definition: KKQueue.h:313
kkint32 crossClassProbTableSize
Definition: Model.h:398
MLClassListPtr classes
Definition: Model.h:390
bool KKMLL::Model::AlreadyNormalized ( ) const
inline

Definition at line 157 of file Model.h.

References alreadyNormalized.

157 {return alreadyNormalized;}
bool alreadyNormalized
Definition: Model.h:388
ModelPtr Model::CreateAModel ( ModelTypes  _modelType,
const KKStr _name,
const ModelParam _param,
FactoryFVProducerPtr  _factoryFVProducer,
VolConstBool _cancelFlag,
RunLog _log 
)
static

A factory method that will instantiate the appropriate class of training model based off '_modelType'.

This method is used to construct a model that is going to be built from training data.

Parameters
[in]_modelTypeType of model to be created; ex: mtOldSVM, mtSvmBase, or mtKNN.
[in]_name
[in]_paramParameters used to drive the creating of the model.
[in]_fileDescDescription of the dataset that will be used to train the classifier and examples that will be classified.
[in]_cancelFlagWill monitor; if at any point it turns true this instance is to terminate and return to caller.
[in,out]_logLogging file.
Parameters
_paramWill make a duplicate copy of

Definition at line 287 of file Model.cpp.

References KKB::KKStr::Concat(), Dual, KKB::KKException::KKException(), KNN, KKMLL::ModelDual::ModelDual(), KKMLL::ModelKnn::ModelKnn(), KKMLL::ModelOldSVM::ModelOldSVM(), KKMLL::ModelSvmBase::ModelSvmBase(), KKMLL::ModelUsfCasCor::ModelUsfCasCor(), OldSVM, KKB::KKStr::operator+(), KKB::operator+(), KKB::StrFromInt16(), KKMLL::ModelOldSVM::SupportVectorNames(), SvmBase, and UsfCasCor.

Referenced by KKMLL::TrainingProcess2::CreateModelsFromTrainingData().

294 {
295  ModelPtr model = NULL;
296  try
297  {
298  switch (_modelType)
299  {
300  case ModelTypes::OldSVM:
301  model = new ModelOldSVM (_name, dynamic_cast<const ModelParamOldSVM&> (_param), _factoryFVProducer);
302  break;
303 
304  case ModelTypes::SvmBase:
305  model = new ModelSvmBase (_name, dynamic_cast<const ModelParamSvmBase&> (_param), _factoryFVProducer);
306  break;
307 
308  case ModelTypes::KNN:
309  model = new ModelKnn (_name, dynamic_cast<const ModelParamKnn&> (_param), _factoryFVProducer);
310  break;
311 
313  model = new ModelUsfCasCor (_name, dynamic_cast<const ModelParamUsfCasCor&> (_param), _factoryFVProducer);
314  break;
315 
316  case ModelTypes::Dual:
317  model = new ModelDual (_name, dynamic_cast<const ModelParamDual&> (_param), _factoryFVProducer);
318  break;
319 
320  default:
321  KKStr errMsg = "Model::CreateAModel ***ERROR*** Invalid _modelType[" + KKB::StrFromInt16((kkint16)_modelType) + "].";
322  _log.Level (-1) << endl << errMsg << endl << endl;
323  throw KKException(errMsg);
324  } /* end of switch */
325  }
326  catch (const KKException& e)
327  {
328  delete model; model = NULL;
329  throw KKException ("Model::CreateAModel Exception calling constructor.", e);
330  }
331  catch (...)
332  {
333  delete model; model = NULL;
334  throw KKException ("Model::CreateAModel Exception calling constructor. No info provided.");
335  }
336 
337  return model;
338 } /* CreateAModel */
__int16 kkint16
16 bit signed integer.
Definition: KKBaseTypes.h:85
HTMLReport &__cdecl endl(HTMLReport &htmlReport)
Definition: HTMLReport.cpp:240
Base class to all Learning Algorithms.
Definition: Model.h:82
A specialization of &#39;Model&#39;; meant to Wrap the original version of &#39;SvmModel&#39; class. It will allow us to use the original implementation using version 2.39 of LibSVM.
Definition: ModelOldSVM.h:34
RunLog & Level(kkint32 _level)
Definition: RunLog.cpp:220
Will implement the Dual Classifier Model.
Definition: ModelDual.h:66
KKStr StrFromInt16(kkint16 i)
Definition: KKStr.cpp:5152
void Model::DeAllocateSpace ( )
protected

Definition at line 383 of file Model.cpp.

References classProbs, crossClassProbTable, numOfClasses, and votes.

Referenced by AllocatePredictionVariables(), and ~Model().

384 {
385  kkint32 x = 0;
387  {
388  for (x = 0; x < numOfClasses; x++)
389  {
390  delete [] crossClassProbTable[x];
391  crossClassProbTable[x] = NULL;
392  }
393  delete[] crossClassProbTable;
394  crossClassProbTable = NULL;
395  }
396 
397  delete[] classProbs;
398  classProbs = NULL;
399 
400  delete[] votes;
401  votes = NULL;
402 }
kkint32 * votes
Definition: Model.h:428
__int32 kkint32
Definition: KKBaseTypes.h:88
double * classProbs
Definition: Model.h:394
kkint32 numOfClasses
Definition: Model.h:410
double ** crossClassProbTable
Definition: Model.h:396
KKStr Model::Description ( ) const
virtual

Return short user readable description of model.

Reimplemented in KKMLL::ModelDual, KKMLL::ModelOldSVM, and KKMLL::ModelSvmBase.

Definition at line 248 of file Model.cpp.

References ModelTypeStr(), Name(), and KKB::KKStr::operator+().

Referenced by KKMLL::TrainingProcess2::ModelDescription(), and ProbabilitiesByClassDual().

249 {
250  return ModelTypeStr () + "(" + Name () + ")";
251 }
const KKStr & Name() const
Definition: Model.h:178
virtual KKStr ModelTypeStr() const
Definition: Model.h:176
virtual ModelPtr KKMLL::Model::Duplicate ( ) const
pure virtual
const FeatureEncoder2 & Model::Encoder ( ) const

Definition at line 406 of file Model.cpp.

References encoder, and KKB::KKException::KKException().

407 {
408  if (!encoder)
409  throw KKException ("Model::GetFeatureNums 'encoder == NULL'.");
410  return *encoder;
411 }
FeatureEncoder2Ptr encoder
Definition: Model.h:400
FactoryFVProducerPtr KKMLL::Model::FactoryFVProducer ( ) const
inline

Definition at line 164 of file Model.h.

References factoryFVProducer.

164 {return factoryFVProducer;}
FactoryFVProducerPtr factoryFVProducer
Definition: Model.h:404
FeatureNumListConstPtr Model::GetFeatureNums ( ) const
virtual

Reimplemented in KKMLL::ModelOldSVM.

Definition at line 415 of file Model.cpp.

References KKB::KKException::KKException(), param, and KKMLL::ModelParam::SelectedFeatures().

416 {
417  if (!param)
418  throw KKException ("Model::GetFeatureNums 'param == NULL'.");
419  return param->SelectedFeatures ();
420 }
ModelParamPtr param
Definition: Model.h:412
virtual FeatureNumListConstPtr SelectedFeatures() const
Definition: ModelParam.h:116
kkint32 Model::MemoryConsumedEstimated ( ) const
virtual

Reimplemented in KKMLL::ModelDual, KKMLL::ModelOldSVM, KKMLL::ModelSvmBase, and KKMLL::ModelUsfCasCor.

Definition at line 208 of file Model.cpp.

References classes, classesIndex, classProbs, crossClassProbTable, encoder, KKMLL::FeatureEncoder2::MemoryConsumedEstimated(), KKMLL::ModelParam::MemoryConsumedEstimated(), KKMLL::NormalizationParms::MemoryConsumedEstimated(), KKMLL::MLClassList::MemoryConsumedEstimated(), KKB::KKStr::MemoryConsumedEstimated(), KKMLL::FeatureVectorList::MemoryConsumedEstimated(), KKMLL::MLClassIndexList::MemoryConsumedEstimated(), normParms, numOfClasses, param, rootFileName, trainExamples, votes, and weOwnTrainExamples.

Referenced by KKMLL::ModelSvmBase::MemoryConsumedEstimated(), KKMLL::ModelUsfCasCor::MemoryConsumedEstimated(), KKMLL::ModelOldSVM::MemoryConsumedEstimated(), KKMLL::ModelDual::MemoryConsumedEstimated(), and KKMLL::TrainingProcess2::MemoryConsumedEstimated().

209 {
210  kkint32 memoryConsumedEstimated = sizeof (Model) + rootFileName.MemoryConsumedEstimated ();
211  if (classes) memoryConsumedEstimated += classes->MemoryConsumedEstimated ();
212  if (classesIndex) memoryConsumedEstimated += classesIndex->MemoryConsumedEstimated ();
213  if (classProbs) memoryConsumedEstimated += numOfClasses * sizeof (double);
214  if (crossClassProbTable) memoryConsumedEstimated += (numOfClasses * sizeof (double*) + numOfClasses * numOfClasses * sizeof (double));
215  if (encoder) memoryConsumedEstimated += encoder->MemoryConsumedEstimated ();
216  if (normParms) memoryConsumedEstimated += normParms->MemoryConsumedEstimated ();
217  if (param) memoryConsumedEstimated += param->MemoryConsumedEstimated ();
218  if (votes) memoryConsumedEstimated += numOfClasses * sizeof (kkint32);
219 
220  if (weOwnTrainExamples && (trainExamples != NULL))
221  memoryConsumedEstimated += trainExamples->MemoryConsumedEstimated ();
222 
223  return memoryConsumedEstimated;
224 }
kkint32 MemoryConsumedEstimated() const
kkint32 * votes
Definition: Model.h:428
kkint32 MemoryConsumedEstimated() const
Definition: KKStr.cpp:766
__int32 kkint32
Definition: KKBaseTypes.h:88
virtual kkint32 MemoryConsumedEstimated() const
NormalizationParmsPtr normParms
Definition: Model.h:408
ModelParamPtr param
Definition: Model.h:412
kkint32 MemoryConsumedEstimated() const
FeatureVectorListPtr trainExamples
Definition: Model.h:424
kkint32 MemoryConsumedEstimated() const
Definition: MLClass.cpp:616
KKStr rootFileName
Definition: Model.h:414
double * classProbs
Definition: Model.h:394
kkint32 numOfClasses
Definition: Model.h:410
virtual kkint32 MemoryConsumedEstimated() const
Definition: ModelParam.cpp:87
double ** crossClassProbTable
Definition: Model.h:396
kkint32 MemoryConsumedEstimated() const
Definition: MLClass.cpp:1569
FeatureEncoder2Ptr encoder
Definition: Model.h:400
bool weOwnTrainExamples
Definition: Model.h:430
MLClassIndexListPtr classesIndex
Definition: Model.h:392
MLClassListPtr classes
Definition: Model.h:390
MLClassListPtr KKMLL::Model::MLClasses ( ) const
inline

Definition at line 170 of file Model.h.

References classes.

Referenced by KKMLL::TrainingProcess2::ReadXML().

170 {return classes;}
MLClassListPtr classes
Definition: Model.h:390
MLClassListPtr Model::MLClassesNewInstance ( ) const

Returns a new instances of 'classes' by calling copy constructor.

Definition at line 228 of file Model.cpp.

References classes, and KKMLL::MLClassList::MLClassList().

Referenced by KKMLL::TrainingProcess2::CreateModelsFromTrainingData().

229 {
230  if (classes)
231  return new MLClassList (*classes);
232  else
233  return NULL;
234 } /* MLClassesNewInstance */
Maintains a list of MLClass instances.
Definition: MLClass.h:233
MLClassListPtr classes
Definition: Model.h:390
Model::ModelTypes Model::ModelTypeFromStr ( const KKStr _modelingTypeStr)
static

Definition at line 271 of file Model.cpp.

References Dual, KKB::KKStr::EqualIgnoreCase(), KNN, Null, OldSVM, SvmBase, and UsfCasCor.

Referenced by KKMLL::TrainingConfiguration2::ModelTypeFromStr(), and ReadXMLModelToken().

272 {
273  if (_modelingTypeStr.EqualIgnoreCase ("OldSVM") ||
274  _modelingTypeStr.EqualIgnoreCase ("One_Level")) return ModelTypes::OldSVM;
275  else if (_modelingTypeStr.EqualIgnoreCase ("SvmBase")) return ModelTypes::SvmBase;
276  else if (_modelingTypeStr.EqualIgnoreCase ("KNN")) return ModelTypes::KNN;
277  else if (_modelingTypeStr.EqualIgnoreCase ("UsfCasCor")) return ModelTypes::UsfCasCor;
278  else if (_modelingTypeStr.EqualIgnoreCase ("Dual")) return ModelTypes::Dual;
279 
280  else
281  return ModelTypes::Null;
282 } /* ModelingMethodFromStr */
bool EqualIgnoreCase(const KKStr &s2) const
Definition: KKStr.cpp:1250
virtual KKStr KKMLL::Model::ModelTypeStr ( ) const
inlinevirtual

Definition at line 176 of file Model.h.

References ModelType(), and ModelTypeToStr().

Referenced by Description(), KKMLL::TrainingProcess2::ModelTypeStr(), ReadXMLModelToken(), and WriteModelXMLFields().

176 {return ModelTypeToStr (ModelType ());}
static KKStr ModelTypeToStr(ModelTypes _modelingType)
Definition: Model.cpp:256
virtual ModelTypes ModelType() const =0
KKStr Model::ModelTypeToStr ( ModelTypes  _modelingType)
static

Definition at line 256 of file Model.cpp.

References Dual, KNN, Null, OldSVM, SvmBase, and UsfCasCor.

Referenced by ModelTypeStr(), KKMLL::TrainingConfiguration2::ModelTypeStr(), and KKMLL::TrainingConfiguration2::ModelTypeToStr().

257 {
258  if (_modelingType == ModelTypes::Null) return "NULL";
259  else if (_modelingType == ModelTypes::OldSVM) return "OldSVM";
260  else if (_modelingType == ModelTypes::SvmBase) return "SvmBase";
261  else if (_modelingType == ModelTypes::KNN) return "KNN";
262  else if (_modelingType == ModelTypes::UsfCasCor) return "UsfCasCor";
263  else if (_modelingType == ModelTypes::Dual) return "Dual";
264  else
265  return "NULL";
266 } /* ModelingMethodToStr */
const KKStr& KKMLL::Model::Name ( ) const
inline
void KKMLL::Model::Name ( const KKStr _name)
inline

Definition at line 179 of file Model.h.

References KKB::KKStr::operator=().

179 {name = _name;}
bool Model::NormalizeNominalAttributes ( ) const
virtual

Return true, if nominal fields need to be normalized.

Reimplemented in KKMLL::ModelOldSVM.

Definition at line 423 of file Model.cpp.

References KKMLL::ModelParam::EncodingMethod(), KKB::KKException::KKException(), KKMLL::ModelParam::NoEncoding, and param.

424 {
425  if (!param)
426  throw KKException ("Model::NormalizeNominalAttributes 'param == NULL'.");
427 
429  return true;
430  else
431  return false;
432 } /* NormalizeNominalAttributes */
ModelParamPtr param
Definition: Model.h:412
virtual EncodingMethodType EncodingMethod() const
Definition: ModelParam.h:111
void Model::NormalizeProbabilitiesWithAMinumum ( kkint32  numClasses,
double *  probabilities,
double  minProbability 
)
protected

Will normalize probabilities such that the sum of all equal 1.0 and no one probability will be less than 'minProbability'.

Definition at line 614 of file Model.cpp.

618 {
619  double sumGreaterOrEqualMin = 0.0;
620  kkint32 numLessThanMin = 0;
621 
622  kkint32 x = 0;
623  for (x = 0; x < numClasses; ++x)
624  {
625  if (probabilities[x] < minProbability)
626  ++numLessThanMin;
627  else
628  sumGreaterOrEqualMin += probabilities[x];
629  }
630 
631  double probLessMinTotal = numLessThanMin * minProbability;
632  double probLeftToAllocate = 1.0 - probLessMinTotal;
633 
634  for (x = 0; x < numClasses; ++x)
635  {
636  if (probabilities[x] < minProbability)
637  probabilities[x] = minProbability;
638  else
639  probabilities[x] = (probabilities[x] / sumGreaterOrEqualMin) * probLeftToAllocate;
640  }
641 } /* NormalizeProbabilitiesWithAMinumum */
__int32 kkint32
Definition: KKBaseTypes.h:88
ModelParamPtr KKMLL::Model::Param ( ) const
inline

Definition at line 183 of file Model.h.

References param.

Referenced by KKMLL::TrainingProcess2::Parameters().

183 {return param;}
ModelParamPtr param
Definition: Model.h:412
virtual MLClassPtr KKMLL::Model::Predict ( FeatureVectorPtr  example,
RunLog log 
)
pure virtual
virtual void KKMLL::Model::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 
)
pure virtual
virtual void KKMLL::Model::PredictRaw ( FeatureVectorPtr  example,
MLClassPtr predClass,
double &  dist 
)
inlinevirtual

Reimplemented in KKMLL::ModelOldSVM.

Definition at line 230 of file Model.h.

Referenced by KKMLL::Classifier2::PredictRaw().

234  {
235  predClass = NULL;
236  dist = 0.0;
237  }
FeatureVectorPtr Model::PrepExampleForPrediction ( FeatureVectorPtr  fv,
bool &  newExampleCreated 
)
virtual

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.

Parameters
[in]fvFeature vector of example that needs to be prepared.
[out]newExampleCreatedIndicates if either Feature Encoding and/or Normalization needed to be done. If neither then the original instance is returned. If Yes then a new instance which the caller will have to delete will be returned.
[in]fvFeature vector of example that needs to be prepared.
[out]newExampleCreatedIndicates if either Feature Encoding and/or Normalization needed to be done. If neither then the original instance is returned. If Yes then a new instance which the caller will have to be delete will be returned.

Reimplemented in KKMLL::ModelOldSVM.

Definition at line 574 of file Model.cpp.

References alreadyNormalized, KKMLL::FeatureEncoder2::EncodeAExample(), encoder, normParms, and KKMLL::NormalizationParms::ToNormalized().

Referenced by KKMLL::ModelSvmBase::Predict(), KKMLL::ModelUsfCasCor::Predict(), KKMLL::ModelDual::Predict(), KKMLL::ModelKnn::ProbabilitiesByClass(), KKMLL::ModelSvmBase::ProbabilitiesByClass(), KKMLL::ModelUsfCasCor::ProbabilitiesByClass(), and KKMLL::ModelDual::ProbabilitiesByClassDual().

577 {
578  FeatureVectorPtr oldFV = NULL;
579  newExampleCreated = false;
580  if ((!alreadyNormalized) && (normParms))
581  {
582  oldFV = fv;
583  fv = normParms->ToNormalized (fv);
584  if (newExampleCreated)
585  {
586  delete oldFV;
587  oldFV = NULL;
588  }
589  newExampleCreated = true;
590  }
591 
592  // I do not believe we need the encoder at this point. At least not for the Features Selected part. Maybe the conversion from minimal fields will make sense.
593  if (encoder)
594  {
595  oldFV = fv;
596  fv = encoder->EncodeAExample (fv);
597  if (newExampleCreated)
598  {
599  delete oldFV;
600  oldFV = NULL;
601  }
602  newExampleCreated = true;
603  }
604 
605  return fv;
606 } /* PrepExampleForPrediction */
bool alreadyNormalized
Definition: Model.h:388
NormalizationParmsPtr normParms
Definition: Model.h:408
FeatureVectorPtr ToNormalized(FeatureVectorPtr example) const
Represents a Feature Vector of a single example, labeled or unlabeled.
Definition: FeatureVector.h:59
FeatureEncoder2Ptr encoder
Definition: Model.h:400
FeatureVectorPtr EncodeAExample(FeatureVectorPtr src) const
virtual ClassProbListPtr KKMLL::Model::ProbabilitiesByClass ( FeatureVectorPtr  example,
RunLog log 
)
pure virtual
virtual void KKMLL::Model::ProbabilitiesByClass ( FeatureVectorPtr  example,
const MLClassList _mlClasses,
kkint32 _votes,
double *  _probabilities,
RunLog _log 
)
pure virtual
virtual void KKMLL::Model::ProbabilitiesByClass ( FeatureVectorPtr  _example,
const MLClassList _mlClasses,
double *  _probabilities,
RunLog _log 
)
pure 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 of 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. The ordering of this list will dictate the order that '_probabilities' will be populated.
[out]_probabilitiesAn array that must be as big as the number of classes in '_mlClasses'. The probability of class in '_mlClasses[x]' will be returned in probabilities[x].

Implemented in KKMLL::ModelDual, KKMLL::ModelOldSVM, KKMLL::ModelUsfCasCor, KKMLL::ModelSvmBase, and KKMLL::ModelKnn.

void Model::ProbabilitiesByClassDual ( FeatureVectorPtr  example,
KKStr classifier1Desc,
KKStr classifier2Desc,
ClassProbListPtr classifier1Results,
ClassProbListPtr classifier2Results,
RunLog log 
)
virtual

Only applied to ModelDual classifier.

Reimplemented in KKMLL::ModelDual.

Definition at line 830 of file Model.cpp.

References KKMLL::ClassProbList::ClassProbList(), Description(), KKB::KKStr::operator=(), and ProbabilitiesByClass().

Referenced by KKMLL::Classifier2::ProbabilitiesByClassDual().

837 {
838  delete classifier1Results; classifier1Results = NULL;
839  delete classifier2Results; classifier2Results = NULL;
840 
841  classifier1Desc = Description ();
842  classifier2Desc = Description ();
843 
844  classifier1Results = ProbabilitiesByClass (example, log);
845  if (classifier1Results)
846  classifier2Results = new ClassProbList (*classifier1Results);
847 } /* ProbabilitiesByClassDual */
virtual ClassProbListPtr ProbabilitiesByClass(FeatureVectorPtr example, RunLog &log)=0
virtual KKStr Description() const
Definition: Model.cpp:248
virtual void KKMLL::Model::ReadXML ( XmlStream s,
XmlTagConstPtr  tag,
VolConstBool cancelFlag,
RunLog log 
)
pure virtual

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

Implemented in KKMLL::ModelOldSVM, KKMLL::ModelDual, KKMLL::ModelSvmBase, KKMLL::ModelUsfCasCor, and KKMLL::ModelKnn.

void Model::ReadXMLModelPost ( RunLog log)
protected

Definition at line 987 of file Model.cpp.

References AddErrorMsg(), classes, KKB::KKStr::Concat(), fileDesc, param, and KKMLL::ModelParam::ValidParam().

Referenced by KKMLL::ModelKnn::ReadXML(), KKMLL::ModelUsfCasCor::ReadXML(), KKMLL::ModelSvmBase::ReadXML(), KKMLL::ModelDual::ReadXML(), and KKMLL::ModelOldSVM::ReadXML().

988 {
989  if (!param)
990  {
991  KKStr errMsg = "Model::ReadXMLModelPost ***ERROR*** 'param' not defined.";
992  AddErrorMsg (errMsg, 0);
993  log.Level (-1) << endl << errMsg << endl << endl;
994  }
995 
996  else if (!param->ValidParam ())
997  {
998  KKStr errMsg = "Model::ReadXMLModelPost ***ERROR*** 'Param' is NOT Valid .";
999  AddErrorMsg (errMsg, 0);
1000  log.Level (-1) << endl << errMsg << endl << endl;
1001  }
1002 
1003  if (!classes)
1004  {
1005  KKStr errMsg = "Model::ReadXMLModelPost ***ERROR*** 'classes' not defined.";
1006  AddErrorMsg (errMsg, 0);
1007  log.Level (-1) << endl << errMsg << endl << endl;
1008  }
1009 
1010  if (!fileDesc)
1011  {
1012  KKStr errMsg = "Model::ReadXMLModelPost ***ERROR*** 'fileDesc' not defined.";
1013  AddErrorMsg (errMsg, 0);
1014  log.Level (-1) << endl << errMsg << endl << endl;
1015  }
1016 
1017  if (errors.size () > 0)
1018  {
1019  log.Level (-1) << "Model::ReadXMLModelPost Errors were detected; model is INVALID." << endl;
1020  validModel = false;
1021  }
1022  else
1023  {
1025  }
1026 
1027 } /* ReadXMLModelPost */
HTMLReport &__cdecl endl(HTMLReport &htmlReport)
Definition: HTMLReport.cpp:240
ModelParamPtr param
Definition: Model.h:412
void AddErrorMsg(const KKStr &errMsg, kkint32 lineNum)
Definition: Model.cpp:239
RunLog & Level(kkint32 _level)
Definition: RunLog.cpp:220
bool validModel
Definition: Model.h:426
VectorKKStr errors
Definition: Model.h:402
FileDescPtr fileDesc
Definition: Model.h:406
MLClassListPtr classes
Definition: Model.h:390
virtual bool ValidParam() const
Definition: ModelParam.h:117
void AllocatePredictionVariables()
Definition: Model.cpp:343
XmlTokenPtr Model::ReadXMLModelToken ( XmlTokenPtr  t,
RunLog log 
)
protected

Will process any tokens that belong to 'ModelParam' and return NULL ones that are not will be passed back.

Definition at line 884 of file Model.cpp.

References AddErrorMsg(), classes, KKB::KKStr::Concat(), KKB::KKStr::EqualIgnoreCase(), KKB::KKStr::KKStr(), ModelType(), ModelTypeFromStr(), ModelTypeStr(), KKB::KKStr::operator=(), rootFileName, KKMLL::XmlElementMLClassNameList::TakeOwnership(), KKB::XmlToken::tokElement, KKB::XmlToken::TokenType(), KKB::XmlElement::ToKKStr(), KKB::XmlToken::VarName(), and KKB::XmlElement::VarName().

Referenced by KKMLL::ModelKnn::ReadXML(), KKMLL::ModelUsfCasCor::ReadXML(), KKMLL::ModelSvmBase::ReadXML(), KKMLL::ModelDual::ReadXML(), and KKMLL::ModelOldSVM::ReadXML().

887 {
888  const KKStr& varName = t->VarName ();
889  if (t->TokenType () == XmlToken::TokenTypes::tokElement)
890  {
891  bool tokenFound = true;
892 
893  XmlElementPtr e = dynamic_cast<XmlElementPtr> (t);
894 
895  const KKStr& varName = e->VarName ();
896 
897  if (varName.EqualIgnoreCase ("ModelType"))
898  {
899  if (ModelType () != Model::ModelTypeFromStr (e->ToKKStr ()))
900  {
901  KKStr errMsg (128);
902  errMsg << "Model::ReadXMLModelToken ***ERROR*** Wrong ModelType encountered; Expected[" << ModelTypeStr () << "] "
903  << "ModelType Specified[" << e->ToKKStr () << "].";
904 
905  log.Level (-1) << endl << errMsg << endl << endl;
906  AddErrorMsg (errMsg, 0);
907  }
908  }
909 
910  else if (varName.EqualIgnoreCase ("Name"))
911  name = e->ToKKStr ();
912 
913  else if (varName.EqualIgnoreCase ("RootFileName"))
914  rootFileName = e->ToKKStr ();
915 
916  else if ((varName.EqualIgnoreCase ("Classes")) && (typeid(*e) == typeid (XmlElementMLClassNameList)))
917  {
918  delete classes;
919  classes = dynamic_cast<XmlElementMLClassNameListPtr> (t)->TakeOwnership ();
920  }
921 
922  else if (varName.EqualIgnoreCase ("ClassesIndex") && (typeid(*e) == typeid (XmlElementMLClassIndexList)))
923  {
924  delete classesIndex;
925  classesIndex = dynamic_cast<XmlElementMLClassIndexListPtr>(t)->TakeOwnership ();
926  }
927 
928  else if (varName.EqualIgnoreCase ("FvFactoryProducer"))
929  {
931  }
932 
933  else if (varName.EqualIgnoreCase ("FileDesc") && (typeid(*e) == typeid (XmlElementFileDesc)))
934  {
935  fileDesc = dynamic_cast<XmlElementFileDescPtr>(t)->Value ();
936  }
937 
938  else if (varName.EqualIgnoreCase ("Param"))
939  {
940  XmlElementModelParamPtr xmlParameterElement = dynamic_cast<XmlElementModelParamPtr> (e);
941  if (xmlParameterElement)
942  {
943  delete param;
944  param = xmlParameterElement->TakeOwnership ();
945  }
946  else
947  {
948  KKStr errMsg (128);
949  errMsg << "Model::ReadXMLModelToken ***ERROR*** ModelParam variable 'param' not defined correctly.";
950  log.Level (-1) << endl << errMsg << endl << endl;
951  AddErrorMsg (errMsg, 0);
952  }
953  }
954 
955  else if (varName.EqualIgnoreCase ("TimeSaved"))
956  timeSaved = DateTime (e->ToKKStr ());
957 
958  else if (varName.EqualIgnoreCase ("TrainingTime"))
959  trainingTime = e->ToDouble ();
960 
961  else if (varName.EqualIgnoreCase ("AlreadyNormalized"))
962  alreadyNormalized = e->ToBool ();
963 
964  else if ((varName.EqualIgnoreCase ("NormParms")) && (typeid (*e) == typeid (XmlElementNormalizationParms)))
965  {
966  delete normParms;
967  normParms = dynamic_cast<XmlElementNormalizationParmsPtr> (e)->TakeOwnership ();
968  }
969 
970  else
971  {
972  tokenFound = false;
973  }
974 
975  if (tokenFound)
976  {
977  delete t;
978  t = NULL;
979  }
980  }
981 
982  return t;
983 } /* ReadXMLModelToken */
HTMLReport &__cdecl endl(HTMLReport &htmlReport)
Definition: HTMLReport.cpp:240
virtual double ToDouble() const
Definition: XmlStream.h:315
bool alreadyNormalized
Definition: Model.h:388
virtual KKStr ToKKStr() const
Definition: XmlStream.h:314
NormalizationParmsPtr normParms
Definition: Model.h:408
ModelParamPtr param
Definition: Model.h:412
void AddErrorMsg(const KKStr &errMsg, kkint32 lineNum)
Definition: Model.cpp:239
static FactoryFVProducerPtr LookUpFactory(const KKStr &name)
Returns pointer to existing instance of &#39;FactoryFVProducer&#39; that was previously registered with &#39;name...
KKStr rootFileName
Definition: Model.h:414
FactoryFVProducerPtr factoryFVProducer
Definition: Model.h:404
static ModelTypes ModelTypeFromStr(const KKStr &_modelingTypeStr)
Definition: Model.cpp:271
bool EqualIgnoreCase(const KKStr &s2) const
Definition: KKStr.cpp:1250
RunLog & Level(kkint32 _level)
Definition: RunLog.cpp:220
XmlElementTemplate< MLClassIndexList > XmlElementMLClassIndexList
Definition: MLClass.h:606
virtual ModelParam * TakeOwnership()
Definition: ModelParam.h:237
virtual bool ToBool() const
Definition: XmlStream.h:313
XmlElementTemplate< NormalizationParms > XmlElementNormalizationParms
virtual const KKStr & VarName() const
Definition: XmlStream.cpp:794
virtual ModelTypes ModelType() const =0
FileDescPtr fileDesc
Definition: Model.h:406
virtual KKStr ModelTypeStr() const
Definition: Model.h:176
virtual TokenTypes TokenType()=0
Base class to be used by all ModelParam derived objects.
Definition: ModelParam.h:212
Will only write the ClassName rather than complete MLClass instances.
Definition: MLClass.h:580
virtual const KKStr & VarName() const
Definition: XmlStream.h:269
MLClassIndexListPtr classesIndex
Definition: Model.h:392
MLClassListPtr classes
Definition: Model.h:390
void Model::ReduceTrainExamples ( RunLog log)
protected

Reduces the Training Images down to the size dictated by the 'examplesPerClass' parameter.

Definition at line 649 of file Model.cpp.

References KKMLL::ModelParam::ExamplesPerClass(), KKMLL::FeatureVectorList::ExtractExamplesForAGivenClass(), KKMLL::FeatureVectorList::GetClassStatistics(), KKMLL::FeatureVectorList::ManufactureEmptyList(), param, trainExamples, validModel, and weOwnTrainExamples.

Referenced by TrainModel().

650 {
651  kkint32 examplesPerClass = param->ExamplesPerClass ();
652  kkuint32 zed = 0;
653 
654  if (examplesPerClass < 0)
655  examplesPerClass = int32_max;
656 
657  bool reductionNeeded = false;
658 
659  {
660  // First lets see if reduction is even necessary.
662  if (!stats)
663  {
664  log.Level (-1) << endl
665  << "Model::ReduceTrainExamples ***ERROR*** can not retrieve Class Stat's for training data." << endl
666  << endl;
667  validModel = false;
668  return;
669  }
670 
671  for (zed = 0; (zed < stats->size ()) && (!reductionNeeded); zed++)
672  {
673  if (stats->IdxToPtr (zed)->Count () > (kkuint32)examplesPerClass)
674  reductionNeeded = true;
675  }
676 
677  delete stats;
678  stats = NULL;
679  }
680 
681  if (!reductionNeeded)
682  {
683  log.Level (20) << "Model::ReduceTrainExamples Was not needed. No classes exceeded 'examplesPerClass'." << endl;
684  return;
685  }
686 
688  FeatureVectorListPtr deleteSet = trainExamples->ManufactureEmptyList (false); // Examples that we do not use will need to be deleted.
690 
691  for (idx = classes->begin (); idx != classes->end (); idx++)
692  {
693  MLClassPtr ic = *idx;
695  if ((!examplesThisClass) || (examplesThisClass->size () < 1))
696  {
697  log.Level (-1) << endl
698  << "Model::ReduceTrainExamples ***ERROR*** No Training Examples for class[" << ic->Name () << "]." << endl
699  << endl;
700  continue;
701  }
702 
703  if (examplesThisClass->size () <= (kkuint32)examplesPerClass)
704  {
705  reducedSet->AddQueue (*examplesThisClass);
706  }
707  else
708  {
709  examplesThisClass->RandomizeOrder ();
710  zed = 0;
711  while (zed < (kkuint32)examplesPerClass)
712  {
713  reducedSet->PushOnBack (examplesThisClass->IdxToPtr (zed));
714  zed++;
715  }
716  while (zed < examplesThisClass->size ())
717  {
718  deleteSet->PushOnBack (examplesThisClass->IdxToPtr (zed));
719  zed++;
720  }
721  }
722 
723  delete examplesThisClass;
724  examplesThisClass = NULL;
725  }
726 
727  if (weOwnTrainExamples)
728  {
729  trainExamples->Owner (false);
730  delete trainExamples;
731  trainExamples = reducedSet;
732  reducedSet = NULL;
733 
734  trainExamples->Owner (true);
735  deleteSet->Owner (true);
736  delete deleteSet;
737  deleteSet = NULL;
738  }
739  else
740  {
741  // Since we are replacing 'trainExamples' with 'reducedSet' we will now own 'trainExamples' but not its contents.
742  reducedSet->Owner (false);
743  weOwnTrainExamples = true;
744  trainExamples = reducedSet;
745  reducedSet = NULL;
746  deleteSet->Owner (false);
747  delete deleteSet;
748  deleteSet = NULL;
749  }
750 } /* ReduceTrainExamples */
HTMLReport &__cdecl endl(HTMLReport &htmlReport)
Definition: HTMLReport.cpp:240
void PushOnBack(FeatureVectorPtr image)
Overloading the PushOnBack function in KKQueue so we can monitor the Version and Sort Order...
void AddQueue(const FeatureVectorList &examplesToAdd)
Add the contents of &#39;examplesToAdd&#39; to the end of this list.
std::vector< MLClass * >::iterator iterator
Definition: KKQueue.h:88
__int32 kkint32
Definition: KKBaseTypes.h:88
ModelParamPtr param
Definition: Model.h:412
FeatureVectorListPtr trainExamples
Definition: Model.h:424
Represents a "Class" in the Machine Learning Sense.
Definition: MLClass.h:52
EntryPtr IdxToPtr(kkuint32 idx) const
Definition: KKQueue.h:732
virtual FeatureVectorListPtr ManufactureEmptyList(bool _owner) const
Creates an instance of a Empty FeatureVectorList.
unsigned __int32 kkuint32
Definition: KKBaseTypes.h:89
RunLog & Level(kkint32 _level)
Definition: RunLog.cpp:220
bool Owner() const
Definition: KKQueue.h:305
Container class for FeatureVector derived objects.
kkuint32 Count() const
FeatureVectorListPtr ExtractExamplesForAGivenClass(MLClassPtr _mlClass, kkint32 _maxToExtract=-1, float _minSize=-1.0f) const
bool validModel
Definition: Model.h:426
ClassStatisticListPtr GetClassStatistics() const
Returns the number of FeatureVectors per class.
void RandomizeOrder()
Randomizes the order of the vector.
Definition: KKQueue.h:469
bool weOwnTrainExamples
Definition: Model.h:430
#define int32_max
Definition: KKBaseTypes.h:119
virtual kkint32 ExamplesPerClass() const
Definition: ModelParam.h:113
MLClassListPtr classes
Definition: Model.h:390
void Model::RetrieveCrossProbTable ( MLClassList classes,
double **  crossProbTable,
RunLog log 
)
virtual
Parameters
crossProbTabletwo dimension matrix that needs to be classes.QueueSize () squared.

Reimplemented in KKMLL::ModelOldSVM, KKMLL::ModelDual, and KKMLL::ModelSvmBase.

Definition at line 755 of file Model.cpp.

References crossClassProbTable.

Referenced by KKMLL::Classifier2::RetrieveCrossProbTable().

759 {
760  if (classes.QueueSize () != crossClassProbTableSize)
761  {
762  // There Class List does not have the same number of entries as our 'CrossProbTable'
763  log.Level (-1) << endl
764  << "SVMModel::RetrieveCrossProbTable ***ERROR***" << endl
765  << " classes.QueueSize ()[" << classes.QueueSize () << "] != crossClassProbTableSize[" << crossClassProbTableSize << "]" << endl
766  << endl;
767  return;
768  }
769 
770  kkint32* indexTable = new kkint32[classes.QueueSize ()];
771  kkint32 x, y;
772  for (x = 0; x < classes.QueueSize (); x++)
773  {
774  for (y = 0; y < classes.QueueSize (); y++)
775  crossClassProbTable[x][y] = 0.0;
776 
777  indexTable[x] = classesIndex->GetClassIndex (classes.IdxToPtr (x));
778  if (indexTable[x] < 0)
779  {
780  log.Level (-1) << endl
781  << "SVMModel::RetrieveCrossProbTable ***WARNING***" << endl
782  << endl
783  << " Class Index[" << x << "] Name[" << classes[x].Name () << "]" << endl
784  << " will populate this index with zeros." << endl
785  << endl;
786  }
787  }
788 
789  if (classes.QueueSize () != crossClassProbTableSize)
790  {
791  log.Level (-1) << endl
792  << "SVMModel::RetrieveCrossProbTable ***ERROR***" << endl
793  << " 'classes.QueueSize () != crossClassProbTableSize'" << endl
794  << endl;
795  return;
796  }
797 
798 
799  // x,y = 'Callers' Class Indexes..
800  // xIdx, yIdx = 'SVMNodel' Class Indexed.
801  for (x = 0; x < classes.QueueSize (); x++)
802  {
803  kkint32 xIdx = indexTable[x];
804  if (xIdx >= 0)
805  {
806  for (y = 0; y < classes.QueueSize (); y++)
807  {
808  kkint32 yIdx = indexTable[y];
809  if (yIdx >= 0)
810  {
811  if ((x != xIdx) || (y != yIdx))
812  {
813  //kak I just added this check to see when this situation actually occurs.
814  kkint32 zed = 111;
815  }
816 
817  crossClassProbTable[x][y] = this->crossClassProbTable[xIdx][yIdx];
818  }
819  }
820  }
821  }
822 
823  delete[] indexTable; indexTable = NULL;
824  return;
825 } /* 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
EntryPtr IdxToPtr(kkuint32 idx) const
Definition: KKQueue.h:732
RunLog & Level(kkint32 _level)
Definition: RunLog.cpp:220
double ** crossClassProbTable
Definition: Model.h:396
kkint32 QueueSize() const
Definition: KKQueue.h:313
kkint32 crossClassProbTableSize
Definition: Model.h:398
MLClassIndexListPtr classesIndex
Definition: Model.h:392
const KKStr& KKMLL::Model::RootFileName ( ) const
inline

Definition at line 187 of file Model.h.

References rootFileName.

187 {return rootFileName;}
KKStr rootFileName
Definition: Model.h:414
void KKMLL::Model::RootFileName ( const KKStr _rootFileName)
inline

Definition at line 199 of file Model.h.

References KKB::KKStr::operator=(), and rootFileName.

199 {rootFileName = _rootFileName;}
KKStr rootFileName
Definition: Model.h:414
FeatureNumListConstPtr Model::SelectedFeatures ( ) const
virtual

Definition at line 436 of file Model.cpp.

References KKB::KKException::KKException(), param, and KKMLL::ModelParam::SelectedFeatures().

Referenced by KKMLL::ModelUsfCasCor::TrainModel().

437 {
438  if (!param)
439  throw KKException ("Model::GetFeatureNums 'param'.");
440  return param->SelectedFeatures ();
441 }
ModelParamPtr param
Definition: Model.h:412
virtual FeatureNumListConstPtr SelectedFeatures() const
Definition: ModelParam.h:116
const KKB::DateTime& KKMLL::Model::TimeSaved ( ) const
inline

Definition at line 189 of file Model.h.

189 {return timeSaved;}
double KKMLL::Model::TrainingTime ( ) const
inline

Definition at line 191 of file Model.h.

Referenced by KKMLL::TrainingProcess2::TrainingTime().

191 {return trainingTime;}
void Model::TrainingTimeEnd ( )

Derived classes call this method to stop the clock for 'trainingTime'.

Definition at line 452 of file Model.cpp.

References KKB::osGetSystemTimeUsed().

Referenced by KKMLL::ModelUsfCasCor::TrainModel(), KKMLL::ModelSvmBase::TrainModel(), KKMLL::ModelDual::TrainModel(), and KKMLL::ModelOldSVM::TrainModel().

453 {
454  double trainingTimeEnd = osGetSystemTimeUsed ();
455  trainingTime = trainingTimeEnd - trainingTimeStart;
456  if (trainingTime < 0.0)
457  trainingTime += (24.0 * 60.0 * 60.0);
458 }
double osGetSystemTimeUsed()
Returns the number of CPU seconds used by current process.
void Model::TrainingTimeStart ( )

Derived classes call this method to start the clock for 'trainingTime'.

Definition at line 445 of file Model.cpp.

References KKB::osGetSystemTimeUsed().

Referenced by KKMLL::ModelUsfCasCor::TrainModel(), KKMLL::ModelSvmBase::TrainModel(), KKMLL::ModelDual::TrainModel(), and KKMLL::ModelOldSVM::TrainModel().

446 {
447  trainingTimeStart = osGetSystemTimeUsed ();
448 }
double osGetSystemTimeUsed()
Returns the number of CPU seconds used by current process.
void Model::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
_takeOwnershipTrue = Model will take ownership of these examples

Reimplemented in KKMLL::ModelOldSVM, KKMLL::ModelDual, KKMLL::ModelSvmBase, KKMLL::ModelUsfCasCor, and KKMLL::ModelKnn.

Definition at line 467 of file Model.cpp.

References AllocatePredictionVariables(), alreadyNormalized, classes, classesIndex, KKB::KKStr::Concat(), KKMLL::FeatureVectorList::Duplicate(), KKMLL::FeatureEncoder2::EncodeAllExamples(), encoder, KKMLL::ModelParam::EncodingMethod(), KKMLL::ModelParam::ExamplesPerClass(), KKMLL::FeatureVectorList::ExtractListOfClasses(), KKMLL::FeatureEncoder2::FeatureEncoder2(), fileDesc, KKB::KKException::KKException(), KKMLL::MLClassIndexList::MLClassIndexList(), KKMLL::ModelParam::NoEncoding, KKMLL::NormalizationParms::NormalizationParms(), KKMLL::NormalizationParms::NormalizeExamples(), normParms, KKMLL::ModelParam::Null, KKB::osGetSystemTimeUsed(), param, ReduceTrainExamples(), KKMLL::MLClassList::SortByName(), trainExamples, and weOwnTrainExamples.

Referenced by KKMLL::TrainingProcess2::CreateModelsFromTrainingData(), KKMLL::ModelKnn::TrainModel(), KKMLL::ModelUsfCasCor::TrainModel(), KKMLL::ModelSvmBase::TrainModel(), KKMLL::ModelDual::TrainModel(), and KKMLL::ModelOldSVM::TrainModel().

473 {
474  _log.Level (10) << "Model::TrainModel Preparing for training of Model[" << Name () << "] Examples[" << _trainExamples->QueueSize () << "]" << endl;
475 
476  double prepStartTime = osGetSystemTimeUsed ();
477 
478  if (_trainExamples == NULL)
479  {
480  KKStr errMsg = "ModelSvmBase::TrainModel (_trainExamples == NULL)";
481  _log.Level (-1) << endl << endl << errMsg << endl << endl;
482  throw KKException (errMsg);
483  }
484 
485  if (_trainExamples->QueueSize () < 2)
486  {
487  KKStr errMsg = "ModelSvmBase::TrainModel (_trainExamples == NULL)";
488  _log.Level (-1) << endl << endl << errMsg << endl << endl;
489  throw KKException (errMsg);
490  }
491 
492  weOwnTrainExamples = _takeOwnership;
493  trainExamples = _trainExamples;
494  alreadyNormalized = _alreadyNormalized;
495  _trainExamples = NULL;
496 
497  delete classes;
499  classes->SortByName ();
500 
501  delete classesIndex;
503 
504  if (param->ExamplesPerClass () < int32_max)
505  ReduceTrainExamples (_log);
506 
507  if (!_alreadyNormalized)
508  {
509  if (!weOwnTrainExamples)
510  {
511  // Since we do not own the WE will have to duplicate the trainExamples list and its contents before we normalize the data.
513  weOwnTrainExamples = true;
514  trainExamples = temp;
515  }
516  else if (!trainExamples->Owner ())
517  {
518  // Even though we own 'trainExamples' we do not own its contents; so we will need to create a new list and own those contents.
520  weOwnTrainExamples = true;
521  delete trainExamples;
522  trainExamples = temp;
523  }
524  delete normParms;
527  }
528 
530  {
531  // There is nothing for us to do.
532  return;
533  }
534 
536  {
537  if (!encoder)
539 
541  if (weOwnTrainExamples)
542  {
543  delete trainExamples;
544  trainExamples = NULL;
545  }
546 
547  trainExamples = encodedImages;
548  weOwnTrainExamples = true;
549  }
550 
552 
553  double prepEndTime = osGetSystemTimeUsed ();
554  trianingPrepTime = prepEndTime - prepStartTime;
555  if (trianingPrepTime < 0.0)
556  trianingPrepTime += (24.0 * 60.0 * 60.0);
557 
558  _log.Level (40) << "Model::TrainModel Exiting." << endl;
559 } /* TrainModel */
const KKStr & Name() const
Definition: Model.h:178
HTMLReport &__cdecl endl(HTMLReport &htmlReport)
Definition: HTMLReport.cpp:240
void NormalizeExamples(FeatureVectorListPtr examples, RunLog &log)
bool alreadyNormalized
Definition: Model.h:388
Maintains a list of classes and their associated integer index.
Definition: MLClass.h:459
virtual FeatureVectorListPtr Duplicate(bool _owner) const
Creates a duplicate of list using the same container.
NormalizationParmsPtr normParms
Definition: Model.h:408
ModelParamPtr param
Definition: Model.h:412
MLClassListPtr ExtractListOfClasses() const
FeatureVectorListPtr trainExamples
Definition: Model.h:424
virtual EncodingMethodType EncodingMethod() const
Definition: ModelParam.h:111
RunLog & Level(kkint32 _level)
Definition: RunLog.cpp:220
bool Owner() const
Definition: KKQueue.h:305
Container class for FeatureVector derived objects.
void ReduceTrainExamples(RunLog &log)
Reduces the Training Images down to the size dictated by the &#39;examplesPerClass&#39; parameter.
Definition: Model.cpp:649
double osGetSystemTimeUsed()
Returns the number of CPU seconds used by current process.
FileDescPtr fileDesc
Definition: Model.h:406
kkint32 QueueSize() const
Definition: KKQueue.h:313
Normalization Parameters; calculation and implementation.
FeatureEncoder2Ptr encoder
Definition: Model.h:400
bool weOwnTrainExamples
Definition: Model.h:430
#define int32_max
Definition: KKBaseTypes.h:119
virtual kkint32 ExamplesPerClass() const
Definition: ModelParam.h:113
MLClassIndexListPtr classesIndex
Definition: Model.h:392
FeatureVectorListPtr EncodeAllExamples(const FeatureVectorListPtr srcData)
MLClassListPtr classes
Definition: Model.h:390
void AllocatePredictionVariables()
Definition: Model.cpp:343
double KKMLL::Model::TrianingPrepTime ( ) const
inline

Definition at line 193 of file Model.h.

193 {return trianingPrepTime;} //*< Time ins sec's spent preparing training data in Model::TrainModel */
bool KKMLL::Model::ValidModel ( ) const
inline
void Model::WriteModelXMLFields ( std::ostream &  o) const

The "WriteXML" method in Derived classes call this method to include the parents classes fields in the XML data.

Definition at line 854 of file Model.cpp.

References alreadyNormalized, classes, classesIndex, fileDesc, ModelTypeStr(), Name(), normParms, param, rootFileName, KKMLL::NormalizationParms::WriteXML(), KKMLL::ModelParam::WriteXML(), KKMLL::FileDesc::WriteXML(), KKB::XmlElementBool::WriteXML(), KKMLL::MLClassIndexList::WriteXML(), KKB::KKStr::WriteXML(), KKMLL::XmlElementMLClassNameList::WriteXML(), and KKB::DateTime::YYYY_MM_DD_HH_MM_SS().

Referenced by KKMLL::ModelKnn::WriteXML(), KKMLL::ModelUsfCasCor::WriteXML(), KKMLL::ModelSvmBase::WriteXML(), KKMLL::ModelDual::WriteXML(), and KKMLL::ModelOldSVM::WriteXML().

855 {
856  //timeSaved = osGetLocalDateTime ();
857  ModelTypeStr ().WriteXML ("ModelType", o);
858  Name ().WriteXML ("Name", o);
859  rootFileName.WriteXML ("RootFileName", o);
861  if (classesIndex)
862  classesIndex->WriteXML ("ClassesIndex", o);
863 
864 
865  if (factoryFVProducer)
866  XmlElementKKStr::WriteXML (factoryFVProducer->Name (), "FvFactoryProducer", o);
867 
868  if (fileDesc)
869  fileDesc->WriteXML ("FileDesc", o);
870 
871  if (param)
872  param->WriteXML ("Param", o);
873 
874  timeSaved.YYYY_MM_DD_HH_MM_SS ().WriteXML ("TimeSaved", o);
875  XmlElementDouble::WriteXML (trainingTime, "TrainingTime", o);
876  XmlElementBool::WriteXML (alreadyNormalized, "AlreadyNormalized", o);
877  if (normParms)
878  normParms->WriteXML ("NormParms", o);
879 } /* WriteModelXMLFields */
const KKStr & Name() const
Definition: Model.h:178
bool alreadyNormalized
Definition: Model.h:388
NormalizationParmsPtr normParms
Definition: Model.h:408
ModelParamPtr param
Definition: Model.h:412
static void WriteXML(const MLClassList &mlClassList, const KKStr &varName, std::ostream &o)
Definition: MLClass.cpp:1499
KKStr rootFileName
Definition: Model.h:414
FactoryFVProducerPtr factoryFVProducer
Definition: Model.h:404
virtual void WriteXML(const KKStr &varName, std::ostream &o) const
Definition: MLClass.cpp:1733
virtual void WriteXML(const KKStr &varName, std::ostream &o) const =0
void WriteXML(const KKStr &varName, std::ostream &o) const
KKStr YYYY_MM_DD_HH_MM_SS() const
Definition: DateTime.cpp:1216
const KKStr & Name() const
void WriteXML(const KKStr &varName, std::ostream &o) const
Definition: KKStr.cpp:4420
FileDescPtr fileDesc
Definition: Model.h:406
virtual KKStr ModelTypeStr() const
Definition: Model.h:176
void WriteXML(const KKStr &varName, std::ostream &o) const
Definition: FileDesc.cpp:875
MLClassIndexListPtr classesIndex
Definition: Model.h:392
MLClassListPtr classes
Definition: Model.h:390
virtual void KKMLL::Model::WriteXML ( const KKStr varName,
std::ostream &  o 
) const
pure virtual

Member Data Documentation

bool KKMLL::Model::alreadyNormalized
protected
double** KKMLL::Model::crossClassProbTable
protected

Probabilities between Binary Classes From last Prediction

Definition at line 396 of file Model.h.

Referenced by AllocatePredictionVariables(), DeAllocateSpace(), MemoryConsumedEstimated(), Model(), and RetrieveCrossProbTable().

kkint32 KKMLL::Model::crossClassProbTableSize
protected

Definition at line 398 of file Model.h.

Referenced by AllocatePredictionVariables(), and Model().

FeatureEncoder2Ptr KKMLL::Model::encoder
protected
VectorKKStr KKMLL::Model::errors
protected

Definition at line 402 of file Model.h.

FactoryFVProducerPtr KKMLL::Model::factoryFVProducer
protected

Definition at line 404 of file Model.h.

Referenced by FactoryFVProducer(), Model(), and KKMLL::ModelDual::TrainModel().

KKStr KKMLL::Model::rootFileName
protected

This is the root name to be used by all component objects; such as svm_model, mlClasses, and svmParam(including selected features). Each one will have the same rootName with a different suffix.

mlClasses "<rootName>.classes"
svmParam "<rootName>.svm_parm"
model "<rootName>"

Definition at line 414 of file Model.h.

Referenced by MemoryConsumedEstimated(), Model(), ReadXMLModelToken(), RootFileName(), KKMLL::ModelSvmBase::TrainModel(), and WriteModelXMLFields().

bool KKMLL::Model::weOwnTrainExamples
protected

Indicates if we own the 'trainExamples'. This does not mean that we own its contents. That is determined by 'trainExamples->Owner ()'.

Definition at line 430 of file Model.h.

Referenced by MemoryConsumedEstimated(), Model(), ReduceTrainExamples(), KKMLL::ModelOldSVM::TrainModel(), TrainModel(), and ~Model().


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