⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tool.cpp

📁 用于有指导分类器的分类特征进行选择的算法
💻 CPP
字号:
// Tool.cpp: implementation of the Tool class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "FSelect.h"
#include "Tool.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

Tool::Tool()
{

}

Tool::~Tool()
{

}

void Tool::Initialize()
{
	CStdioFile fIn("data_svm.txt.fscore",CFile::modeRead);
	CString strLine;
	while(fIn.ReadString(strLine))
	{
		int pos1=strLine.Find(":");
		CString strFeature=strLine.Left(pos1);
		int pos2=strLine.Find("0",pos1);
		CString strValue=strLine.Mid(pos2,strLine.GetLength()-pos2);
		float fValue=atof(LPCSTR(strValue));
		m_mapFScore.insert(make_pair(strFeature,fValue));
	}

}

void Tool::Select()
{
	CStdioFile fIn("data_svm.txt",CFile::modeRead);
	CStdioFile fOut("s_train_data.txt",CFile::modeCreate|CFile::modeWrite);
	CString strLine;
	while(fIn.ReadString(strLine))
	{
		CString strOutLine="";
		int pos1=strLine.Find(" ");
		strOutLine=strOutLine+strLine.Left(pos1);
		pos1++;
		while(pos1<strLine.GetLength()&&pos1!=-1)
		{
           int pos2=strLine.Find(":",pos1);
		   CString strFeature=strLine.Mid(pos1,pos2-pos1);
		   CString strValue;
		   int pos3=strLine.Find(" ",pos2);
		   if(pos3==-1)
              strValue=strLine.Mid(pos2+1,strLine.GetLength()-pos2-1);
		   else
			   strValue=strLine.Mid(pos2+1,pos3-pos2-1);
			  
		   map<CString,float>::iterator iter=m_mapFScore.find(strFeature);
		   if(iter!=m_mapFScore.end()&&iter->second>0.0001)
		   {
               strOutLine=strOutLine+" "+strFeature+":"+strValue;
		   }
		   pos1=strLine.Find(" ",pos2);
		   if(pos1!=-1)
		       pos1++;
		}
		strOutLine+="\n";
		fOut.WriteString(strOutLine);
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -