hmm_1Dlg.cpp ( File view )

Description:...
  • By duandian 2013-10-03
  • View(s):442
  • Download(s):14
  • Point(s): 4
			// hmm_1Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "hmm_1.h"
#include "hmm_1Dlg.h"



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

/////////////////////////////////////////////////////////////////////////////
// CHmm_1Dlg dialog

CHmm_1Dlg::CHmm_1Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CHmm_1Dlg::IDD, pParent)
{

	//{
{
AFX_DATA_INIT(CHmm_1Dlg)
	//
}
}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

}

CHmm_1Dlg::~CHmm_1Dlg()
{

	delete [] m_pA[0];
	delete [] m_pA[1];
	delete [] m_pA[2];
	delete [] m_pA;

	delete [] m_pB[0];
	delete [] m_pB[1];
	delete [] m_pB[2];
	delete [] m_pB;

	if(m_pRltMatrix!=NULL)
	{

		for(int i=0; i<m_iDimA; i++)
		{

			if(m_pRltMatrix[i]!=NULL)
			{

				delete [] m_pRltMatrix[i];
				m_pRltMatrix[i] = NULL;
			
}
		
}

		delete [] m_pRltMatrix;
		m_pRltMatrix = NULL;
	
}

	if(m_plamda!=NULL)
	{

		for(int i=0; i<m_iDimA; i++)
		{

			if(m_plamda[i]!=NULL)
			{

				delete [] m_plamda[i];
				m_plamda[i] = NULL; 
			
}
		
}

		delete [] m_plamda;
		m_plamda = NULL;
	
}

}

void CHmm_1Dlg::DoDataExchange(CDataExchange* pDX)
{

	CDialog::DoDataExchange(pDX);
	//{
{
AFX_DATA_MAP(CHmm_1Dlg)
	DDX_Control(pDX, IDC_STATIC_INFO2, m_cInfo2);
	DDX_Control(pDX, IDC_STATIC_INFO1, m_cInfo1);
	DDX_Control(pDX, IDC_STATIC_INFO, m_cInfo);
	//
}
}AFX_DATA_MAP

}

BEGIN_MESSAGE_MAP(CHmm_1Dlg, CDialog)
	//{
{
AFX_MSG_MAP(CHmm_1Dlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	//
}
}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CHmm_1Dlg message handlers

BOOL CHmm_1Dlg::OnInitDialog()
{

	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here

	m_iDimA = 3;
	m_iDimB = 2;

	m_pA = new double*[m_iDimA];
	m_pA[0] = new double[m_iDimA];	m_pA[1] = new double[m_iDimA];	m_pA[2] = new double[m_iDimA];

	m_pA[0][0] = 0.9;	m_pA[0][1] = 0.05;		m_pA[0][2] = 0.05;
	m_pA[1][0] = 0.45;	m_pA[1][1] = 0.1;		m_pA[1][2] = 0.45;
	m_pA[2][0] = 0.45;	m_pA[2][1] = 0.45;		m_pA[2][2] = 0.1;
	
	m_pB = new double*[m_iDimA];
	m_pB[0] = new double[m_iDimB];	m_pB[1] = new double[m_iDimB];	m_pB[2] = new double[m_iDimB];
	m_pB[0][0] = 0.5;			m_pB[0][1] = 0.5;
	m_pB[1][0] = 0.75;			m_pB[1][1] = 0.25;
	m_pB[2][0] = 0.25;			m_pB[2][1] = 0.75;

	m_pPI = new double[m_iDimA];
	m_pPI[0] = double(1.0/3.0);
	m_pPI[1] = double(1.0/3.0);
	m_pPI[2] = double(1.0/3.0);


	m_hmm.SetHmmParam(m_iDimA, m_iDimB, m_pA, m_pB, m_pPI);


	m_iInputLen = 3;

	m_pRltMatrix = new double*[m_iDimA];
	for(int i=0; i<m_iDimA; i++)
	{

		m_pRltMatrix[i] = new double[m_iInputLen+1];
	
}

	m_plamda = new int*[m_iDimA];
	for(i=0; i<m_iDimA; i++)
	{

		m_plamda[i] = new int[m_iInputLen];
	
}
	

	m_plamda[0][0] = 0;
	m_plamda[1][0] = 0;
	m_plamda[2][0] = 0;

	return TRUE;  // return TRUE  unless you set the focus to a control

}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CHmm_1Dlg::OnPaint() 
{

	if (IsIconic())
	{

		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	
}
	else
	{

		CDialog::OnPaint();
	
}

}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CHmm_1Dlg::OnQueryDragIcon()
{

	return (HCURSOR) m_hIcon;

}



