KSquare Utilities
KKMLL::BinaryClassParms Class Reference

Similar to SVMparam except it is specialized for two classes. More...

#include <BinaryClassParms.h>

Public Types

typedef BinaryClassParmsBinaryClassParmsPtr
 
typedef SVM233::svm_parameter svm_parameter
 

Public Member Functions

 BinaryClassParms (MLClassPtr _class1, MLClassPtr _class2, const svm_parameter &_param, FeatureNumListConstPtr _selectedFeatures, float _weight)
 Constructor for 'BinaryClassParms' where caller supplies the two classes and parameters for that specific class pair. More...
 
 BinaryClassParms (const BinaryClassParms &binaryClassParms)
 
 ~BinaryClassParms ()
 
double AParam () const
 
void AParam (float _A)
 
double C () const
 
void C (double _c)
 
MLClassPtr Class1 () const
 
KKStr Class1Name () const
 
MLClassPtr Class2 () const
 
KKStr Class2Name () const
 
void Gamma (double _gamma)
 
kkint32 MemoryConsumedEstimated () const
 
kkuint16 NumOfFeatures (FileDescPtr fileDesc) const
 
const svm_parameterParam () const
 
void Param (const svm_parameter &_param)
 
FeatureNumListConstPtr SelectedFeatures () const
 
void SelectedFeatures (const FeatureNumListConst &_selectedFeatures)
 
void SelectedFeatures (FeatureNumListConstPtr _selectedFeatures)
 
FeatureNumListConstPtr SelectedFeaturesFD (FileDescPtr fileDesc) const
 
KKStr ToTabDelString () const
 
float Weight () const
 
void Weight (float _weight)
 

Static Public Member Functions

static BinaryClassParmsPtr CreateFromTabDelStr (const KKStr &_str, RunLog &_log)
 

Detailed Description

Similar to SVMparam except it is specialized for two classes.

Machine Learning parameters to be used by a pair of classes.

See also
SVMparam
SVM233
Author
Kurt Kramer
Written by: Kurt Kramer *
For: Research Work, Plankton recognition System *
-------------------------------------------------------------------*
History *
*
date Programmer Description *
*
May-2004 Kurt Kramer Original Development. *
-------------------------------------------------------------------*
Was developed to support Feature Selection for each binary class *
combination. This way each two class combination can have SVM *
and feature parameters that are specific to them. *
See also
KKMLL::SVMparam, KKMLL::ModelParamOldSVM, KKMLL::SVM233

Definition at line 46 of file BinaryClassParms.h.

Member Typedef Documentation

Constructor & Destructor Documentation

BinaryClassParms::BinaryClassParms ( MLClassPtr  _class1,
MLClassPtr  _class2,
const svm_parameter _param,
FeatureNumListConstPtr  _selectedFeatures,
float  _weight 
)

Constructor for 'BinaryClassParms' where caller supplies the two classes and parameters for that specific class pair.

Parameters
[in]_class1
[in]_class2
[in]_param
[in]_selectedFeaturesWill create a duplicate instance; caller will still have same ownership status.
[in]_weight

Definition at line 25 of file BinaryClassParms.cpp.

References KKMLL::FeatureNumList::FeatureNumList(), and SVM233::svm_parameter::svm_parameter().

Referenced by KKMLL::SVMparam::AddBinaryClassParms(), CreateFromTabDelStr(), and KKMLL::SVMparam::GetParamtersToUseFor2ClassCombo().

30  :
31  class1 (_class1),
32  class2 (_class2),
33  param (_param),
34  selectedFeatures (NULL),
35  weight (_weight)
36 {
37  if (_selectedFeatures)
38  selectedFeatures = new FeatureNumList (*_selectedFeatures);
39 }
Keeps track of selected features.
BinaryClassParms::BinaryClassParms ( const BinaryClassParms binaryClassParms)

Definition at line 44 of file BinaryClassParms.cpp.

References KKMLL::FeatureNumList::FeatureNumList(), and SVM233::svm_parameter::svm_parameter().

Referenced by KKMLL::BinaryClassParmsList::DuplicateListAndContents().

44  :
45  class1 (binaryClassParms.class1),
46  class2 (binaryClassParms.class2),
47  param (binaryClassParms.param),
48  selectedFeatures (NULL),
49  weight (binaryClassParms.weight)
50 {
51  if (binaryClassParms.selectedFeatures)
52  selectedFeatures = new FeatureNumList (*binaryClassParms.selectedFeatures);
53 }
Keeps track of selected features.
BinaryClassParms::~BinaryClassParms ( )

Definition at line 57 of file BinaryClassParms.cpp.

58 {
59  delete selectedFeatures;
60  selectedFeatures = NULL;
61 }

Member Function Documentation

double KKMLL::BinaryClassParms::AParam ( ) const
inline

