27 using namespace KKMLL;
36 normalizeNominalFeatures (
false),
37 selectedFeatures (NULL),
63 encodingMethod (_param.encodingMethod),
64 examplesPerClass (_param.examplesPerClass),
65 fileName
(_param.fileName
),
66 normalizeNominalFeatures (_param.normalizeNominalFeatures),
67 selectedFeatures (NULL),
68 validParam (_param.validParam),
74 if (_param.selectedFeatures)
82 delete selectedFeatures;
83 selectedFeatures = NULL;
94 return memoryConsumedEstimated;
101 if (selectedFeatures)
111 delete selectedFeatures;
128 return "ModelParamDual";
131 return "ModelParamKnn";
134 return "ModelParamOldSVM";
137 return "ModelParamSvmBase";
248 while (!field
.Empty () && _validFormat)
252 _log.Level (-1) <<
"ModelParam::ParseCmdLine *** Invalid Parameter[" 255 _validFormat =
false;
262 if (_cmdLineStr
.Len () > 0)
268 valueNum = atof (value.Str ());
275 if ((field
== "-FS") || (field
== "-FEATURESSELECTED") || (field
== "-FEATURESSEL") || (field
== "FEATURESEL"))
277 delete selectedFeatures;
280 if (!selectedFeatures)
289 else if ((field
== "-ENCODE"))
299 if (examplesPerClass < 1)
303 <<
"ModelParam::ParseCmdLine ***ERROR*** Invalid '-ExamplsPerClass' parameter specified[" << value <<
"]" << endl
305 _validFormat =
false;
323 normalizeNominalFeatures =
true;
330 bool parameterUsed =
false;
331 ParseCmdLineParameter (field, value, parameterUsed, _log);
334 _log.Level (-1) <<
"ModelParam::ParseCmdLine - Invalid Parameter[" 335 << field <<
"] Value[" << value <<
"]." 337 _validFormat =
false;
347 validParam = _validFormat;
371 if (selectedFeatures)
375 cmdStr <<
" -EPC " << examplesPerClass;
392 kkint32 numFeaturesAfterEncoding = 0;
394 if (!selectedFeatures)
402 for (z = 0; z < numOfFeaturesSelected; z++)
410 numFeaturesAfterEncoding ++;
422 return numFeaturesAfterEncoding;
448 if ((encodingMethodUpper
== "BINARY") || (encodingMethodUpper
== "BIN"))
451 if (encodingMethodUpper
== "SCALE")
454 if (encodingMethodUpper
== "NONE")
469 XmlElementInt32::WriteXML (examplesPerClass,
"ExamplesPerClass", o);
475 if (selectedFeatures)
478 XmlElementDouble::WriteXML (cost,
"Cost", o);
479 XmlElementDouble::WriteXML (gamma,
"Gamma", o);
480 XmlElementDouble::WriteXML (prob,
"Prob", o);
494 bool tokenFound =
true;
516 else if ((varName.EqualIgnoreCase (
"SelectedFeatures")) && (
typeid (*e) ==
typeid (XmlElementFeatureNumList)))
518 selectedFeatures =
dynamic_cast<XmlElementFeatureNumListPtr> (e)->TakeOwnership ();
521 else if (varName.EqualIgnoreCase (
"Cost"))
523 cost = e->ToDouble ();
526 else if (varName.EqualIgnoreCase (
"Gamma"))
528 gamma = e->ToDouble ();
531 else if (varName.EqualIgnoreCase (
"Prob"))
533 prob = (
float)(e->ToDouble ());
536 else if (varName.EqualIgnoreCase (
"ValidParam"))
538 validParam = e->ToBool ();
KKStr(kkint32 size)
Creates a KKStr object that pre-allocates space for 'size' characters.
virtual double Gamma() const
bool EqualIgnoreCase(const char *s2) const
virtual KKStr ToCmdLineStr() const
Creates a a Command Line String that represents these parameters.
void WriteXMLFields(std::ostream &o) const
kkint32 MemoryConsumedEstimated() const
virtual void Cost(double _cost)
virtual KKStr ToKKStr() const
Keeps track of selected features.
virtual double C_Param() const
FeatureNumList(FileDescPtr _fileDesc)
KKMLL::AttributeType Type(kkint32 fieldNum) const
KKStr ExtractToken(const char *delStr="\n\t\r ")
FeatureNumList const FeatureNumListConst
bool operator==(const char *rtStr) const
virtual void ParseCmdLinePost(RunLog &log)
Called after 'ParseCmdLine' is completed. Classed derived from 'ModelParam' can implement this method...
virtual EncodingMethodType EncodingMethod() const
static void WriteXML(const bool b, const KKStr &varName, std::ostream &o)
FeatureNumList(const FeatureNumList &featureNumList)
Copy constructor.
virtual void Prob(float _prob)
KKStr & operator=(KKStr &&src)
virtual kkint32 ToInt32() const
kkuint32 Len() const
Returns the number of characters in the string.
static KKStr ModelParamTypeToStr(ModelParamTypes _modelParamType)
static ModelParamTypes ModelParamTypeFromStr(const KKStr &_modelParamTypeStr)
virtual bool ToBool() const
kkuint16 operator[](kkint32 idx) const
Returns back the selected feature.
KKStr operator+(const char *left, const KKStr &right)
bool ExtractTokenBool(const char *delStr)
Extract the next token from the string assuming that it is a logical True/False value.
virtual void Gamma(double _gamma)
KKStr(const KKStr &str)
Copy Constructor.
XmlElement * XmlElementPtr
virtual kkint32 MemoryConsumedEstimated() const
kkint32 NumOfFeatures() const
static EncodingMethodType EncodingMethodFromStr(const KKStr &encodingMethodStr)
virtual float A_Param() const
void TrimLeft(const char *whiteSpaceChars="\n\r\t ")
XmlTokenPtr ReadXMLModelParamToken(XmlTokenPtr t)
Will process any tokens that belong to 'ModelParam' and return NULL ones that are not will be passed ...
virtual float AvgMumOfFeatures() const
static KKStr Concat(const std::vector< std::string > &values)
Concatenates the list of 'std::string' strings.
void Upper()
Converts all characters in string to their Upper case equivalents via 'toupper'.
virtual void SelectedFeatures(FeatureNumListConst &_selectedFeatures)
void WriteXML(const KKStr &varName, std::ostream &o) const
virtual float Prob() const
FeatureNumList(const KKStr &_featureListStr, bool &_valid)
Constructs a 'FeatureNumList' instance from a string that contains a list of selected features...
ModelParam(const ModelParam &_param)
virtual kkint32 NumOfFeaturesAfterEncoding(FileDescPtr fileDesc, RunLog &log) const
Used for logging messages.
void EncodeProblem(const struct svm_paramater ¶m, struct svm_problem &prob_in, struct svm_problem &prob_out)
static KKStr EncodingMethodToStr(EncodingMethodType encodingMethod)
virtual TokenTypes TokenType()=0
kkint32 Cardinality(kkint32 fieldNum) const
virtual void A_Param(float _prob)
virtual void C_Param(double _cost)
virtual double Cost() const
Abstract Base class for Machine Learning parameters.
kkint32 MemoryConsumedEstimated() const
virtual const KKStr & VarName() const
void WriteXML(const KKStr &varName, std::ostream &o) const
KKStr ToCommaDelStr() const
virtual void ParseCmdLine(KKStr _cmdLineStr, bool &_validFormat, RunLog &_log)