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

📄 _mean_algorithm.cpp

📁 模式识别中的K近邻法和快速K近邻法的VC++实现
💻 CPP
字号:
// _Mean_Algorithm.cpp: implementation of the C_Mean_Algorithm class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "PR_exercise.h"
#include "_Mean_Algorithm.h"

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

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

C_Mean_Algorithm::C_Mean_Algorithm()
{
}

/*C_Mean_Algorithm::C_Mean_Algorithm(SampleSet& allsamples)
{
	AllSamples = allsamples;
}*/

C_Mean_Algorithm::~C_Mean_Algorithm()
{
}

//////////////////////////////////////////////////////////////////////
/*bool C_Mean_Algorithm::SetSampleSet(SampleSet& allsamples)
{
	AllSamples = allsamples;
}

int C_Mean_Algorithm::ReadSamplesFromFile(string &FileName)
{
}

int C_Mean_Algorithm::Categories(int C = 2)
{
	if(C = 2)return iCategories;
	iCategories = C;
	return iCategories;
}

bool C_Mean_Algorithm::InitialClassifying(int method)
{
}

void C_Mean_Algorithm::ReClassifying(void)
{
}

void C_Mean_Algorithm::GetSamplesTotal(void)
{
}

void C_Mean_Algorithm::CalculateMean(void)
{
}

double C_Mean_Algorithm::CalculateJudgeValue(void)
{
	dJe = 0.0;

	return dJe;
}

int C_Mean_Algorithm::Iterating(void)
{
	double OldJe, Delta = 1.0e100;
	InitialClassifying();
	Je = CalculateJudgeValue();
	OldJe = Je;

	for(int i = 0; i < 1000000; i++)
	{
		ReClassifying();
		Je = CalculateJudgeValue();
		Delta = OldJe - Je;
		Delta = (Delta>0)?Delta:(-Delta);	
		if(Delta < 1e-30)return 0;

	}
	return -1;
}

int C_Mean_Algorithm::GetOptimalCategories(void)
{
	int c = 1;
	Categories(c);
	if(Iterating())return 1;
	double Delta, NewDelta, DDelta, OldJe;
	OldJe = Je;
	Categories(c+1);
	if(Iterating())return 1;
	Delta = OldJe - Je;
	Delta = (Delta>0)?Delta:(-Delta);
	OldJe = Je;
	for(c = 3; c < 100; c++)
	{
		if(Iterating())return (c-1);
		NewDelta = OldJe - Je;
		NewDelta = (NewDelta>0)?NewDelta:(-NewDelta);
		DDelta = NewDelta - Delta;
		DDelta = (DDelta>0)?DDelta:(-DDelta);
		if((DDelta / Delta) < 0.1 || DDelta < 1e-6)return c;
		Delta = NewDelta;
	}
	return c;
}

void C_Mean_Algorithm::Standardizing(void)
{
}

void C_Mean_Algorithm::SetStandardMethod(StandMethod)
{
	NormalizeMethod = StandMethod;
}

void C_Mean_Algorithm::Normalization(void)
{

}

bool C_Mean_Algorithm::Allocation(void)
{
}

void C_Mean_Algorithm::Deallocation(void)
{
}

void C_Mean_Algorithm::GetStandardizeParameters(void)
{
	int i, j, k;
	double dmFactor, dvFactor;
	for(j = 0; j < iDimension; j++)
	{
		pdMean[0][j] = 0.0;
	}
	dmFactor = 1.0 / (double)iTotal; 
	dvactor = 1.0 / (double)(iTotal - 1); 
	for(i = 0; i < iTotal; i++)
	{
		for(j = 0; j < iDimension; j++)
		{
			pdMean[0][j] += dmFactor * AllSamples[i][j];
		}
	}
	for(i = 0; i < iTotal; i++)
	{
		for(j = 0; j < iDimension; j++)
		{
			NormalSamples[i][j] = AllSamples[i][j] - pdMean[0][j];
		}
	}
	for(i = 0; i < iTotal; i++)
	{
		for(j = 0; j < iDimension; j++)
		{
			for(k = 0; k < iDimension; k++)
			{
				x = AllSamples[i][j] - 
				pdVariance[j][k] += dvDactor * NormalSamples[i][j] * NormalSamples[i][k]];
			}
		}
	}

}
*/

⌨️ 快捷键说明

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