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

📄 lbg.cpp

📁 用LBG(Linde,Buzo,Gray)算法训练码本
💻 CPP
字号:
// LBG.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "LBG.h"
#include "Clustering.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// The one and only application object
double CodeBook[128][5]={
{  0.326171875, -1.440429688, -0.612304688, -0.874023438, -1.246582031},
{ -2.457031250, -2.234863281, -0.510253906,  1.419921875,  1.620117188},
{ -1.376464844, -1.307128906, -0.462890625, -1.379394531, -2.172851563},
{ -3.261230469, -0.166015625,  0.723632813, -0.623046875,  0.616210938},
{ -0.274414063, -3.299316406,  0.625488281,  0.087402344, -0.622070313},
{ -1.226562500, -3.481445313, -2.404785156,  3.375488281,  1.177246094},
{ -1.209960938, -0.076171875,  2.286621094, -1.891113281,  0.000000000},
{ -4.007812500,  1.044921875, -0.233398438, -1.359863281,  0.260253906},
{  0.922363281,  1.347167969,  0.674316406, -3.395996094, -2.887207031},
{  2.481445313, -1.201171875, -2.821289063,  0.877441406,  0.277343750},
{ -1.078125000, -1.615722656, -2.208496094, -3.044921875, -3.664550781},
{ -1.327636719,  2.127929688, -1.458984375, -0.561035156,  1.300781250},
{  0.614746094,  0.485839844,  1.323730469, -1.203125000, -5.073242188},
{  0.840820313, -3.695800781, -1.338867188,  1.060058594, -1.137207031},
{  0.503906250,  0.364746094, -0.418945313, -3.879882813, -6.270996094},
{  1.516601563,  2.371093750, -2.047363281, -1.240722656,  0.505371094},
{  0.909179688, -0.468750000, -3.236328125,  0.200195313,  2.872070313},
{ -1.217285156, -1.283203125, -1.953125000, -0.029296875,  3.516601563},
{ -1.304687500,  0.706054688,  0.750000000, -1.870605469,  0.602050781},
{ -2.588867188,  3.375000000,  0.775878906, -2.044433594,  1.789550781},
{ -1.687500000, -3.989257813, -3.764160156,  0.675781250,  2.293945313},
{ -2.294433594, -3.031738281, -5.457031250,  3.957031250,  8.217773438},
{  0.454101563,  3.419921875,  0.619628906, -4.383300781,  1.253417969},
{  2.270019531,  5.763671875,  1.680175781, -2.762207031,  0.585449219},
{  1.241210938, -0.089355469, -4.325683594, -3.894531250,  1.577148438},
{ -1.402343750, -0.981933594, -4.742675781, -4.094238281,  6.339355469},
{  1.506835938,  1.044921875, -1.796875000, -4.708496094, -1.414062500},
{ -3.715332031,  3.181152344, -1.114746094, -1.231445313,  3.091796875},
{ -1.627441406, -2.744140625, -4.458007813, -5.435058594,  2.706542969},
{ -0.198730469, -3.281738281, -8.528320313, -1.410644531,  5.648437500},
{  1.802734375,  3.318359375, -0.127929688, -5.295898438, -0.906250000},
{  3.552246094,  6.544921875, -1.459472656, -5.173339844,  2.410156250},
{  0.119140625, -1.083496094,  1.296875000,  1.843750000, -2.642578125},
{ -1.974121094, -2.897460938,  1.040527344,  0.421386719, -1.399414063},
{ -1.612304688,  0.851074219, -0.979492188, -0.062500000, -1.001953125},
{ -3.105957031,  1.631835938, -0.772949219, -0.010253906,  0.557617188},
{ -1.873535156, -0.894042969,  3.123535156,  1.242675781, -1.390625000},
{ -4.556640625, -3.187500000,  2.592285156,  0.969726563, -1.096191406},
{ -2.192382813,  0.365234375,  0.944824219, -1.478027344, -0.240722656},
{ -4.519042969,  2.620117188,  1.559082031, -2.193847656,  0.871093750},
{  2.335937500, -0.180664063,  0.911132813,  0.516113281, -0.922363281},
{  3.584960938, -1.313476563, -1.258300781,  0.330078125, -0.298339844},
{ -0.245117188,  1.091308594, -0.903320313, -0.867675781, -1.000488281},
{  0.493652344,  1.894531250, -1.203613281,  1.078613281, -0.074218750},
{  1.265625000,  1.381347656,  2.728515625,  1.386230469, -3.567382813},
{ -1.488769531, -2.401367188,  2.907714844,  4.492675781, -2.171386719},
{  0.340332031,  1.908203125,  2.831054688, -2.173339844, -2.267578125},
{ -1.035644531,  2.658203125, -1.254882813,  0.156738281, -0.586914063},
{  1.389648438, -1.018554688,  1.724609375,  0.276367188, -0.345703125},
{ -2.089355469,  0.463867188,  2.431640625,  1.830566406,  0.220703125},
{ -1.212890625,  1.709960938,  0.839355469, -0.083007813,  0.116210938},
{ -1.677246094,  0.128417969,  1.032226563, -0.979003906,  1.152832031},
{ -3.583007813, -0.589843750,  4.563964844, -0.593750000, -1.959472656},
{ -6.590820313, -0.214355469,  3.919921875, -2.066406250,  0.176269531},
{ -1.820800781,  2.652832031,  0.978515625, -2.308105469, -0.614746094},
{ -1.946289063,  3.780761719,  4.115722656, -1.802246094, -0.481933594},
{  2.538085938, -0.206542969,  0.561523438, -0.625488281,  0.398437500},
{  3.617675781,  2.006347656, -1.928222656,  1.313476563,  0.014648438},
{  0.608398438,  1.491699219, -0.017089844, -0.668945313, -0.120117188},
{ -0.727050781,  2.751464844, -0.331054688, -1.282714844,  1.547851563},
{  2.358398438, -2.238769531,  0.980468750, -0.518554688,  0.390136719},
{ -0.062988281,  0.350097656,  2.243164063,  7.293457031,  5.227539063},
{  0.203613281,  1.347167969,  0.903320313, -2.469238281, -0.562988281},
{ -1.897949219,  3.594238281, -2.816406250,  2.092285156,  0.325195313},
{  0.704589844, -0.458007813,  0.009765625, -1.034667969, -0.828613281},
{ -1.812500000, -1.661132813, -1.080078125,  0.053710938,  1.042968750},
{ -1.441406250,  0.005859375, -0.765625000, -1.708984375, -0.905761719},
{ -0.642089844, -0.845214844,  0.566406250, -0.272460938,  0.834472656},
{  0.042968750, -2.230957031,  0.094726563, -0.221679688, -1.443847656},
{ -1.386230469, -0.813476563, -0.133300781,  1.017578125, -0.075683594},
{ -0.092285156, -1.160156250,  0.812011719, -0.507812500, -1.195800781},
{ -1.387695313, -0.668457031,  0.310546875, -0.121093750, -1.307128906},
{  0.740722656,  0.038574219, -1.471191406, -1.791503906, -0.475097656},
{  0.934082031, -1.217285156, -2.593750000, -0.365722656,  0.620605469},
{ -1.417480469, -1.623046875, -1.833984375, -1.801757813, -0.893066406},
{ -1.422363281, -0.755371094, -1.347656250, -0.686523438,  0.548828125},
{  0.900390625, -0.895507813,  0.222656250,  0.344726563, -2.085937500},
{  0.228027344, -2.078125000, -0.932128906,  0.742675781,  0.553710938},
{ -0.062011719, -0.485351563, -0.311035156, -0.728027344, -3.170898438},
{  0.426269531, -0.998535156, -1.869140625, -1.363281250, -0.282226563},
{  1.128417969, -0.887207031,  1.285156250, -1.490234375,  0.960937500},
{  0.312988281,  0.583007813,  0.924316406,  2.005371094,  3.096679688},
{ -0.021972656,  0.584960938,  1.054687500, -0.707519531,  1.075683594},
{ -0.978515625,  0.836425781,  1.717773438,  1.294921875,  2.075683594},
{  1.433593750, -1.937500000,  0.625000000,  0.063964844, -0.720703125},
{  1.380371094,  0.003906250, -0.941406250,  1.297851563,  1.715332031},
{  1.562011719, -0.398437500,  1.312011719, -0.850097656, -0.687011719},
{  1.439453125,  1.967285156,  0.192382813, -0.123535156,  0.633789063},
{  2.092773438,  0.024902344, -2.200683594, -0.015625000, -0.321777344},
{  1.905761719,  2.756835938, -2.728515625, -1.265625000,  2.786621094},
{ -0.295898438,  0.602539063, -0.784667969, -2.532714844,  0.324218750},
{ -0.256347656,  1.767578125, -1.070312500, -1.233886719,  0.833496094},
{  2.098144531, -1.587402344, -1.114746094,  0.396484375, -1.105468750},
{  2.814941406,  0.257812500, -1.604980469,  0.660156250,  0.816406250},
{  1.335449219,  0.605957031, -0.538574219, -1.598144531, -1.663574219},
{  1.969238281,  0.804687500, -1.447753906, -0.573242188,  0.705078125},
{  0.036132813,  0.448242188,  0.976074219,  0.446777344, -0.500976563},
{ -1.218750000, -0.783691406,  0.993164063,  1.440429688,  0.111816406},
{ -1.058593750,  0.994628906,  0.007324219, -0.617187500, -0.101562500},
{ -1.734375000,  0.747070313,  0.283691406,  0.728027344,  0.469726563},
{ -1.275878906, -1.141601563,  1.768066406, -0.726562500, -1.066894531},
{ -0.853027344,  0.039550781,  2.704101563,  0.699218750, -1.102050781},
{ -0.497558594,  0.423339844,  0.104492188, -1.115234375, -0.737304688},
{ -0.822265625,  1.375000000, -0.111816406,  1.245605469, -0.678222656},
{  1.321777344,  0.246093750,  0.233886719,  1.358886719, -0.492675781},
{  1.229003906, -0.726074219, -0.779296875,  0.303222656,  0.941894531},
{ -0.072265625,  1.077148438, -2.093750000,  0.630859375, -0.684082031},
{ -0.257324219,  0.606933594, -1.333496094,  0.932128906,  0.625000000},
{  1.049316406, -0.732910156,  1.800781250,  0.297851563, -2.241699219},
{  1.614257813, -1.645019531,  0.915527344,  1.775390625, -0.594238281},
{  1.256835938,  1.227050781,  0.707519531, -1.500976563, -2.431152344},
{  0.397460938,  0.891601563, -1.219238281,  2.067382813, -1.990722656},
{  0.812500000, -0.107421875,  1.668945313,  0.489257813,  0.544433594},
{  0.381347656,  0.809570313,  1.913574219,  2.993164063,  1.533203125},
{  0.560546875,  1.984863281,  0.740234375,  0.397949219,  0.097167969},
{  0.581542969,  1.215332031,  1.250488281,  1.182128906,  1.192871094},
{  0.375976563, -2.888183594,  2.692871094, -0.179687500, -1.562011719},
{  0.581054688,  0.511230469,  1.827148438,  3.382324219, -1.020019531},
{  0.142578125,  1.513183594,  2.103515625, -0.370117188, -1.198730469},
{  0.255371094,  1.914550781,  1.974609375,  0.676757813,  0.041503906},
{  2.132324219,  0.491210938, -0.611328125, -0.715820313, -0.675292969},
{  1.880859375,  0.770996094, -0.037597656,  1.007812500,  0.423828125},
{  2.494628906,  1.425292969, -0.098632813,  0.175292969, -0.248535156},
{  1.782226563,  1.565429688,  1.124511719,  0.826660156,  0.632812500},
{  1.418457031, -1.907714844,  0.111816406, -0.583984375, -1.138671875},
{  2.918457031, -1.750488281,  0.393066406,  1.867675781, -1.532226563},
{  1.829101563, -0.295898438,  0.025878906, -0.131347656, -1.611816406},
{  0.295898438,  0.985351563, -0.642578125,  1.984375000,  0.194335938}
};
CWinApp theApp;

using namespace std;

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
	int nRetCode = 0;

	// initialize MFC and print and error on failure
	if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
	{
		// TODO: change error code to suit your needs
		cerr << _T("Fatal Error: MFC initialization failed") << endl;
		nRetCode = 1;
	}
	else
	{
		// TODO: code your application's behavior here.
		int N=128;
		int M=128;
		VQ_VECTOR *vqx=new VQ_VECTOR[128];
		VQ_CENTER *vqy=new VQ_CENTER[128];
		int i,j;
		for(i=0;i<128;i++)
		{
			vqx[i].Data=new double[5];
			vqy[i].Data=new double[5];
			for(j=0;j<5;j++)
				vqx[i].Data[j]=CodeBook[i][j]*2048;
			vqx[i].nCluster=i;
			vqx[i].nDimension=5;
			vqy[i].nDimension=5;
		}
		LBGCluster(vqx,N,vqy,M);
		DumpClusterData("e:\\data\\test.dat",vqx,N,vqy,M);

		for(i=0;i<128;i++)
		{
			delete vqx[i].Data;
			delete vqy[i].Data;
		}
		delete vqx;
		delete vqy;


	}

	return nRetCode;
}


⌨️ 快捷键说明

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