Definition at line 79 of file BinaryClassParms.h.

References SVM233::svm_parameter::A.

79 {return param.A;}
void KKMLL::BinaryClassParms::AParam ( float  _A)
inline

Definition at line 92 of file BinaryClassParms.h.

References SVM233::svm_parameter::A.

92 {param.A = _A;}
double KKMLL::BinaryClassParms::C ( ) const
inline

Definition at line 82 of file BinaryClassParms.h.

References SVM233::svm_parameter::C.

Referenced by KKMLL::ModelParamOldSVM::C_Param(), and KKMLL::SVMparam::C_Param().

82 {return param.C;}
void KKMLL::BinaryClassParms::C ( double  _c)
inline

Definition at line 93 of file BinaryClassParms.h.

References SVM233::svm_parameter::C.

Referenced by KKMLL::ModelParamOldSVM::C_Param(), and KKMLL::SVMparam::C_Param().

93 {param.C = _c;}
KKStr BinaryClassParms::Class1Name ( ) const

Definition at line 87 of file BinaryClassParms.cpp.

References KKMLL::MLClass::Name().

Referenced by ToTabDelString(), and KKMLL::SVMModel::WriteXML().

88 {
89  if (class1)
90  return class1->Name ();
91  else
92  return "";
93 } /* Class1Name */
KKStr BinaryClassParms::Class2Name ( ) const

Definition at line 97 of file BinaryClassParms.cpp.

References KKMLL::MLClass::Name().

Referenced by ToTabDelString(), and KKMLL::SVMModel::WriteXML().

98 {
99  if (class2)
100  return class2->Name ();
101  else
102  return "";
103 } /* Class2Name */
BinaryClassParmsPtr BinaryClassParms::CreateFromTabDelStr ( const KKStr _str,
RunLog _log 
)
static

Definition at line 132 of file BinaryClassParms.cpp.

References BinaryClassParms(), KKB::KKStr::Concat(), KKMLL::MLClass::CreateNewMLClass(), KKB::KKStr::Empty(), KKB::KKStr::ExtractQuotedStr(), KKMLL::FeatureNumList::FeatureNumList(), KKB::KKStr::KKStr(), KKB::KKStr::operator==(), SVM233::svm_parameter::svm_parameter(), and KKB::KKStr::Upper().

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

135 {
136  MLClassPtr class1 = NULL;
137  MLClassPtr class2 = NULL;
138  svm_parameter* svm_param = NULL;
139  FeatureNumListPtr selectedFeatures = NULL;
140  float weight = 0.0f;
141 
142  KKStr str (_str);
143  while (!str.Empty())
144  {
145  KKStr field = str.ExtractQuotedStr ("\n\r\t", true);
146  field.Upper ();
147  KKStr value = str.ExtractQuotedStr ("\n\r\t", true);
148 
149  if (field == "CLASS1")
150  {
151  class1 = MLClass::CreateNewMLClass (value);
152  }
153 
154  else if (field == "CLASS2")
155  {
156  class2 = MLClass::CreateNewMLClass (value);
157  }
158 
159  else if (field == "SVM_PARAMETER")
160  {
161  svm_param = new svm_parameter (value);
162  }
163 
164  else if (field == "SELECTEDFEATURES")
165  {
166  bool valid = false;
167  selectedFeatures = new FeatureNumList (value, valid);
168  }
169 
170  else if (field == "WEIGHT")
171  weight = float (atof (value.Str ()));
172  }
173 
174  BinaryClassParmsPtr binaryClassParms = (svm_param == NULL) ? NULL :new BinaryClassParms (class1, class2, *svm_param, selectedFeatures, weight);
175 
176  delete selectedFeatures; selectedFeatures = NULL;
177  delete svm_param; svm_param = NULL;
178 
179  return binaryClassParms;
180 } /* CreateFromTabDelStr */
Similar to SVMparam except it is specialized for two classes.
Keeps track of selected features.
Represents a "Class" in the Machine Learning Sense.
Definition: MLClass.h:52
SVM233::svm_parameter svm_parameter
void Upper()
Converts all characters in string to their Upper case equivalents via &#39;toupper&#39;.
Definition: KKStr.cpp:2461
KKStr ExtractQuotedStr(const char *delChars, bool decodeEscapeCharacters)
Definition: KKStr.cpp:3282
const char * Str() const
Returns a pointer to a ascii string.
Definition: KKStr.h:422
static MLClassPtr CreateNewMLClass(const KKStr &_name, kkint32 _classId=-1)
Static method used to create a new instance of a MLClass object.
Definition: MLClass.cpp:100
void KKMLL::BinaryClassParms::Gamma ( double  _gamma)
inline

Definition at line 94 of file BinaryClassParms.h.

References SVM233::svm_parameter::gamma.

94 {param.gamma = _gamma;}
double gamma
Definition: svm.h:79
kkint32 BinaryClassParms::MemoryConsumedEstimated ( ) const

Definition at line 185 of file BinaryClassParms.cpp.

References SVM233::svm_parameter::MemoryConsumedEstimated(), and KKMLL::FeatureNumList::MemoryConsumedEstimated().

186 {
187  kkint32 memoryConsumedEstimated = sizeof (*this) + param.MemoryConsumedEstimated ();
188 
189  if (selectedFeatures)
190  memoryConsumedEstimated += selectedFeatures->MemoryConsumedEstimated ();
191 
192  return memoryConsumedEstimated;
193 }
kkint32 MemoryConsumedEstimated() const
Definition: svm.cpp:886
__int32 kkint32
Definition: KKBaseTypes.h:88
kkint32 MemoryConsumedEstimated() const
kkuint16 BinaryClassParms::NumOfFeatures ( FileDescPtr  fileDesc) const

Definition at line 64 of file BinaryClassParms.cpp.

References KKMLL::FeatureNumList::NumOfFeatures(), and SelectedFeaturesFD().

Referenced by KKMLL::BinaryClassParmsList::FeatureCountNet().

65 {
66  return SelectedFeaturesFD (fileDesc)->NumOfFeatures ();
67 }
FeatureNumListConstPtr SelectedFeaturesFD(FileDescPtr fileDesc) const
const svm_parameter& KKMLL::BinaryClassParms::Param ( ) const
inline

Definition at line 83 of file BinaryClassParms.h.

Referenced by KKMLL::SVMModel::FindWorstSupportVectors(), and KKMLL::SVMModel::FindWorstSupportVectors2().

83 {return param;}
void KKMLL::BinaryClassParms::Param ( const svm_parameter _param)
inline

Definition at line 95 of file BinaryClassParms.h.

References SVM233::svm_parameter::operator=().

Referenced by KKMLL::SVMparam::SetBinaryClassFields().

95 {param = _param;}
FeatureNumListConstPtr KKMLL::BinaryClassParms::SelectedFeatures ( ) const
inline

Definition at line 84 of file BinaryClassParms.h.

84 {return selectedFeatures;}
void KKMLL::BinaryClassParms::SelectedFeatures ( const FeatureNumListConst _selectedFeatures)
void BinaryClassParms::SelectedFeatures ( FeatureNumListConstPtr  _selectedFeatures)

Will make copy of instance; caller will retain ownership status.

Definition at line 77 of file BinaryClassParms.cpp.

References KKMLL::FeatureNumList::FeatureNumList().

Referenced by KKMLL::SVMparam::SetBinaryClassFields(), and KKMLL::SVMparam::SetFeatureNums().

78 {
79  delete selectedFeatures;
80  selectedFeatures = new FeatureNumList (*_selectedFeatures);
81 }
Keeps track of selected features.
FeatureNumListConstPtr BinaryClassParms::SelectedFeaturesFD ( FileDescPtr  fileDesc) const

Definition at line 106 of file BinaryClassParms.cpp.

References KKMLL::FeatureNumList::FeatureNumList().

Referenced by KKMLL::SVMparam::GetFeatureNums(), and NumOfFeatures().

107 {
108  if (!selectedFeatures)
109  selectedFeatures = new FeatureNumList (fileDesc);
110  return selectedFeatures;
111 }
Keeps track of selected features.
KKStr BinaryClassParms::ToTabDelString ( ) const

Definition at line 115 of file BinaryClassParms.cpp.

References Class1Name(), Class2Name(), KKB::KKStr::Concat(), SVM233::svm_parameter::ToCmdLineStr(), and KKMLL::FeatureNumList::ToString().

116 {
117  KKStr result;
118  result << "Class1" << "\t" << Class1Name () << "\t"
119  << "Class2" << "\t" << Class2Name () << "\t"
120  << "Svm_Parameter" << "\t" << param.ToCmdLineStr () << "\t";
121 
122  if (selectedFeatures)
123  result << "SelectedFeatures" << "\t" << selectedFeatures->ToString () << "\t";
124 
125  result << "Weight" << "\t" << weight;
126 
127  return result;
128 } /* ToTabDelString */
KKStr ToCmdLineStr() const
Definition: svm.cpp:1069
KKStr ToString() const
Returns comma delimited list of all features selected; will make use of range specification.
float KKMLL::BinaryClassParms::Weight ( ) const
inline

Definition at line 85 of file BinaryClassParms.h.

Referenced by KKMLL::SVMparam::SetFeatureNums().

85 {return weight;}
void KKMLL::BinaryClassParms::Weight ( float  _weight)
inline

Definition at line 98 of file BinaryClassParms.h.

Referenced by KKMLL::SVMparam::SetBinaryClassFields().

98 {weight = _weight;}

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