void CHmm_1Dlg::OnButton1() 
{

	int *Input;
	Input = new int[m_iInputLen];

	Input[0] = 0;
	Input[1] = 0;
	Input[2] = 1;

	//get result
	double result = m_hmm.Forward(Input, 3, m_pRltMatrix);
	

	CString s;
	s.Format("%f", result);
	m_cInfo.SetWindowText(s);

	s.Format("%f %f %f | %f %f %f | %f %f %f", 
		m_pRltMatrix[0][0],	m_pRltMatrix[1][0], m_pRltMatrix[2][0],
		m_pRltMatrix[0][1], m_pRltMatrix[1][1], m_pRltMatrix[2][1],
		m_pRltMatrix[0][2],	m_pRltMatrix[1][2], m_pRltMatrix[2][2]);
	m_cInfo1.SetWindowText(s);
	m_cInfo2.SetWindowText("");

	delete [] Input;

}


void CHmm_1Dlg::OnButton2() 
{


	int *Input;
	Input = new int[m_iInputLen];

	Input[0] = 0;
	Input[1] = 0;
	Input[2] = 1;
	
	//get result
	double result = m_hmm.Backward(Input, 3, m_pRltMatrix);

	CString s;
	s.Format("%f", result);
	m_cInfo.SetWindowText(s);

	s.Format("%f %f %f | %f %f %f | %f %f %f", 
		m_pRltMatrix[0][0],	m_pRltMatrix[1][0], m_pRltMatrix[2][0],
		m_pRltMatrix[0][1], m_pRltMatrix[1][1], m_pRltMatrix[2][1],
		m_pRltMatrix[0][2],	m_pRltMatrix[1][2], m_pRltMatrix[2][2]);
	m_cInfo1.SetWindowText(s);
	m_cInfo2.SetWindowText("");

	delete [] Input;

}


void CHmm_1Dlg::OnButton3() 
{


	//输入 序列
	int *Input;
	Input = new int[m_iInputLen];
	Input[0] = 0;
	Input[1] = 0;
	Input[2] = 1;

	int *bestpath;	//最佳路径
	bestpath = new int[m_iInputLen];

	//
	double result = m_hmm.Viterbi(Input, 3, bestpath, m_pRltMatrix, m_plamda);
	

	//显示结果
	CString s;
	s.Format("%f 最佳路径: %d %d %d", result, bestpath[0], bestpath[1], bestpath[2]);
	m_cInfo.SetWindowText(s);

	s.Format("%f %f %f | %f %f %f | %f %f %f", 
		m_pRltMatrix[0][0],	m_pRltMatrix[1][0], m_pRltMatrix[2][0],
		m_pRltMatrix[0][1], m_pRltMatrix[1][1], m_pRltMatrix[2][1],
		m_pRltMatrix[0][2],	m_pRltMatrix[1][2], m_pRltMatrix[2][2]);
	m_cInfo1.SetWindowText(s);

	s.Format("%d %d %d | %d %d %d | %d %d %d", 
		m_plamda[0][0],	m_plamda[1][0], m_plamda[2][0],
		m_plamda[0][1], m_plamda[1][1], m_plamda[2][1],
		m_plamda[0][2],	m_plamda[1][2], m_plamda[2][2]);
	m_cInfo2.SetWindowText(s);

	delete [] bestpath;
	delete [] Input;


}


			
...
Expand> <Close

Want complete source code? Download it here

Point(s): 4

Download
0 lines left, continue to read
Sponsored links

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
Hmm.cpp4.95 kB21-10-06 21:35
Hmm.h1.08 kB21-10-06 21:24
hmm_1.aps19.91 kB11-09-07 11:30
hmm_1.clw928.00 B21-09-07 15:59
hmm_1.cpp2.00 kB20-10-06 09:22
hmm_1.dsp4.16 kB21-10-06 21:36
hmm_1.dsw516.00 B20-10-06 09:22
hmm_1.h1.28 kB20-10-06 09:22
hmm_1.ncb57.00 kB21-09-07 16:02
hmm_1.opt52.50 kB21-09-07 16:02
hmm_1.plg697.00 B20-08-07 09:53
hmm_1.rc4.64 kB21-10-06 21:40
hmm_1Dlg.cpp6.37 kB29-07-07 15:18
hmm_1Dlg.h1.54 kB21-10-06 21:08
ReadMe.txt3.48 kB20-10-06 09:22
hmm_1.ico1.05 kB20-10-06 09:22
hmm_1.rc2397.00 B20-10-06 09:22
Thumbs.db3.00 kB11-09-07 12:11
resource.h775.00 B21-10-06 21:09
StdAfx.cpp207.00 B20-10-06 09:22
StdAfx.h1.03 kB20-10-06 09:22
<Debug>0.00 B08-11-07 10:03
<res>0.00 B11-09-07 12:11
<hmm源码-c>0.00 B21-09-07 16:02
...
Sponsored links

hmm_1Dlg.cpp (27.65 kB)

Need 4 point
Your Point(s)

Your Point isn't enough.

Get point immediately by PayPal

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more point

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com

切换到中文版?

CodeForge Chinese Version
CodeForge English Version

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D