KSquare Utilities
KKMLL::ModelParam Class Referenceabstract

Abstract Base class for Machine Learning parameters. More...

#include <ModelParam.h>

+ Inheritance diagram for KKMLL::ModelParam:

Public Types

enum  EncodingMethodType { EncodingMethodType::Null, EncodingMethodType::NoEncoding, EncodingMethodType::Binary, EncodingMethodType::Scaled }
 
typedef ModelParamModelParamPtr
 
enum  ModelParamTypes {
  ModelParamTypes::Null, ModelParamTypes::Dual, ModelParamTypes::KNN, ModelParamTypes::OldSVM,
  ModelParamTypes::SvmBase, ModelParamTypes::UsfCasCor
}
 

Public Member Functions

 ModelParam ()
 
 ModelParam (const ModelParam &_param)
 
virtual ~ModelParam ()
 
virtual float A_Param () const
 
virtual void A_Param (float _prob)
 
virtual float AvgMumOfFeatures () const
 
virtual double C_Param () const
 
virtual void C_Param (double _cost)
 
virtual double Cost () const
 
virtual void Cost (double _cost)
 
virtual ModelParamPtr Duplicate () const =0
 
virtual EncodingMethodType EncodingMethod () const
 
virtual void EncodingMethod (EncodingMethodType _encodingMethod)
 
virtual KKStr EncodingMethodStr () const
 
virtual kkint32 ExamplesPerClass () const
 
virtual void ExamplesPerClass (kkint32 _examplesPerClass)
 
virtual const KKStrFileName () const
 
virtual void FileName (const KKStr &_fileName)
 
virtual double Gamma () const
 
virtual void Gamma (double _gamma)
 
virtual kkint32 MemoryConsumedEstimated () const
 
virtual ModelParamTypes ModelParamType () const =0
 
virtual KKStr ModelParamTypeStr () const
 
virtual bool NormalizeNominalFeatures () const
 
virtual kkint32 NumOfFeaturesAfterEncoding (FileDescPtr fileDesc, RunLog &log) const
 
virtual void ParseCmdLine (KKStr _cmdLineStr, bool &_validFormat, RunLog &_log)
 
virtual void ParseCmdLinePost (RunLog &log)
 Called after 'ParseCmdLine' is completed. Classed derived from 'ModelParam' can implement this method to do any processing that they want after the entire command line has been processed. More...
 
virtual float Prob () const
 
virtual void Prob (float _prob)
 
virtual void ReadXML (XmlStream &s, XmlTagConstPtr tag, VolConstBool &cancelFlag, RunLog &log)=0
 
XmlTokenPtr ReadXMLModelParamToken (XmlTokenPtr t)
 Will process any tokens that belong to 'ModelParam' and return NULL ones that are not will be passed back. More...
 
virtual FeatureNumListConstPtr SelectedFeatures () const
 
virtual void SelectedFeatures (FeatureNumListConst &_selectedFeatures)
 
virtual KKStr ToCmdLineStr () const
 Creates a a Command Line String that represents these parameters. More...
 
virtual bool ValidParam () const
 
virtual void ValidParam (bool _validParam)
 
virtual void WriteXML (const KKStr &varName, std::ostream &o) const =0
 
void WriteXMLFields (std::ostream &o) const
 

Static Public Member Functions

static EncodingMethodType EncodingMethodFromStr (const KKStr &encodingMethodStr)
 
static KKStr EncodingMethodToStr (EncodingMethodType encodingMethod)
 
static ModelParamTypes ModelParamTypeFromStr (const KKStr &_modelParamTypeStr)
 
static KKStr ModelParamTypeToStr (ModelParamTypes _modelParamType)
 

Detailed Description

Abstract Base class for Machine Learning parameters.

Author
Kurt Kramer

For each Machine Learning algorithm implemented you would create a specialization of this class to manage the parameters required by the algorithm. Specifically for each new class that you create that is derived from 'Model' you will create a class derived from 'ModelParam'. This class encapsulates general parameters that are common to all Machine Learning Models.

See also
Model

Definition at line 35 of file ModelParam.h.

Member Typedef Documentation

Definition at line 38 of file ModelParam.h.

Member Enumeration Documentation

Needs to be synchronized with SVMparam::SVM_EncodingMethod

