コード例 #1
0
ファイル: main.cpp プロジェクト: bigsmiles/TCfinal
int main()
{
	clock_t start,finish;
	time_t tStart,tFinish;
	double totaltime;
	tStart = time(&tStart);
	start = clock();
	
	//将训练集下的文本分词后,保存为myDic.txt(DF词典)和myTFDic(TF词典)
    //myParagraphProcess("E:\\finalData\\1_train",myDicPath,myTFDicPath);

	//卡方检验特征选择
	//chiFeatureSelect(myDicPath);
	//期望交叉熵特征选择——从词频词典中选取
	//expectedCrossEntrophyFeatureSelect(myTFDicPath);

	 /*myParagraphProcessToVSM(textTrainDataPath,VSMDesPath);
	myParagraphProcessToVSM(textTestDataPath,VSMtestDesPath);*/

	//基于CHI特征向量将训练和测试文本向量化——记得 去掉 宏定义_CROSS
	//myParagraphProcessToVSM(textTrainDataPath,textOfTrainVSMOnCHI);
	//myParagraphProcessToVSM(textTestDataPath,textOfTestVSMOnCHI);

	//基于ECE特征向量将训练和测试文本向量化——记得 加上 宏定义_CROSS
	//myParagraphProcessToVSM(textTrainDataPath,textOfTrainVSMOnCross);
	//myParagraphProcessToVSM(textTestDataPath,textOfTestVSMOnCross);

	//基于CHI特征向量将训练和测试文本向量化(Bayes)——记得 去掉 宏定义_CROSS
	//myTextToVSMforNaiveBayes(textTestDataPath,naiveBayesOfTestVSMOnCHI);
	//基于ECE特征向量将训练和测试文本向量化(Bayes)——记得 加上 宏定义_CROSS
	//myTextToVSMforNaiveBayes(textTestDataPath,naiveBayesOfTestVSMOnCross);


	//基于CHI特征向量的KNN分类——记得 去掉 宏定义_CROSS
	//KNN(textOfTrainVSMOnCHI,textOfTestVSMOnCHI);
	//基于ECE特征向量的KNN分类——记得 加上 宏定义_CROSS
	//KNN(textOfTrainVSMOnCross,textOfTestVSMOnCross);

	//基于CHI特征向量的NB分类——记得 去掉 宏定义_CROSS
	//naiveBayes(naiveBayesOfTestVSMOnCHI);
	//基于ECE特征向量的NB分类——记得 加上 宏定义_CROSS
	naiveBayes(naiveBayesOfTestVSMOnCross);

	evaluateResult(artNum,P,8);
	
	 


	 finish = clock();
	 tFinish = time(&tFinish);
	 totaltime = (finish - start) / CLOCKS_PER_SEC;
	 cout<<totaltime-(totaltime/60)*60<<"秒   "<<"运行时间:"<<tFinish - tStart<<endl;

	return 0;
}
コード例 #2
0
/**************************************************************************************************
* Analyze the terrain and assign the proper type
**************************************************************************************************/
void TerrainAnalyzer::analyze(SmurfPolygon*** terrain, int w, int h, float maxHeight, float minHeight) {
	// Iterate through the terrain and analyze each individual terrain piece of terrain
	for(int i = 0; i < h; i++) {
		for(int j = 0; j < w; j+=2) {
			// Clear the probabilities
			clearProbabilities();
			
			// Choose the a piece of terrain and analyze it
			//**********************************************************************************************
			// Analyze slope
			analyzeSlope(terrain[i][j]);

			// Analyze height
			analyzeHeight(terrain[i][j], maxHeight, minHeight);

			/* Analyze adjacent terrains
			* Even
			*	i-1: j-1, j, j+1, j+2, j+3
			*	i: j-2, j-1
			* Odd 
			*	i-1: j, j+1, j+2
			*	i: j-2, j-1
			*/
			int adjacentAnalyzed = 0;
			if(i % 2 == 0) {	// Even
				// case: i - 1
				if(i - 1 >= 0) {
					if(j - 1 >= 0) {
						analyzeAdjacent(terrain[i][j], terrain[i-1][j-1]);
						adjacentAnalyzed++;
					}

					analyzeAdjacent(terrain[i][j], terrain[i-1][j]);
					adjacentAnalyzed++;

					if(j + 1 < w) {
						analyzeAdjacent(terrain[i][j], terrain[i-1][j+1]);
						adjacentAnalyzed++;
					}
					if(j + 2 < w) {
						analyzeAdjacent(terrain[i][j], terrain[i-1][j+2]);
						adjacentAnalyzed++;
					}
					if(j + 3 < w) {
						analyzeAdjacent(terrain[i][j], terrain[i-1][j+3]);
						adjacentAnalyzed++;
					}
				}

				// case: i
				if(j - 2 >= 0) {
					analyzeAdjacent(terrain[i][j], terrain[i][j-2]);
					adjacentAnalyzed++;
				}
				if(j - 1 >= 0) {
					analyzeAdjacent(terrain[i][j], terrain[i][j-1]);
					adjacentAnalyzed++;
				}
			} else {	// Odd
				// case: i - 1
				if(i - 1 >= 0) {
					analyzeAdjacent(terrain[i][j], terrain[i-1][j]);
					adjacentAnalyzed++;

					if(j + 1 < w) {
						analyzeAdjacent(terrain[i][j], terrain[i-1][j+1]);
						adjacentAnalyzed++;
					}
					if(j + 2 < w) {
						analyzeAdjacent(terrain[i][j], terrain[i-1][j+2]);
						adjacentAnalyzed++;
					}
				}

				// case: i
				if(j - 2 >= 0) {
					analyzeAdjacent(terrain[i][j], terrain[i][j-2]);
					adjacentAnalyzed++;
				}
				if(j - 1 >= 0) {
					analyzeAdjacent(terrain[i][j], terrain[i][j-1]);
					adjacentAnalyzed++;
				}					
			}

			if(adjacentAnalyzed == 0)
				adjacentAnalyzed = 1;
			
			// Find the average probability of the adjacent values
			for(int k = 0; k < 6; k++) {
				// Edge case testing. This is to prevent a band of the most probable substance at the seeding 
				// corner, essentially this causes the entire first row of values to act as a seed rather than the first value.
				if(i == 0)
					terrainProbabilities[k][3] = 0.1f;
				else
					terrainProbabilities[k][3] = terrainProbabilities[k][3] / (float)adjacentAnalyzed;
			}

			// Use naive bayes for final analysis of probabilities
			naiveBayes();
			
			// assign terrain type
			assignType(terrain[i][j]);
			assignType(terrain[i][j+1]);
		}
	}
}