?? bptoxorsview.cpp
字號(hào):
// BPtoXorSView.cpp : implementation of the CBPtoXorSView class
//
#include "stdafx.h"
#include "BPtoXorS.h"
#include "BPtoXorSDoc.h"
#include "BPtoXorSView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBPtoXorSView
IMPLEMENT_DYNCREATE(CBPtoXorSView, CView)
BEGIN_MESSAGE_MAP(CBPtoXorSView, CView)
//{{AFX_MSG_MAP(CBPtoXorSView)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBPtoXorSView construction/destruction
CBPtoXorSView::CBPtoXorSView()
{
// TODO: add construction code here
for(int j=0; i<300; i++)
{
point[j].x = 0;
point[j].y = 0;
}
i = 0; //在不刷新的情況下i=1 否則會(huì)出現(xiàn)point[-1]的情況,奇怪也不報(bào)錯(cuò)
origin_y = 0;
k = 0;
}
CBPtoXorSView::~CBPtoXorSView()
{
}
BOOL CBPtoXorSView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CBPtoXorSView drawing
void CBPtoXorSView::OnDraw(CDC* pDC)
{
CBPtoXorSDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
//加載圖像
CDC memDC; //內(nèi)存設(shè)備場(chǎng)景
CBitmap cb; //位圖類對(duì)象
CRect rect; //
GetWindowRect(&rect);
cb.LoadBitmap(IDB_BITMAP1); //載入資源
memDC.CreateCompatibleDC(pDC); //創(chuàng)建內(nèi)存設(shè)備上下文
CBitmap *oldbitmap = NULL;
oldbitmap = memDC.SelectObject(&cb); //將位圖選入當(dāng)前設(shè)備場(chǎng)景
pDC->BitBlt(350,0,rect.Width(),rect.Height(),&memDC,0,0,SRCCOPY); //將內(nèi)存場(chǎng)景的圖像拷貝到屏幕上
memDC.SelectObject(oldbitmap);
BPnet net;
net.train();
pDC->TextOut(0,0,"動(dòng)態(tài)顯示個(gè)BP網(wǎng)中的參數(shù):");
CString s;
s.Format("%f",net.a);
pDC->TextOut(0,50,"學(xué)習(xí)系數(shù) a = "+s);
s.Format("%f",net.b);
pDC->TextOut(200,50," b = "+s);
//輸入值
s.Format("%f",net.input[0]);
pDC->TextOut(0,70,"輸入值 x0 = "+s);
s.Format("%f",net.input[1]);
pDC->TextOut(200,70,"x1 = "+s);
//輸入層到中間層的權(quán)值
pDC->TextOut(0,90,"輸入層到中間層的權(quán)值:");
s.Format("%f",net.w_middle[0]);
pDC->TextOut(0,50 + 20 * 3,"w01 = "+s);
s.Format("%f",net.w_middle[1]);
pDC->TextOut(200,50 + 20 * 3,"w02 = "+s);
s.Format("%f",net.w_middle[2]);
pDC->TextOut(0, 50 + 20 * 4,"w10 = "+s);
s.Format("%f",net.w_middle[3]);
pDC->TextOut(200, 50 + 20 * 4,"w11 = "+s);
//中間層到輸出層的權(quán)值
pDC->TextOut(0,50 + 20 * 6,"中間層到輸出層的權(quán)值:");
s.Format("%f",net.w_output[0]);
pDC->TextOut(0,50 + 20 * 7,"t0 = "+s);
s.Format("%f",net.w_output[1]);
pDC->TextOut(200,50 + 20 * 7,"t1 = "+s);
//中間層的閾值
pDC->TextOut(0,50 + 20 * 9,"中間層的閾值:");
s.Format("%f",net.threshold_m[0]);
pDC->TextOut(0,50 + 20 * 10,"h0 = "+s);
s.Format("%f",net.threshold_m[1]);
pDC->TextOut(200,50 + 20 * 10,"h1 = "+s);
//輸出層的閾值
pDC->TextOut(0,50 + 20 * 12,"輸出層的閾值:");
s.Format("%f",net.threshold_o);
pDC->TextOut(0,50 + 20 * 13,"u0 = "+s);
//誤差
pDC->TextOut(0,50 + 20 * 15,"輸出誤差:");
s.Format("%f",net.error);
pDC->TextOut(0,50 + 20 * 16,"error = "+s);
//輸出
pDC->TextOut(0,50 + 20 * 18,"輸出:");
s.Format("%f",net.output_o);
pDC->TextOut(0,50 + 20 * 19,"output_o = "+s);
//
pDC->TextOut(0,50 + 20 * 21,"****************************************");
CClientDC dc(this);
CPen mpen;
mpen.CreatePen(PS_SOLID,1,RGB(255,0,0));
dc.SelectObject(&mpen);
//y坐標(biāo)
dc.MoveTo(350,300);
dc.LineTo(350,450);
//箭頭
dc.MoveTo(350,300);
dc.LineTo(340,310);
dc.MoveTo(350,300);
dc.LineTo(360,310);
//x坐標(biāo)
dc.MoveTo(350,420);
dc.LineTo(700,420);
//箭頭
dc.MoveTo(700,420);
dc.LineTo(690,410);
dc.MoveTo(700,420);
dc.LineTo(690,430);
//輸出零點(diǎn)值
pDC->TextOut(330,420,"0");
//輸出一點(diǎn)值
pDC->TextOut(330,370,"1");
//在1值處輸出一條線
dc.MoveTo(350,370);
dc.LineTo(700,370);
origin_y = ((420.0 - (net.output_o * 50)));
if(origin_y < 220) //輸出范圍限定,在220 ——520之間
origin_y = 220;
if(origin_y > 520)
origin_y = 520;
if(i<=300) //算法 very good!!
{
point[i].x = (350 + i);
point[i].y = (long)origin_y;
for(k=0; k<(i-1); k++)
{
dc.MoveTo(point[k]);
dc.LineTo(point[k+1]);
}
i++; //重復(fù)時(shí)使其在坐標(biāo)原點(diǎn)輸出
}
else
{
i = 0;
for(k=0; k<300;k++)
{
point[k].x = 0;
point[k].y = 0;
}
}
//停0.25秒
Sleep(250);
if(net.error>0.1)
dc.LineTo(point[i-1]);
CWnd::Invalidate(TRUE);
DeleteObject(mpen); //刪除所選畫筆,好像沒(méi)用??
/*//用不刷新試一下 。————坐標(biāo)擦除不了
point[0].x = 350;
point[0].y = 420;
if(i<=300)
{
point[i].x = (350 + i);
point[i].y = origin_y;
dc.MoveTo(point[i-1]);
dc.LineTo(point[i]);
i++; //重復(fù)時(shí)使其在坐標(biāo)原點(diǎn)輸出
}
else
{
i = 1;
for(k=0; k<300;k++)
{
point[k].x = 0;
point[k].y = 0;
}
}
DeleteObject(mpen);
//停0.15秒
Sleep(150);
if(net.error>0.01)
CWnd::Invalidate(FALSE);*/
}
/////////////////////////////////////////////////////////////////////////////
// CBPtoXorSView diagnostics
#ifdef _DEBUG
void CBPtoXorSView::AssertValid() const
{
CView::AssertValid();
}
void CBPtoXorSView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CBPtoXorSDoc* CBPtoXorSView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CBPtoXorSDoc)));
return (CBPtoXorSDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CBPtoXorSView message handlers
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -