Compute_Param.cpp
上传用户:sanxfzhen
上传日期:2014-12-28
资源大小:2324k
文件大小:3k
源码类别:

多国语言处理

开发平台:

Visual C++

  1. // Compute_Param.cpp: implementation of the CCompute_Param class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "Compute_Param.h"
  6. #ifdef _DEBUG
  7. #undef THIS_FILE
  8. static char THIS_FILE[]=__FILE__;
  9. #define new DEBUG_NEW
  10. #endif
  11. //////////////////////////////////////////////////////////////////////
  12. // Construction/Destruction
  13. //////////////////////////////////////////////////////////////////////
  14. CCompute_Param::CCompute_Param()
  15. {
  16. biased_Hyperplane=1;
  17. remove_inconsitant=0;
  18. C                =0.0;
  19. cost_factor      =1.0;
  20. loo              =0;
  21. search_depth     =0;
  22. rho              =1.0;
  23. fraction         =1.0;
  24. rbf_gamma        =1.0;
  25. poly_c           =0.0;
  26. poly_s           =1.0;
  27. poly_degree      =1;
  28. kernel_type      =0;
  29. epsion           =0.001;
  30. iteration_time   =100;
  31. cache_size       =40;
  32. new_variable     =10;
  33. maximum_size     =10;
  34. final_test       =1;
  35. classifier_num   =0;
  36. classifier_type  =0;
  37. running          =0;
  38. paused           =false;
  39. }
  40. CCompute_Param::~CCompute_Param()
  41. {
  42. }
  43. void CCompute_Param::Serialize(CArchive &ar)
  44. {
  45. if(ar.IsStoring())
  46. {
  47. ar<<C;
  48. ar<<cost_factor;
  49. ar<<biased_Hyperplane;
  50. ar<<remove_inconsitant;
  51. ar<<loo;
  52. ar<<rho;
  53. ar<<search_depth;
  54. ar<<fraction;
  55. ar<<kernel_type;
  56. ar<<poly_degree;
  57. ar<<rbf_gamma;
  58. ar<<poly_s;
  59. ar<<poly_c;
  60. ar<<maximum_size;
  61. ar<<new_variable;//2..maximun_size
  62. ar<<cache_size;//5..,the larger, the faster
  63. ar<<epsion;
  64. ar<<iteration_time;//default 100
  65. ar<<final_test;//default 1, to do final test.
  66. ar<<classifier_num;
  67. ar<<classifier_type;
  68. ar<<trainfile;
  69. ar<<modelfile;
  70. ar<<resultfile;
  71. ar<<classifyfile;
  72. ar<<matrixfile;
  73. ar<<resultpath;
  74. ar<<Coff[2];
  75. }
  76. else
  77. {
  78. ar>>C;
  79. ar>>cost_factor;
  80. ar>>biased_Hyperplane;
  81. ar>>remove_inconsitant;
  82. ar>>loo;
  83. ar>>rho;
  84. ar>>search_depth;
  85. ar>>fraction;
  86. ar>>kernel_type;
  87. ar>>poly_degree;
  88. ar>>rbf_gamma;
  89. ar>>poly_s;
  90. ar>>poly_c;
  91. ar>>maximum_size;
  92. ar>>new_variable;//2..maximun_size
  93. ar>>cache_size;//5..,the larger, the faster
  94. ar>>epsion;
  95. ar>>iteration_time;//default 100
  96. ar>>final_test;//default 1, to do final test.
  97. ar>>classifier_num;
  98. ar>>classifier_type;
  99. ar>>trainfile;
  100. ar>>modelfile;
  101. ar>>resultfile;
  102. ar>>classifyfile;
  103. ar>>matrixfile;
  104. ar>>resultpath;
  105. ar>>Coff[2];
  106. }
  107. }
  108. void CCompute_Param::DumpToFile(CString strFileName)
  109. {
  110. CFile fBinOut;
  111. if(!fBinOut.Open(strFileName,CFile::modeWrite | CFile::modeCreate) )
  112. {
  113. AfxMessageBox( "无法创建文件"+strFileName+"!") ;
  114. return;
  115. }
  116. CArchive ar(&fBinOut,CArchive::store);
  117. Serialize(ar);
  118. ar.Close();
  119. fBinOut.Close();
  120. }
  121. bool CCompute_Param::GetFromFile(CString strFileName)
  122. {
  123. CFile fBinIn;
  124. if(!fBinIn.Open(strFileName,CFile::modeRead) )
  125. {
  126. AfxMessageBox( "无法打开文件"+strFileName+"!");
  127. return false;
  128. }
  129. CArchive ar(&fBinIn,CArchive::load);
  130. Serialize(ar);
  131. ar.Close();
  132. fBinIn.Close();
  133. return true;
  134. }