Enumerator
Null 
NoEncoding 
Binary 
Scaled 

Definition at line 56 of file ModelParam.h.

Enumerator
Null 
Dual 
KNN 
OldSVM 
SvmBase 
UsfCasCor 

Definition at line 40 of file ModelParam.h.

41  {Null,
42  Dual,
43  KNN,
44  OldSVM,
45  SvmBase,
46  UsfCasCor
47  };

Constructor & Destructor Documentation

ModelParam::ModelParam ( )

Definition at line 31 of file ModelParam.cpp.

References KKB::KKStr::KKStr(), and NoEncoding.

Referenced by KKMLL::ModelParamDual::ModelParamDual(), KKMLL::ModelParamKnn::ModelParamKnn(), KKMLL::ModelParamOldSVM::ModelParamOldSVM(), KKMLL::ModelParamSvmBase::ModelParamSvmBase(), and KKMLL::ModelParamUsfCasCor::ModelParamUsfCasCor().

31  :
32 
33  encodingMethod (EncodingMethodType::NoEncoding),
34  examplesPerClass (int32_max),
35  fileName (),
36  normalizeNominalFeatures (false),
37  selectedFeatures (NULL),
38  validParam (true),
39  // SVM related parameters
40  cost (0.0),
41  gamma (0.0),
42  prob (0.0f)
43 {
44  /*
45  if (!fileDesc)
46  {
47  log.Level (-1) << endl
48  << "ModelParam::ModelParam *** ERROR ***" << endl
49  << " fileDesc == NULL" << endl
50  << endl;
51  osWaitForEnter ();
52  exit (-1);
53  }
54  */
55 }
#define int32_max
Definition: KKBaseTypes.h:119
ModelParam::ModelParam ( const ModelParam _param)

Definition at line 61 of file ModelParam.cpp.

References KKMLL::FeatureNumList::FeatureNumList(), and KKB::KKStr::KKStr().

Referenced by KKMLL::ModelParamDual::ModelParamDual(), KKMLL::ModelParamKnn::ModelParamKnn(), KKMLL::ModelParamOldSVM::ModelParamOldSVM(), and KKMLL::ModelParamSvmBase::ModelParamSvmBase().

61  :
62 
63  encodingMethod (_param.encodingMethod),
64  examplesPerClass (_param.examplesPerClass),
65  fileName (_param.fileName),
66  normalizeNominalFeatures (_param.normalizeNominalFeatures),
67  selectedFeatures (NULL),
68  validParam (_param.validParam),
69  // SVM related parameters
70  cost (_param.cost),
71  gamma (_param.gamma),
72  prob (_param.prob)
73 {
74  if (_param.selectedFeatures)
75  selectedFeatures = new FeatureNumList (*(_param.selectedFeatures));
76 }
Keeps track of selected features.
ModelParam::~ModelParam ( )
virtual

Definition at line 80 of file ModelParam.cpp.

81 {
82  delete selectedFeatures;
83  selectedFeatures = NULL;
84 }

Member Function Documentation

float ModelParam::A_Param ( ) const
virtual

Reimplemented in KKMLL::ModelParamOldSVM.

Definition at line 172 of file ModelParam.cpp.

Referenced by KKMLL::TrainingConfiguration2::A_Param().

173 {
174  return prob;
175 }
void ModelParam::A_Param ( float  _prob)
virtual

Reimplemented in KKMLL::ModelParamOldSVM.

Definition at line 201 of file ModelParam.cpp.

Referenced by KKMLL::ModelParamOldSVM::A_Param(), KKMLL::TrainingConfiguration2::A_Param(), and KKMLL::ModelParamOldSVM::ParseCmdLine().

202 {
203  prob = _prob;
204 }
float ModelParam::AvgMumOfFeatures ( ) const
virtual

Definition at line 99 of file ModelParam.cpp.

References KKMLL::FeatureNumList::NumOfFeatures().

Referenced by KKMLL::TrainingConfiguration2::AvgNumOfFeatures().

100 {
101  if (selectedFeatures)
102  return (float)selectedFeatures->NumOfFeatures ();
103  else
104  return 0;
105 }
kkint32 NumOfFeatures() const
double ModelParam::C_Param ( ) const
virtual

Reimplemented in KKMLL::ModelParamOldSVM.

