📄 dlgbn_naviebayesianclassfier.cpp
字号:
// DlgBN_NavieBayesianClassfier.cpp : implementation file
//
#include "stdafx.h"
#include "AI.h"
#include "DlgBN_NavieBayesianClassfier.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
const int PANES_Row=11;
const int PANES_Col=9;
const int PANE_Height=12;
const int PANE_Width=12;
const COLORREF PANES_BkColor=RGB(255,255,255);//RGB(0xd4,0xd0,0xc8);
const COLORREF PANES_BorderColor=RGB(0x0,0x4d,0x99);
const COLORREF PANE_FillColor=RGB(0,125,0);//RGB(0,0,0);
const COLORREF PANE_NullColor=PANES_BkColor;//RGB(255,255,0);
const int PANES_x10=40;
const int PANES_y10=40;
const int PANES_x11=PANES_x10+PANE_Width*PANES_Col;
const int PANES_y11=PANES_y10+PANE_Height*PANES_Row;
const int PANES_x20=PANES_x11+PANE_Width*5;
const int PANES_y20=PANES_y10;
const int PANES_x21=PANES_x20+PANE_Width*PANES_Col;
const int PANES_y21=PANES_y20+PANE_Height*PANES_Row;
const M=10,N=PANES_Row*PANES_Col,Q=10;
/////////////////////////////////////////////////////////////////////////////
// CDlgBN_NavieBayesianClassfier dialog
CDlgBN_NavieBayesianClassfier::CDlgBN_NavieBayesianClassfier(CWnd* pParent /*=NULL*/)
: CDialog(CDlgBN_NavieBayesianClassfier::IDD, pParent)
{
//{{AFX_DATA_INIT(CDlgBN_NavieBayesianClassfier)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CDlgBN_NavieBayesianClassfier::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgBN_NavieBayesianClassfier)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlgBN_NavieBayesianClassfier, CDialog)
//{{AFX_MSG_MAP(CDlgBN_NavieBayesianClassfier)
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONUP()
ON_BN_CLICKED(IDC_BUTTON_Study, OnBUTTONStudy)
ON_BN_CLICKED(IDC_BUTTON_Ontroduce, OnBUTTONOntroduce)
ON_BN_CLICKED(IDC_BUTTON_Work, OnBUTTONWork)
ON_BN_CLICKED(IDC_BUTTON_Clear, OnBUTTONClear)
ON_BN_CLICKED(IDC_BUTTON_Sample, OnBUTTONSample)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDlgBN_NavieBayesianClassfier message handlers
BOOL CDlgBN_NavieBayesianClassfier::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
pTable1=new CPanes(this,PANES_x10,PANES_y10,PANES_Row,PANES_Col,PANE_Height,PANE_Width,RGB(0,0,0),RGB(0,150,0),RGB(0,230,0),RGB(0,0,0),1,"书写区");
pTable2=new CPanes(this,PANES_x20,PANES_y20,PANES_Row,PANES_Col,PANE_Height,PANE_Width,RGB(0,0,0),RGB(0,150,0),RGB(0,230,0),RGB(0,0,0),1,"识别区");
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDlgBN_NavieBayesianClassfier::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
pTable1->Draw();
pTable2->Draw();
// Do not call CDialog::OnPaint() for painting messages
}
void CDlgBN_NavieBayesianClassfier::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
pTable1->DoLButtonDown(point);
//pTable2->DoLButtonDown(point);
CDialog::OnLButtonDown(nFlags, point);
}
void CDlgBN_NavieBayesianClassfier::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
pTable1->DoMouseMove(point);
//pTable2->DoMouseMove(point);
CDialog::OnMouseMove(nFlags, point);
}
void CDlgBN_NavieBayesianClassfier::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
pTable1->DoLButtonUp(point);
//pTable2->DoLButtonUp(point);
CDialog::OnLButtonUp(nFlags, point);
}
void CDlgBN_NavieBayesianClassfier::OnBUTTONStudy()
{
// TODO: Add your control notification handler code here
CButton *pBtn;
pBtn=(CButton*)GetDlgItem(IDC_BUTTON_Study);
pBtn->EnableWindow(FALSE);
/*
if (pNBC!=NULL){
delete pNBC;
}
*/
int i,j;
CString s,sTmp;
struct TypeClass C[M];
for(i=0; i<M; i++){
C[i].Class=i;
//s.Format("%d",i);
C[i].Word=new CString( (char)((int)'A'+i) );
}
struct TypeSample S[Q];
for(i=0; i<Q; i++)
{
S[i].Class=i;
S[i].sample=(int *) calloc(N, sizeof(int));
pTable1->SetSample(*C[i].Word,0,0,"宋体",RGB(0,0,0),RGB(0,255,255));
pTable1->FillSample(0,0);
pTable1->Get(S[i].sample);
}
pNBC=new CBN_NavieBayesianClassifier(
/*struct TypeClass *C, int M, int N,struct TypeSample *S, int Q*/
C,M,N,S,Q
);
pNBC->Study();
pNBC->ToFile("BN_NavieBayesianClassifier.htm");
SamNum=0;
pBtn=(CButton*)GetDlgItem(IDC_BUTTON_Ontroduce);
pBtn->EnableWindow(TRUE);
pBtn=(CButton*)GetDlgItem(IDC_BUTTON_Clear);
pBtn->EnableWindow(TRUE);
pBtn=(CButton*)GetDlgItem(IDC_BUTTON_Sample);
pBtn->EnableWindow(TRUE);
pBtn=(CButton*)GetDlgItem(IDC_BUTTON_Work);
pBtn->EnableWindow(TRUE);
}
void CDlgBN_NavieBayesianClassfier::OnBUTTONWork()
{
// TODO: Add your control notification handler code here
CButton *pBtn;
pBtn=(CButton*)GetDlgItem(IDC_BUTTON_Ontroduce);
pBtn->EnableWindow(FALSE);
pBtn=(CButton*)GetDlgItem(IDC_BUTTON_Clear);
pBtn->EnableWindow(FALSE);
pBtn=(CButton*)GetDlgItem(IDC_BUTTON_Sample);
pBtn->EnableWindow(FALSE);
pBtn=(CButton*)GetDlgItem(IDC_BUTTON_Work);
pBtn->EnableWindow(FALSE);
int pTest[PANES_Row*PANES_Col];
pTable1->Get(pTest);
CString csTestResult=pNBC->Work(pTest);
pTable2->SetSample(csTestResult[0],0,0,"宋体",RGB(0,0,0),RGB(0,255,255));
pTable2->FillSample(0,0);
csTestResult.Delete(0);
this->SetDlgItemText( IDC_EDIT1,csTestResult);
//::AfxMessageBox(csTestResult);
pBtn=(CButton*)GetDlgItem(IDC_BUTTON_Ontroduce);
pBtn->EnableWindow(TRUE);
pBtn=(CButton*)GetDlgItem(IDC_BUTTON_Clear);
pBtn->EnableWindow(TRUE);
pBtn=(CButton*)GetDlgItem(IDC_BUTTON_Sample);
pBtn->EnableWindow(TRUE);
pBtn=(CButton*)GetDlgItem(IDC_BUTTON_Work);
pBtn->EnableWindow(TRUE);
}
void CDlgBN_NavieBayesianClassfier::OnBUTTONOntroduce()
{
// TODO: Add your control notification handler code here
HWND h=::FindWindowEx(NULL,NULL,NULL,"Microsoft Internet Explorer");
::ShellExecute(h,"open","BN_NavieBayesianClassifier.htm",NULL,NULL,SW_SHOWNORMAL);
}
void CDlgBN_NavieBayesianClassfier::OnBUTTONClear()
{
// TODO: Add your control notification handler code here
pTable1->Clear();
pTable2->Clear();
}
void CDlgBN_NavieBayesianClassfier::OnBUTTONSample()
{
// TODO: Add your control notification handler code here
CString s;
s=pNBC->GetSample(SamNum);
pTable1->SetSample(s,0,0,"宋体",RGB(0,0,0),RGB(0,255,255));
pTable1->FillSample(0,0);
SamNum=(SamNum+1)%Q;
s.Format(">>样本%d",SamNum);
this->SetDlgItemText( IDC_BUTTON_Sample,s);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -