KSquare Utilities
SVM289_MFS::svm_parameter Struct Reference

#include <svm2.h>

Public Member Functions

 svm_parameter ()
 
 svm_parameter (const svm_parameter &_param)
 
 svm_parameter (KKStr &paramStr)
 
 ~svm_parameter ()
 
void Cost (double _cost)
 
double Cost () const
 
void Gamma (double _gamma)
 
double Gamma () const
 
void KernalType (Kernel_Type _kernalType)
 
Kernel_Type KernalType () const
 
svm_parameteroperator= (const svm_parameter &right)
 
void ParseTabDelStr (const KKStr &_str)
 
void ProcessSvmParameter (const KKStr &cmd, const KKStr &value, bool &parmUsed)
 
void SvmType (SVM_Type _svm_type)
 
SVM_Type SvmType () const
 
KKStr ToCmdLineStr () const
 
KKStr ToTabDelStr () const
 

Public Attributes

double C
 
double cache_size
 
double coef0
 
kkint32 degree
 
double eps
 
double gamma
 
Kernel_Type kernel_type
 
kkint32 nr_weight
 
double nu
 
double p
 
kkint32 probability
 
double probParam
 
kkint32 shrinking
 
SVM_Type svm_type
 
double * weight
 
kkint32weight_label
 

Static Public Attributes

static const char * kernel_type_table []
 
static const char * svm_type_table []
 

Detailed Description

Definition at line 101 of file svm2.h.

Constructor & Destructor Documentation

SVM289_MFS::svm_parameter::svm_parameter ( )

Definition at line 177 of file svm2.cpp.

References C, SVM289_MFS::C_SVC, cache_size, coef0, degree, eps, gamma, kernel_type, nr_weight, nu, p, probability, probParam, SVM289_MFS::RBF, shrinking, svm_type, weight, and weight_label.

Referenced by KKMLL::ModelParamSvmBase::ModelParamSvmBase(), and SVM289_MFS::Svm_Model::Svm_Model().

177  :
180  degree (3),
181  gamma (0.0),
182  coef0 (0.0),
183  cache_size (40.0),
184  eps (1e-3),
185  C (1),
186  nr_weight (0),
187  weight_label (NULL),
188  weight (NULL),
189  nu (0.5),
190  p (0.1),
191  shrinking (1),
192  probability (0),
193  probParam (0.0)
194 {
195 }
Kernel_Type kernel_type
Definition: svm2.h:132
kkint32 * weight_label
Definition: svm2.h:142
SVM289_MFS::svm_parameter::svm_parameter ( const svm_parameter _param)

Definition at line 198 of file svm2.cpp.

References C, cache_size, coef0, degree, eps, gamma, kernel_type, nr_weight, nu, p, probability, probParam, shrinking, svm_type, weight, and weight_label.

Referenced by KKMLL::ModelParamSvmBase::ModelParamSvmBase(), and SVM289_MFS::Svm_Model::Svm_Model().

198  :
199  svm_type (_param.svm_type),
200  kernel_type (_param.kernel_type),
201  degree (_param.degree),
202  gamma (_param.gamma),
203  coef0 (_param.coef0),
204  cache_size (_param.cache_size),
205  eps (_param.eps),
206  C (_param.C),
207  nr_weight (_param.nr_weight),
208  weight_label (NULL),
209  weight (NULL),
210  nu (_param.nu),
211  p (_param.p),
212  shrinking (_param.shrinking),
213  probability (_param.probability),
214  probParam (_param.probParam)
215 {
216  if (_param.weight_label)
217  {
219  for (kkint32 x = 0; x < nr_weight; x++)
220  weight_label[x] = _param.weight_label[x];
221  }
222 
223  if (_param.weight)
224  {
225  weight = new double[nr_weight];
226  for (kkint32 x = 0; x < nr_weight; x++)
227  weight[x] = _param.weight[x];
228  }
229 }
__int32 kkint32
Definition: KKBaseTypes.h:88
Kernel_Type kernel_type
Definition: svm2.h:132
kkint32 * weight_label
Definition: svm2.h:142
SVM289_MFS::svm_parameter::svm_parameter ( KKStr paramStr)

Definition at line 233 of file svm2.cpp.

References C, SVM289_MFS::C_SVC, cache_size, coef0, degree, eps, gamma, kernel_type, nr_weight, nu, p, probability, probParam, SVM289_MFS::RBF, shrinking, svm_type, weight, and weight_label.

233  :
236  degree (3),
237  gamma (0.0),
238  coef0 (0.0),
239  cache_size (40.0),
240  eps (1e-3),
241  C (1),
242  nr_weight (0),
243  weight_label (NULL),
244  weight (NULL),
245  nu (0.5),
246  p (0.1),
247  shrinking (1),
248  probability (0),
249  probParam (0.0)
250 {
251  cerr << endl << "VM289::svm_parameter::svm_parameter Not Doing anything with 'paramStr'" << endl << endl;
252 }
HTMLReport &__cdecl endl(HTMLReport &htmlReport)
Definition: HTMLReport.cpp:240
Kernel_Type kernel_type
Definition: svm2.h:132
kkint32 * weight_label
Definition: svm2.h:142
SVM289_MFS::svm_parameter::~svm_parameter ( )

Definition at line 256 of file svm2.cpp.

References weight, and weight_label.

257 {
258  delete weight_label; weight_label = NULL;
259  delete weight; weight = NULL;
260 }
kkint32 * weight_label
Definition: svm2.h:142

Member Function Documentation

void SVM289_MFS::svm_parameter::Cost ( double  _cost)
inline

Definition at line 109 of file svm2.h.

References C.

Referenced by KKMLL::ModelParamSvmBase::Cost(), and KKMLL::ModelParamSvmBase::ModelParamSvmBase().

109 {C = _cost;}
double SVM289_MFS::svm_parameter::Cost ( ) const
inline

Definition at line 114 of file svm2.h.

References C.

Referenced by KKMLL::ModelParamSvmBase::Cost().

114 {return C;}
void SVM289_MFS::svm_parameter::Gamma ( double  _gamma)
inline

Definition at line 110 of file svm2.h.

References gamma.

Referenced by KKMLL::ModelParamSvmBase::Gamma(), and KKMLL::ModelParamSvmBase::ModelParamSvmBase().

110 {gamma = _gamma;}
double SVM289_MFS::svm_parameter::Gamma ( ) const
inline

Definition at line 115 of file svm2.h.

References gamma.

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

115 {return gamma;}
void SVM289_MFS::svm_parameter::KernalType ( Kernel_Type  _kernalType)
inline

Definition at line 111 of file svm2.h.

References kernel_type.

Referenced by KKMLL::ModelParamSvmBase::KernalType(), and KKMLL::ModelParamSvmBase::ModelParamSvmBase().

111 {kernel_type = _kernalType;}
Kernel_Type kernel_type
Definition: svm2.h:132
Kernel_Type SVM289_MFS::svm_parameter::KernalType ( ) const
inline

Definition at line 116 of file svm2.h.

References kernel_type.

Referenced by KKMLL::ModelParamSvmBase::KernalType().

116 {return kernel_type;}
Kernel_Type kernel_type
Definition: svm2.h:132
svm_parameter & SVM289_MFS::svm_parameter::operator= ( const svm_parameter right)

Definition at line 264 of file svm2.cpp.

References C, cache_size, coef0, degree, eps, gamma, kernel_type, nr_weight, nu, p, probability, probParam, shrinking, svm_type, weight, and weight_label.

265 {
266  svm_type = right.svm_type;
267  kernel_type = right.kernel_type;
268  degree = right.degree;
269  gamma = right.gamma;
270  coef0 = right.coef0;
271  cache_size = right.cache_size;
272  eps = right.eps;
273  C = right.C;
274  nr_weight = right.nr_weight;
275  weight_label = NULL;
276  weight = NULL;
277  nu = right.nu;
278  p = right.p;
279  shrinking = right.shrinking;
280  probability = right.probability;
281  probParam = right.probParam;
282 
283  if (right.weight_label)
284  {
286  for (kkint32 x = 0; x < nr_weight; x++)
287  weight_label[x] = right.weight_label[x];
288  }
289 
290  if (right.weight)
291  {
292  weight = new double[nr_weight];
293  for (kkint32 x = 0; x < nr_weight; x++)
294  weight[x] = right.weight[x];
295  }
296 
297  return *this;
298 }
__int32 kkint32
Definition: KKBaseTypes.h:88
Kernel_Type kernel_type
Definition: svm2.h:132
kkint32 * weight_label
Definition: svm2.h:142
void SVM289_MFS::svm_parameter::ParseTabDelStr ( const KKStr _str)

Definition at line 452 of file svm2.cpp.

References C, cache_size, coef0, KKB::KKStr::Concat(), degree, KKB::KKStr::Empty(), eps, KKB::KKStr::EqualIgnoreCase(), KKB::KKStr::ExtractToken2(), KKB::KKStr::ExtractTokenDouble(), KKB::KKStr::ExtractTokenInt(), gamma, kernel_type, SVM289_MFS::Kernel_Type_FromStr(), nr_weight, nu, KKB::KKStr::operator==(), p, probability, probParam, shrinking, svm_type, SVM289_MFS::SVM_Type_FromStr(), KKB::KKStr::ToDouble(), KKB::KKStr::ToFloat(), KKB::KKStr::ToInt(), weight, and weight_label.

453 {
454  KKStr str = _str;
455  kkint32 x;
456 
457  while (!str.Empty ())
458  {
459  KKStr field = str.ExtractToken2 ("\t");
460  KKStr value = str.ExtractToken2 ("\t");
461  kkint32 valueI = value.ToInt ();
462  double valueD = value.ToDouble ();
463  float valueF = value.ToFloat ();
464 
465  if (field == "svm_type")
466  svm_type = SVM_Type_FromStr (value);
467 
468  else if (field == "kernel_type")
470 
471  else if (field == "degree")
472  degree = valueI;
473 
474  else if (field == "gamma")
475  gamma = valueD;
476 
477  else if (field == "coef0")
478  coef0 = valueD;
479  else if (field == "cache_size")
480  cache_size = valueD;
481 
482  else if (field == "eps")
483  eps = valueD;
484 
485  else if (field == "C")
486  C = valueD;
487 
488  else if (field == "nr_weight")
489  {
490  nr_weight = valueI;
491  if (nr_weight > 0)
492  {
493  delete[] weight_label;
495 
496  // value = weight label.
497  for (x = 0; x < nr_weight; x++)
498  {
499  weight_label[x] = value.ExtractTokenInt (",");
500  }
501 
502  delete[] weight;
503  weight = new double [nr_weight];
504  KKStr weightStr = str.ExtractToken2 ("\t");
505  for (x = 0; x < nr_weight; x++)
506  {
507  weight[x] = weightStr.ExtractTokenDouble (",");
508  }
509  }
510  }
511 
512  else if (field == "nu")
513  nu = valueD;
514 
515  else if (field == "p")
516  p = valueD;
517 
518  else if (field == "shrinking")
519  shrinking = valueI;
520 
521  else if (field == "probability")
522  probability = valueI;
523 
524  else if (field.EqualIgnoreCase ("probparam") || field.EqualIgnoreCase ("pp"))
525  probParam = valueD;
526  }
527 } /* ParseTabDelStr */
__int32 kkint32
Definition: KKBaseTypes.h:88
KKStr ExtractToken2(const char *delStr="\n\t\r ")
Extract first Token from the string.
Definition: KKStr.cpp:3026
Kernel_Type kernel_type
Definition: svm2.h:132
kkint32 ToInt() const
Definition: KKStr.cpp:3565
bool EqualIgnoreCase(const KKStr &s2) const
Definition: KKStr.cpp:1250
double ExtractTokenDouble(const char *delStr)
Definition: KKStr.cpp:3180
bool Empty() const
Definition: KKStr.h:241
SVM_Type SVM_Type_FromStr(KKStr s)
Definition: svm2.cpp:534
Kernel_Type Kernel_Type_FromStr(KKStr s)
Definition: svm2.cpp:564
double ToDouble() const
Definition: KKStr.cpp:3541
kkint32 ExtractTokenInt(const char *delStr)
Definition: KKStr.cpp:3129
kkint32 * weight_label
Definition: svm2.h:142
float ToFloat() const
Definition: KKStr.cpp:3553
void SVM289_MFS::svm_parameter::ProcessSvmParameter ( const KKStr cmd,
const KKStr value,
bool &  parmUsed 
)

Definition at line 330 of file svm2.cpp.

References C, cache_size, coef0, degree, eps, KKB::KKStr::EqualIgnoreCase(), gamma, kernel_type, SVM289_MFS::Kernel_Type_FromStr(), nr_weight, nu, p, probability, probParam, shrinking, svm_type, SVM289_MFS::SVM_Type_FromStr(), KKB::KKStr::ToBool(), KKB::KKStr::ToDouble(), and weight.

334 {
335  parmUsed = true;
336 
337  double valueNum = value.ToDouble ();
338 
339  if (cmd.EqualIgnoreCase ("-B") ||
340  cmd.EqualIgnoreCase ("-CP") ||
341  cmd.EqualIgnoreCase ("-CalcProb") ||
342  cmd.EqualIgnoreCase ("-CalcProbability")
343  )
344  {
345  if (value.ToBool ())
346  probability = 1;
347  else
348  probability = 0;
349  }
350 
351  else if (cmd.EqualIgnoreCase ("-C") || cmd.EqualIgnoreCase ("-Cost"))
352  C = valueNum;
353 
354  else if (cmd.EqualIgnoreCase ("-D"))
355  degree = (kkint32)valueNum;
356 
357  else if (cmd.EqualIgnoreCase ("-E"))
358  eps = valueNum;
359 
360  else if (cmd.EqualIgnoreCase ("-G") || cmd.EqualIgnoreCase ("-GAMMA"))
361  gamma = valueNum;
362 
363  else if (cmd.EqualIgnoreCase ("-H"))
364  shrinking = (kkint32)valueNum;
365 
366  else if (cmd.EqualIgnoreCase ("-M"))
367  cache_size = valueNum;
368 
369  else if (cmd.EqualIgnoreCase ("-N"))
370  nu = valueNum;
371 
372  else if (cmd.EqualIgnoreCase ("-P"))
373  p = valueNum;
374 
375  else if (cmd.EqualIgnoreCase ("-R"))
376  coef0 = valueNum;
377 
378  else if (cmd.EqualIgnoreCase ("-S"))
379  svm_type = SVM_Type_FromStr (value);
380 
381  else if (cmd.EqualIgnoreCase ("-T"))
383 
384  else if (cmd.EqualIgnoreCase ("-ProbParam") || cmd.EqualIgnoreCase ("-PP"))
385  probParam = valueNum;
386 
387  else if (cmd.EqualIgnoreCase ("-W"))
388  {
389  ++nr_weight;
390  weight_label = (kkint32 *) realloc (weight_label, sizeof (kkint32) * nr_weight);
391  weight = (double *) realloc (weight, sizeof (double) * nr_weight);
392  weight_label[nr_weight - 1] = atoi (cmd.SubStrPart (2).Str ());
393  weight[nr_weight - 1] = valueNum;
394  }
395  else
396  {
397  parmUsed = false;
398  }
399 } /* ProcessSvmParameter */
__int32 kkint32
Definition: KKBaseTypes.h:88
Kernel_Type kernel_type
Definition: svm2.h:132
bool EqualIgnoreCase(const KKStr &s2) const
Definition: KKStr.cpp:1250
SVM_Type SVM_Type_FromStr(KKStr s)
Definition: svm2.cpp:534
Kernel_Type Kernel_Type_FromStr(KKStr s)
Definition: svm2.cpp:564
double ToDouble() const
Definition: KKStr.cpp:3541
const char * Str() const
Returns a pointer to a ascii string.
Definition: KKStr.h:422
kkint32 * weight_label
Definition: svm2.h:142
bool ToBool() const
Returns the bool equivalent of the string, ex &#39;Yes&#39; = true, &#39;No&#39; = false, &#39;True&#39; = true...
Definition: KKStr.cpp:3523
KKStr SubStrPart(kkint32 firstChar) const
returns a SubString consisting of all characters starting at index &#39;firstChar&#39; until the end of the s...
Definition: KKStr.cpp:2780
void SVM289_MFS::svm_parameter::SvmType ( SVM_Type  _svm_type)
inline

Definition at line 112 of file svm2.h.

References svm_type.

Referenced by KKMLL::ModelParamSvmBase::ModelParamSvmBase(), and KKMLL::ModelParamSvmBase::SvmType().

112 {svm_type = _svm_type;}
SVM_Type SVM289_MFS::svm_parameter::SvmType ( ) const
inline

Definition at line 117 of file svm2.h.

References svm_type.

Referenced by KKMLL::ModelParamSvmBase::SvmType().

117 {return svm_type;}
KKStr SVM289_MFS::svm_parameter::ToCmdLineStr ( ) const

Definition at line 302 of file svm2.cpp.

References C, cache_size, coef0, KKB::KKStr::Concat(), degree, eps, gamma, kernel_type, KKB::KKStr::KKStr(), nu, p, probability, probParam, shrinking, and svm_type.

Referenced by KKMLL::ModelParamSvmBase::ToCmdLineStr().

303 {
304  KKStr cmdStr (200); // Initialized char* allocation to 200
305 
306  cmdStr << "-CalcProb " << ((probability == 1) ? "Yes" : "No") << " "
307  << "-c " << C << " "
308  << "-d " << degree << " "
309  << "-e " << eps << " "
310  << "-g " << gamma << " "
311  << "-h " << shrinking << " "
312  << "-m " << cache_size << " "
313  << "-n " << nu << " "
314  << "-p " << p << " ";
315 
316  if (probParam > 0.0)
317  cmdStr << "-ProbParam " << probParam << " ";
318 
319  cmdStr << "-r " << coef0 << " "
320  << "-s " << (int)svm_type << " "
321  << "-t " << (int)kernel_type << " ";
322 
323  return cmdStr;
324 }
Kernel_Type kernel_type
Definition: svm2.h:132
KKStr SVM289_MFS::svm_parameter::ToTabDelStr ( ) const

Definition at line 406 of file svm2.cpp.

References C, cache_size, coef0, KKB::KKStr::Concat(), degree, eps, gamma, kernel_type, SVM289_MFS::Kernel_Type_ToStr(), KKB::KKStr::KKStr(), nr_weight, nu, p, probability, probParam, shrinking, svm_type, SVM289_MFS::SVM_Type_ToStr(), weight, and weight_label.

Referenced by KKMLL::ModelParamSvmBase::WriteXML().

407 {
408  KKStr result (256);
409 
410  kkint32 x = 0;
411 
412  result << "svm_type" << "\t" << SVM_Type_ToStr (svm_type) << "\t"
413  << "kernel_type" << "\t" << Kernel_Type_ToStr (kernel_type) << "\t"
414  << "degree" << "\t" << degree << "\t"
415  << "gamma" << "\t" << gamma << "\t"
416  << "coef0" << "\t" << coef0 << "\t"
417  << "cache_size" << "\t" << cache_size << "\t"
418  << "eps" << "\t" << eps << "\t"
419  << "C" << "\t" << C << "\t"
420  << "nr_weight" << "\t" << nr_weight << "\t";
421 
422  if (nr_weight > 0)
423  {
424  for (x = 0; x < nr_weight; x++)
425  {
426  if (x > 0) result << ",";
427  result << weight_label[x];
428  }
429  result << "\t";
430 
431  for (x = 0; x < nr_weight; x++)
432  {
433  if (x > 0) result << ",";
434  result << weight[x];
435  }
436  result << "\t";
437  }
438 
439  result << "nu" << "\t" << nu << "\t"
440  << "p" << "\t" << p << "\t"
441  << "shrinking" << "\t" << shrinking << "\t"
442  << "probability" << "\t" << probability;
443 
444  if (probParam > 0.0)
445  result << "\t" << "ProbParam" << "\t" << probParam;
446 
447  return result;
448 } /* ToTabDelStr */
__int32 kkint32
Definition: KKBaseTypes.h:88
Kernel_Type kernel_type
Definition: svm2.h:132
KKStr Kernel_Type_ToStr(Kernel_Type kernelType)
Definition: svm2.cpp:580
kkint32 * weight_label
Definition: svm2.h:142
KKStr SVM_Type_ToStr(SVM_Type svmType)
Definition: svm2.cpp:549

Member Data Documentation

const char* SVM289_MFS::svm_parameter::kernel_type_table[]
static

Definition at line 153 of file svm2.h.

kkint32 SVM289_MFS::svm_parameter::nr_weight
double SVM289_MFS::svm_parameter::p
double SVM289_MFS::svm_parameter::probParam
const char* SVM289_MFS::svm_parameter::svm_type_table[]
static

Definition at line 151 of file svm2.h.

double* SVM289_MFS::svm_parameter::weight
kkint32* SVM289_MFS::svm_parameter::weight_label

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