Definition at line 177 of file ModelParam.cpp.

Referenced by KKMLL::TrainingConfiguration2::C_Param().

178 {
179  return cost;
180 }
void ModelParam::C_Param ( double  _cost)
virtual

Reimplemented in KKMLL::ModelParamOldSVM.

Definition at line 207 of file ModelParam.cpp.

Referenced by KKMLL::TrainingConfiguration2::C_Param(), and KKMLL::ModelParamOldSVM::ParseCmdLine().

208 {
209  cost = _cost;
210 }
double ModelParam::Cost ( ) const
virtual

Reimplemented in KKMLL::ModelParamSvmBase.

Definition at line 182 of file ModelParam.cpp.

183 {
184  return cost;
185 }
void ModelParam::Cost ( double  _cost)
virtual

Reimplemented in KKMLL::ModelParamSvmBase.

Definition at line 213 of file ModelParam.cpp.

Referenced by KKMLL::ModelParamOldSVM::C_Param(), KKMLL::ModelParamSvmBase::Cost(), and ParseCmdLine().

214 {
215  cost = _cost;
216 }
virtual EncodingMethodType KKMLL::ModelParam::EncodingMethod ( ) const
inlinevirtual
virtual void KKMLL::ModelParam::EncodingMethod ( EncodingMethodType  _encodingMethod)
inlinevirtual

Reimplemented in KKMLL::ModelParamOldSVM.

Definition at line 128 of file ModelParam.h.

Referenced by KKMLL::ModelParamOldSVM::EncodingMethod(), KKMLL::TrainingConfiguration2::EncodingMethod(), and KKMLL::ModelParamOldSVM::ParseCmdLine().

128 {encodingMethod = _encodingMethod;}
ModelParam::EncodingMethodType ModelParam::EncodingMethodFromStr ( const KKStr encodingMethodStr)
static

Definition at line 444 of file ModelParam.cpp.

References Binary, KKB::KKStr::Concat(), NoEncoding, Null, KKB::KKStr::operator==(), Scaled, and KKB::KKStr::ToUpper().

Referenced by ParseCmdLine(), and ReadXMLModelParamToken().

445 {
446  KKStr encodingMethodUpper = encodingMethodStr.ToUpper ();
447 
448  if ((encodingMethodUpper == "BINARY") || (encodingMethodUpper == "BIN"))
450 
451  if (encodingMethodUpper == "SCALE")
453 
454  if (encodingMethodUpper == "NONE")
456 
458 } /* EncodingMethodFromStr */
KKStr ToUpper() const
Definition: KKStr.cpp:2517
virtual KKStr KKMLL::ModelParam::EncodingMethodStr ( ) const
inlinevirtual

Definition at line 112 of file ModelParam.h.

References EncodingMethodToStr().

112 {return EncodingMethodToStr (encodingMethod);}
static KKStr EncodingMethodToStr(EncodingMethodType encodingMethod)
Definition: ModelParam.cpp:428
KKStr ModelParam::EncodingMethodToStr ( EncodingMethodType  encodingMethod)
static

Definition at line 428 of file ModelParam.cpp.

References Binary, and Scaled.

Referenced by EncodingMethodStr(), ToCmdLineStr(), and WriteXMLFields().

429 {
430  if (encodingMethod == EncodingMethodType::Binary)
431  return "Binary";
432 
433  else if (encodingMethod == EncodingMethodType::Scaled)
434  return "Scale";
435 
436  else
437  return "None";
438 } /* EncodingMethodToStr */
virtual kkint32 KKMLL::ModelParam::ExamplesPerClass ( ) const
inlinevirtual

Definition at line 113 of file ModelParam.h.

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

113 {return examplesPerClass;}
virtual void KKMLL::ModelParam::ExamplesPerClass ( kkint32  _examplesPerClass)
inlinevirtual

Definition at line 129 of file ModelParam.h.

129 {examplesPerClass = _examplesPerClass;}
virtual const KKStr& KKMLL::ModelParam::FileName ( ) const
inlinevirtual

Definition at line 114 of file ModelParam.h.

114 {return fileName;}
virtual void KKMLL::ModelParam::FileName ( const KKStr _fileName)
inlinevirtual

Definition at line 130 of file ModelParam.h.

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

