kwspot.cpp
资源名称:VQ-DHMM.rar [点击查看]
上传用户:avbj512
上传日期:2013-09-18
资源大小:6239k
文件大小:12k
源码类别:
DSP编程
开发平台:
Visual C++
- // DHMM_MFC.cpp:
- // Defines the entry point for the console application.
- //
- // Created 2001/08, By DongMing, MDSR.
- //
- /////////////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "kwspot.h"
- #include "DHMM_VQ_MFC.h"
- #include "DHMM_Model_MFC.h"
- #include "DHMM_Recog_MFC.h"
- #include <direct.h>
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // Private functions
- int TheMain(void);
- void Init(void);
- void KittyInit(void);
- void Init_Pro_Config(void);
- CString FindProp(CString Prop);
- void Run(void);
- void Done(void);
- /////////////////////////////////////////////////////////////////////////////
- // Global variables
- PRO_CONFIG u_Pro_Config;
- /////////////////////////////////////////////////////////////////////////////
- // The one and only application object
- 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.
- nRetCode = TheMain();
- }
- return nRetCode;
- }
- // 因为MFC程序框架的原因,此处是程序的main()
- static int TheMain(void)
- {
- char sz_Date_Time[64];
- int n_Loop_Index, n_Rotate_Test_Index;
- // n_Loop_Index = 0x6789;
- Init_Pro_Config();
- // 写Result.txt,程序结果纪录
- _strdate(sz_Date_Time);
- RESULT_LOG("Current Date: %s, ", sz_Date_Time);
- _strtime(sz_Date_Time);
- RESULT_LOG("Time: %s.n", sz_Date_Time);
- RESULT_LOG("Total persons Num = %3d, Training set persons Num = %3d.n", u_Pro_Config.n_Feature_Person_Num, u_Pro_Config.n_DHMM_Model_Train_Set_Person_Num);
- RESULT_LOG("ttCoefficientttStart_PersonttAccurate_Raten", u_Pro_Config.d_Feature_DT_MFCC_Coefficient / 3, u_Pro_Config.n_DHMM_Model_Person_Start_Index, u_Pro_Config.d_Recognition_Accurate_Rate);
- RESULT_LOG("================================================================================n");
- // 第一层循环,循环DT MFCC的倍乘系数
- for (n_Loop_Index = 0; n_Loop_Index < u_Pro_Config.n_Loop_Num; n_Loop_Index++)
- {
- u_Pro_Config.d_Feature_DT_MFCC_Coefficient = 3 * (u_Pro_Config.d_Feature_DT_MFCC_Coefficient_Start + 0.03F * n_Loop_Index);
- // 写DHMM.log,程序运行信息纪录
- TRACE("nProgram Started ...n");
- PRO_LOG("nProgram Started ...n");
- _strdate(sz_Date_Time);
- PRO_LOG("tCur Date: %s, ", sz_Date_Time);
- _strtime(sz_Date_Time);
- PRO_LOG("Time: %s.n", sz_Date_Time);
- PRO_LOG("tDT_MFCC_Coefficient = %10.4f.nn", u_Pro_Config.d_Feature_DT_MFCC_Coefficient / 3.0F);
- double * pd = new double[u_Pro_Config.n_Rotate_Test_Num];
- ASSERT(pd != NULL);
- // 第二层循环,循环滚动测试的训练集与测试集
- for (n_Rotate_Test_Index = 0; n_Rotate_Test_Index < u_Pro_Config.n_Rotate_Test_Num; n_Rotate_Test_Index++)
- {
- PRO_LOG("Leave-one-out Loop: %4d/%4d.n", n_Rotate_Test_Index, u_Pro_Config.n_Rotate_Test_Num);
- u_Pro_Config.n_DHMM_Model_Person_Start_Index = (u_Pro_Config.n_DHMM_Model_Person_Start_Index + (u_Pro_Config.n_Feature_Person_Num / u_Pro_Config.n_Rotate_Test_Num) * n_Rotate_Test_Index) % u_Pro_Config.n_Feature_Person_Num;
- u_Pro_Config.n_DHMM_Model_Person_End_Index = (u_Pro_Config.n_DHMM_Model_Train_Set_Person_Num + u_Pro_Config.n_DHMM_Model_Person_Start_Index - 1) % u_Pro_Config.n_Feature_Person_Num;
- u_Pro_Config.n_Recog_Person_Start_Index = (u_Pro_Config.n_DHMM_Model_Person_End_Index + 1) % u_Pro_Config.n_Feature_Person_Num;
- u_Pro_Config.n_Recog_Person_End_Index = (u_Pro_Config.n_Recog_Person_Start_Index + u_Pro_Config.n_Recog_Set_Person_Num - 1) % u_Pro_Config.n_Feature_Person_Num;
- sprintf(u_Pro_Config.sz_Toload_Code_Book_File_Name, u_Pro_Config.sz_Toload_Code_Book_File_fmt, n_Rotate_Test_Index);
- sprintf(u_Pro_Config.sz_Toload_DHMM_Model_File_Name, u_Pro_Config.sz_Toload_DHMM_Model_File_fmt, n_Rotate_Test_Index);
- Run();
- pd[n_Rotate_Test_Index] = u_Pro_Config.d_Recognition_Accurate_Rate;
- }
- // 统计识别率。
- double d = 0.0F;
- for (n_Rotate_Test_Index = 0; n_Rotate_Test_Index < u_Pro_Config.n_Rotate_Test_Num; n_Rotate_Test_Index++)
- d += pd[n_Rotate_Test_Index];
- RESULT_LOG("nAvg. Accuracy Rate = %8.4f.nn", d / u_Pro_Config.n_Rotate_Test_Num);
- RESULT_LOG("Code_Book_Size = %4d.t", u_Pro_Config.n_VQ_Code_Book_Size);
- RESULT_LOG("tDHMM_Model_Num = %4d.t", u_Pro_Config.n_DHMM_Model_Num);
- RESULT_LOG("tDHMM_Model_State_Num = %4d.tn", u_Pro_Config.n_DHMM_Model_State_Num);
- delete [] pd;
- }
- RESULT_LOG("n");
- TRACE("Program Ended ...nn");
- PRO_LOG("Program Ended ...n");
- Done();
- return 0;
- }
- static void Init_Pro_Config(void)
- {
- memset(&u_Pro_Config, 0, sizeof(u_Pro_Config));
- u_Pro_Config.l_Prgram_Start_Time = time(NULL);
- u_Pro_Config.n_Loop_Num = 1;
- u_Pro_Config.n_Rotate_Test_Num = 1;
- strcpy(u_Pro_Config.sz_Program_Log_File_Name, "..\..\DATA\DHMM.LOG");
- strcpy(u_Pro_Config.sz_Result_File_Name, "..\..\DATA\Result.TXT");
- char buffer[_MAX_PATH];
- /* Get the current working directory: */
- if( _getcwd( buffer, _MAX_PATH ) == NULL )
- perror( "_getcwd error" );
- else
- printf( "%sn", buffer );
- u_Pro_Config.n_Feature_Person_Num = 100;
- CString pv = FindProp("Feature_Person_Num");
- if (pv != "