130 {fileName = _fileName;}
double ModelParam::Gamma ( ) const
virtual

Reimplemented in KKMLL::ModelParamOldSVM, and KKMLL::ModelParamSvmBase.

Definition at line 187 of file ModelParam.cpp.

Referenced by KKMLL::TrainingConfiguration2::Gamma().

188 {
189  return gamma;
190 }
void ModelParam::Gamma ( double  _gamma)
virtual
kkint32 ModelParam::MemoryConsumedEstimated ( ) const
virtual

Definition at line 87 of file ModelParam.cpp.

References KKMLL::FeatureNumList::MemoryConsumedEstimated(), and KKB::KKStr::MemoryConsumedEstimated().

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

88 {
89  kkint32 memoryConsumedEstimated = sizeof (ModelParam)
90  + fileName.MemoryConsumedEstimated ();
91 
92  if (selectedFeatures)
93  memoryConsumedEstimated += selectedFeatures->MemoryConsumedEstimated ();
94  return memoryConsumedEstimated;
95 }
kkint32 MemoryConsumedEstimated() const
Definition: KKStr.cpp:766
__int32 kkint32
Definition: KKBaseTypes.h:88
kkint32 MemoryConsumedEstimated() const
ModelParam::ModelParamTypes ModelParam::ModelParamTypeFromStr ( const KKStr _modelParamTypeStr)
static

Definition at line 148 of file ModelParam.cpp.

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

149 {
150  if (_modelParamTypeStr.EqualIgnoreCase ("ModelParamDual"))
151  return ModelParamTypes::Dual;
152 
153  else if (_modelParamTypeStr.EqualIgnoreCase ("ModelParamOldSVM"))
155 
156  else if (_modelParamTypeStr.EqualIgnoreCase ("ModelParamSvmBase"))
158 
159  else if (_modelParamTypeStr.EqualIgnoreCase ("ModelParamKnn"))
160  return ModelParamTypes::KNN;
161 
162  else if (_modelParamTypeStr.EqualIgnoreCase ("UsfCasCor"))
164 
165  else
166  return ModelParamTypes::Null;
167 }
bool EqualIgnoreCase(const KKStr &s2) const
Definition: KKStr.cpp:1250
virtual KKStr KKMLL::ModelParam::ModelParamTypeStr ( ) const
inlinevirtual

Definition at line 108 of file ModelParam.h.

References ModelParamType(), and ModelParamTypeToStr().

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

108 {return ModelParamTypeToStr (ModelParamType ());}
static KKStr ModelParamTypeToStr(ModelParamTypes _modelParamType)
Definition: ModelParam.cpp:122
virtual ModelParamTypes ModelParamType() const =0
KKStr ModelParam::ModelParamTypeToStr ( ModelParamTypes  _modelParamType)
static

Definition at line 122 of file ModelParam.cpp.

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

Referenced by ModelParamTypeStr().

123 {
124  if (_modelParamType == ModelParamTypes::Null)
125  return "NULL";
126 
127  else if (_modelParamType == ModelParamTypes::Dual)
128  return "ModelParamDual";
129 
130  else if (_modelParamType == ModelParamTypes::KNN)
131  return "ModelParamKnn";
132 
133  else if (_modelParamType == ModelParamTypes::OldSVM)
134  return "ModelParamOldSVM";
135 
136  else if (_modelParamType == ModelParamTypes::SvmBase)
137  return "ModelParamSvmBase";
138 
139  else if (_modelParamType == ModelParamTypes::UsfCasCor)
140  return "UsfCasCor";
141 
142  else
143  return "NULL";
144 }
virtual bool KKMLL::ModelParam::NormalizeNominalFeatures ( ) const
inlinevirtual

Definition at line 115 of file ModelParam.h.

Referenced by KKMLL::NormalizationParms::NormalizationParms(), and KKMLL::TrainingConfiguration2::NormalizeNominalFeatures().

115 {return normalizeNominalFeatures;}
kkint32 ModelParam::NumOfFeaturesAfterEncoding ( FileDescPtr  fileDesc,
RunLog log 
) const
virtual

Reimplemented in KKMLL::ModelParamOldSVM.

Definition at line 387 of file ModelParam.cpp.

References Binary, KKMLL::FileDesc::Cardinality(), EncodingMethod(), KKMLL::FeatureNumList::FeatureNumList(), NoEncoding, KKMLL::Nominal, KKMLL::FeatureNumList::NumOfFeatures(), KKMLL::FeatureNumList::operator[](), Scaled, KKMLL::Symbolic, and KKMLL::FileDesc::Type().

Referenced by KKMLL::TrainingConfiguration2::NumOfFeaturesAfterEncoding().

390 {
391  kkint32 z;
392  kkint32 numFeaturesAfterEncoding = 0;
393 
394  if (!selectedFeatures)
395  selectedFeatures = new FeatureNumList (fileDesc);
396 
397  kkint32 numOfFeaturesSelected = selectedFeatures->NumOfFeatures ();
398 
399  switch (EncodingMethod ())
400  {
402  for (z = 0; z < numOfFeaturesSelected; z++)
403  {
404  kkint32 fieldNum = (*selectedFeatures)[z];
405  if ((fileDesc->Type (fieldNum) == AttributeType::Nominal) ||
406  (fileDesc->Type (fieldNum) == AttributeType::Symbolic)
407  )
408  numFeaturesAfterEncoding += fileDesc->Cardinality (fieldNum);
409  else
410  numFeaturesAfterEncoding ++;
411  }
412  break;
413 
416  default:
417  //numFeaturesAfterEncoding = fileDesc->NumOfFields ( );
418  numFeaturesAfterEncoding = selectedFeatures->NumOfFeatures ();
419  break;
420  }
421 
422  return numFeaturesAfterEncoding;
423 } // NumOfFeaturesAfterEncoding
__int32 kkint32
Definition: KKBaseTypes.h:88
Keeps track of selected features.
KKMLL::AttributeType Type(kkint32 fieldNum) const
Definition: FileDesc.cpp:370
virtual EncodingMethodType EncodingMethod() const
Definition: ModelParam.h:111
kkint32 NumOfFeatures() const
kkint32 Cardinality(kkint32 fieldNum) const
Definition: FileDesc.cpp:341
void ModelParam::ParseCmdLine ( KKStr  _cmdLineStr,
bool &  _validFormat,
RunLog _log 
)
virtual

Reimplemented in KKMLL::ModelParamOldSVM.

Definition at line 234 of file ModelParam.cpp.

References KKB::KKStr::Concat(), Cost(), KKB::KKStr::Empty(), EncodingMethodFromStr(), KKB::KKStr::EqualIgnoreCase(), KKB::KKStr::ExtractToken(), KKB::KKStr::ExtractTokenBool(), KKMLL::FeatureNumList::FeatureNumList(), KKB::KKStr::FirstChar(), Gamma(), KKB::KKStr::KKStr(), KKB::KKStr::Len(), KKB::KKStr::operator=(), KKB::KKStr::operator==(), ParseCmdLinePost(), KKB::KKStr::ToInt(), KKB::KKStr::TrimLeft(), and KKB::KKStr::Upper().

238 {
239  _validFormat = true;
240 
241  //DecodeParamStr (_cmdLineStr, param);
242 
243  KKStr field (_cmdLineStr.ExtractToken (" \t\n\r"));
244  KKStr value;
245 
246  double valueNum;
247 
248  while (!field.Empty () && _validFormat)
249  {
250  if (field.FirstChar () != '-')
251  {
252  _log.Level (-1) << "ModelParam::ParseCmdLine *** Invalid Parameter["
253  << field << "] ***"
254  << endl;
255  _validFormat = false;
256  break;
257  }
258 
259  // See if next field is a Switch field or a parameter.
260  _cmdLineStr.TrimLeft (" \t\n\r");
261  value == "";
262  if (_cmdLineStr.Len () > 0)
263  {
264  if (_cmdLineStr.FirstChar () != '-')
265  value = _cmdLineStr.ExtractToken (" \t\n\r");
266  }
267 
268  valueNum = atof (value.Str ());
269 
270  field.Upper ();
271  KKStr valueUpper (value);
272 
273  valueUpper.Upper ();
274 
275  if ((field == "-FS") || (field == "-FEATURESSELECTED") || (field == "-FEATURESSEL") || (field == "FEATURESEL"))
276  {
277  delete selectedFeatures;
278  bool valid = true;
279  selectedFeatures = new FeatureNumList (value, valid);
280  if (!selectedFeatures)
281  _validFormat= false;
282  }
283 
284  else if (field.EqualIgnoreCase ("-C") || field.EqualIgnoreCase ("-Cost"))
285  {
286  Cost (valueNum);
287  }
288 
289  else if ((field == "-ENCODE"))
290  {
291  encodingMethod = EncodingMethodFromStr (valueUpper);
292  }
293 
294  else if ((field.EqualIgnoreCase ("-EPC")) ||
295  (field.EqualIgnoreCase ("-ExamplesPerClass"))
296  )
297  {
298  examplesPerClass = value.ToInt ();
299  if (examplesPerClass < 1)
300  {
301  _log.Level (-1)
302  << endl << endl
303  << "ModelParam::ParseCmdLine ***ERROR*** Invalid '-ExamplsPerClass' parameter specified[" << value << "]" << endl
304  << endl;
305  _validFormat = false;
306  examplesPerClass = int32_max;
307  break;
308  }
309  }
310 
311  else if (field.EqualIgnoreCase ("-G") || field.EqualIgnoreCase ("-Gamma"))
312  {
313  Gamma (valueNum);
314  }
315 
316  else if ((field.EqualIgnoreCase ("-NormNominal")) ||
317  (field.EqualIgnoreCase ("-NormalizeNominal")) ||
318  (field.EqualIgnoreCase ("-NormalizeNominalFeatures")) ||
319  (field.EqualIgnoreCase ("-NN"))
320  )
321  {
322  if (value.Empty ())
323  normalizeNominalFeatures = true;
324  else
325  normalizeNominalFeatures = value.ExtractTokenBool ("\t");
326  }
327 
328  else
329  {
330  bool parameterUsed = false;
331  ParseCmdLineParameter (field, value, parameterUsed, _log);
332  if (!parameterUsed)
333  {
334  _log.Level (-1) << "ModelParam::ParseCmdLine - Invalid Parameter["
335  << field << "] Value[" << value << "]."
336  << endl;
337  _validFormat = false;
338  break;
339  }
340  }
341 
342  field = _cmdLineStr.ExtractToken (" \t\n\r");
343  }
344 
345  ParseCmdLinePost (_log);
346 
347  validParam = _validFormat;
348 } /* ParseCmdLine */
HTMLReport &__cdecl endl(HTMLReport &htmlReport)
Definition: HTMLReport.cpp:240
virtual double Gamma() const
Definition: ModelParam.cpp:187
Keeps track of selected features.
KKStr ExtractToken(const char *delStr="\n\t\r ")
Definition: KKStr.cpp:2969
char FirstChar() const
Definition: KKStr.cpp:1970
virtual void ParseCmdLinePost(RunLog &log)
Called after &#39;ParseCmdLine&#39; is completed. Classed derived from &#39;ModelParam&#39; can implement this method...
Definition: ModelParam.cpp:358
RunLog & Level(kkint32 _level)
Definition: RunLog.cpp:220
kkuint32 Len() const
Returns the number of characters in the string.
Definition: KKStr.h:366
static EncodingMethodType EncodingMethodFromStr(const KKStr &encodingMethodStr)
Definition: ModelParam.cpp:444
void TrimLeft(const char *whiteSpaceChars="\n\r\t ")
Definition: KKStr.cpp:1745
void Upper()
Converts all characters in string to their Upper case equivalents via &#39;toupper&#39;.
Definition: KKStr.cpp:2461
virtual double Cost() const
Definition: ModelParam.cpp:182
#define int32_max
Definition: KKBaseTypes.h:119
void ModelParam::ParseCmdLinePost ( RunLog log)
virtual

Called after 'ParseCmdLine' is completed. Classed derived from 'ModelParam' can implement this method to do any processing that they want after the entire command line has been processed.

An example use of this is in 'ModelParamSvmBase' where the local 'ParseCmdLineParameter' routine processes parameters that 'Model' needs to be aware of.

Definition at line 358 of file ModelParam.cpp.

Referenced by ParseCmdLine().

359 {
360 }
float ModelParam::Prob ( ) const
virtual

Definition at line 192 of file ModelParam.cpp.

193 {
194  return prob;
195 }
void ModelParam::Prob ( float  _prob)
virtual

Definition at line 225 of file ModelParam.cpp.

226 {
227  prob = _prob;
228 }
virtual void KKMLL::ModelParam::ReadXML ( XmlStream s,
XmlTagConstPtr  tag,
VolConstBool cancelFlag,
RunLog log 
)
pure virtual
XmlTokenPtr ModelParam::ReadXMLModelParamToken ( XmlTokenPtr  t)

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

Definition at line 487 of file ModelParam.cpp.

References KKB::KKStr::Concat(), EncodingMethodFromStr(), KKB::KKStr::EqualIgnoreCase(), KKB::KKStr::operator=(), KKB::XmlElement::ToBool(), KKB::XmlElement::ToInt32(), KKB::XmlToken::tokElement, KKB::XmlToken::TokenType(), KKB::XmlElement::ToKKStr(), and KKB::XmlToken::VarName().

Referenced by KKMLL::ModelParamKnn::ReadXML(), KKMLL::ModelParamSvmBase::ReadXML(), KKMLL::ModelParamUsfCasCor::ReadXML(), KKMLL::ModelParamDual::ReadXML(), and KKMLL::ModelParamOldSVM::ReadXML().

488 {
489  const KKStr& varName = t->VarName ();
490  if (t->TokenType () == XmlToken::TokenTypes::tokElement)
491  {
492  XmlElementPtr e = dynamic_cast<XmlElementPtr> (t);
493 
494  bool tokenFound = true;
495 
496  if (varName.EqualIgnoreCase ("EncodingMethod"))
497  {
498  encodingMethod = EncodingMethodFromStr (e->ToKKStr ());
499  }
500 
501  else if (varName.EqualIgnoreCase ("ExamplesPerClass"))
502  {
503  examplesPerClass = e->ToInt32 ();
504  }
505 
506  else if (varName.EqualIgnoreCase ("FileName"))
507  {
508  fileName = e->ToKKStr ();
509  }
510 
511  else if (varName.EqualIgnoreCase ("NormalizeNominalFeatures"))
512  {
513  normalizeNominalFeatures = e->ToBool ();;
514  }
515 
516  else if ((varName.EqualIgnoreCase ("SelectedFeatures")) && (typeid (*e) == typeid (XmlElementFeatureNumList)))
517  {
518  selectedFeatures = dynamic_cast<XmlElementFeatureNumListPtr> (e)->TakeOwnership ();
519  }
520 
521  else if (varName.EqualIgnoreCase ("Cost"))
522  {
523  cost = e->ToDouble ();
524  }
525 
526  else if (varName.EqualIgnoreCase ("Gamma"))
527  {
528  gamma = e->ToDouble ();
529  }
530 
531  else if (varName.EqualIgnoreCase ("Prob"))
532  {
533  prob = (float)(e->ToDouble ());
534  }
535 
536  else if (varName.EqualIgnoreCase ("ValidParam"))
537  {
538  validParam = e->ToBool ();
539  }
540  else
541  {
542  tokenFound = false;
543  }
544 
545  if (tokenFound)
546  {
547  delete t;
548  t = NULL;
549  }
550  }
551 
552  return t;
553 } /* ReadXMLModelParamToken */
virtual double ToDouble() const
Definition: XmlStream.h:315
virtual KKStr ToKKStr() const
Definition: XmlStream.h:314
bool EqualIgnoreCase(const KKStr &s2) const
Definition: KKStr.cpp:1250
virtual kkint32 ToInt32() const
Definition: XmlStream.h:317
virtual bool ToBool() const
Definition: XmlStream.h:313
static EncodingMethodType EncodingMethodFromStr(const KKStr &encodingMethodStr)
Definition: ModelParam.cpp:444
virtual TokenTypes TokenType()=0
XmlElementTemplate< FeatureNumList > XmlElementFeatureNumList
virtual const KKStr & VarName() const
Definition: XmlStream.h:269
void ModelParam::SelectedFeatures ( FeatureNumListConst _selectedFeatures)
virtual

Definition at line 109 of file ModelParam.cpp.

References KKMLL::FeatureNumList::FeatureNumList().

Referenced by KKMLL::ModelParamOldSVM::SelectedFeatures(), and KKMLL::TrainingConfiguration2::SetFeatureNums().

110 {
111  delete selectedFeatures;
112  selectedFeatures = new FeatureNumList (_selectedFeatures);
113 }
Keeps track of selected features.
KKStr ModelParam::ToCmdLineStr ( ) const
virtual

Creates a a Command Line String that represents these parameters.

Convert all parameters to a command line string.

All derived classes should implement this method. They should first call this method and then append there own parameters that are specific to their implementation.

Reimplemented in KKMLL::ModelParamOldSVM, KKMLL::ModelParamDual, KKMLL::ModelParamUsfCasCor, and KKMLL::ModelParamSvmBase.

Definition at line 367 of file ModelParam.cpp.

References KKB::KKStr::Concat(), EncodingMethodToStr(), KKB::KKStr::KKStr(), NoEncoding, KKB::operator+(), and KKMLL::FeatureNumList::ToCommaDelStr().

Referenced by KKMLL::TrainingConfiguration2::ModelParameterCmdLine(), KKMLL::ModelParamKnn::ToCmdLineStr(), KKMLL::ModelParamSvmBase::ToCmdLineStr(), and KKMLL::ModelParamDual::ToCmdLineStr().

368 {
369  KKStr cmdStr (300);
370 
371  if (selectedFeatures)
372  cmdStr << "-SF " + selectedFeatures->ToCommaDelStr ();
373 
374  if (examplesPerClass < int32_max)
375  cmdStr << " -EPC " << examplesPerClass;
376 
377  if (encodingMethod != EncodingMethodType::NoEncoding)
378  cmdStr << " -Encode " + EncodingMethodToStr (encodingMethod);
379 
380  return cmdStr;
381 } /* ToCmdLineStr */
static KKStr EncodingMethodToStr(EncodingMethodType encodingMethod)
Definition: ModelParam.cpp:428
#define int32_max
Definition: KKBaseTypes.h:119
KKStr ToCommaDelStr() const
virtual bool KKMLL::ModelParam::ValidParam ( ) const
inlinevirtual

Definition at line 117 of file ModelParam.h.

Referenced by KKMLL::Model::ReadXMLModelPost(), and KKMLL::TrainingConfiguration2::TrainingConfiguration2().

117 {return validParam;}
virtual void KKMLL::ModelParam::ValidParam ( bool  _validParam)
inlinevirtual

Definition at line 132 of file ModelParam.h.

Referenced by KKMLL::ModelParamOldSVM::ParseCmdLine().

132 {validParam = _validParam;}
virtual void KKMLL::ModelParam::WriteXML ( const KKStr varName,
std::ostream &  o 
) const
pure virtual
void ModelParam::WriteXMLFields ( std::ostream &  o) const

Definition at line 464 of file ModelParam.cpp.

References EncodingMethodToStr(), KKMLL::FeatureNumList::WriteXML(), KKB::XmlElementBool::WriteXML(), and KKB::KKStr::WriteXML().

Referenced by KKMLL::ModelParamKnn::WriteXML(), KKMLL::ModelParamSvmBase::WriteXML(), KKMLL::ModelParamUsfCasCor::WriteXML(), KKMLL::ModelParamDual::WriteXML(), and KKMLL::ModelParamOldSVM::WriteXML().

466 {
467  EncodingMethodToStr (encodingMethod).WriteXML ("EncodingMethod", o);
468 
469  XmlElementInt32::WriteXML (examplesPerClass, "ExamplesPerClass", o);
470 
471  fileName.WriteXML ("FileName", o);
472 
473  XmlElementBool::WriteXML (normalizeNominalFeatures, "NormalizeNominalFeatures", o);
474 
475  if (selectedFeatures)
476  selectedFeatures->WriteXML ("SelectedFeatures", o);
477 
478  XmlElementDouble::WriteXML (cost, "Cost", o);
479  XmlElementDouble::WriteXML (gamma, "Gamma", o);
480  XmlElementDouble::WriteXML (prob, "Prob", o);
481  XmlElementBool::WriteXML (validParam, "ValidParam", o);
482 } /* WriteXML */
void WriteXML(const KKStr &varName, std::ostream &o) const
Definition: KKStr.cpp:4420
static KKStr EncodingMethodToStr(EncodingMethodType encodingMethod)
Definition: ModelParam.cpp:428
void WriteXML(const KKStr &varName, std::ostream &o) const

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