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

📄 dlgneuron.cpp

📁 使用神经网络开发包实现图形化的神经网络模拟
💻 CPP
字号:
// DlgNeuron.cpp : implementation file
//

#include "stdafx.h"
#include "NeuralNetwork.h"
#include "DlgNeuron.h"
#include "MainFrm.h"
#include "NeuralNetworkView.h"
#include "DlgFunction.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDlgNeuron dialog


CDlgNeuron::CDlgNeuron(CWnd* pParent /*=NULL*/)//: neuralFunction= {gaussian,dgaussian,sigmoid,dsigmoid,identity,didentity,signum};
: CDialog(CDlgNeuron::IDD, pParent) 
{	

	//neuralFunction = {gaussian,dgaussian,sigmoid,dsigmoid,identity,didentity,signum};
	//{{AFX_DATA_INIT(CDlgNeuron)
	m_nFunction = -1;
	m_nBias = 0.0f;
	//}}AFX_DATA_INIT
	neuralFunction[0]=gaussian;
	neuralFunction[1]=dgaussian;
	neuralFunction[2]=sigmoid;
	neuralFunction[3]=dsigmoid;
	neuralFunction[4]=identity;
	neuralFunction[5]=didentity;
	neuralFunction[6]=signum;
}
//const CDlgNeuron::neuralFunction[7]={gaussian,dgaussian,sigmoid,dsigmoid,identity,didentity,signum};

void CDlgNeuron::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgNeuron)
	DDX_Radio(pDX, IDC_FUNCTION, m_nFunction);
	DDX_Text(pDX, IDC_EDIT_BIAS, m_nBias);
	DDV_MinMaxFloat(pDX, m_nBias, -1.f, 1.f);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgNeuron, CDialog)
	//{{AFX_MSG_MAP(CDlgNeuron)
	ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
	ON_BN_CLICKED(IDC_RADIO3, OnRadio3)
	ON_BN_CLICKED(IDC_RADIO4, OnRadio4)
	ON_BN_CLICKED(IDC_RADIO5, OnRadio5)
	ON_BN_CLICKED(IDC_RADIO6, OnRadio6)
	ON_BN_CLICKED(IDC_RADIO7, OnRadio7)
	ON_EN_CHANGE(IDC_EDIT_BIAS, OnChangeEditBias)
	ON_BN_CLICKED(IDCANCEL, OnDelete)
	ON_BN_CLICKED(ID_FUNCTION_DETAIL, OnFunctionDetail)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgNeuron message handlers


BOOL CDlgNeuron::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDlgNeuron::OnOK() 
{
	// TODO: Add extra validation here
	CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd();
	CNeuralNetworkDoc* pDoc = (CNeuralNetworkDoc*) pMainFrame->GetActiveDocument();
	//=========设置当前神经元偏置值=========
	pDoc->neuralNetwork.setCurrentBias(m_nBias);
	//=========设置传输函数=================
	pDoc->neuralNetwork.setCurrectFunction(neuralFunction[m_nFunction]);
	CDialog::OnOK();
}

void CDlgNeuron::OnRadio2() 
{
	// TODO: Add your control notification handler code here
	m_nFunction=1;
}

void CDlgNeuron::OnRadio3() 
{
	// TODO: Add your control notification handler code here
	m_nFunction=2;
}

void CDlgNeuron::OnRadio4() 
{
	// TODO: Add your control notification handler code here
	m_nFunction=3;
}

void CDlgNeuron::OnRadio5() 
{
	// TODO: Add your control notification handler code here
	m_nFunction=4;
}

void CDlgNeuron::OnRadio6() 
{
	// TODO: Add your control notification handler code here
	m_nFunction=5;
}

void CDlgNeuron::OnRadio7() 
{
	// TODO: Add your control notification handler code here
	m_nFunction=6;
}

void CDlgNeuron::OnChangeEditBias() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	CString strText;
	GetDlgItemText(IDC_EDIT_BIAS, strText);
	//CString转换为float
	m_nBias=atof(strText);
}

void CDlgNeuron::setCDC(CDC *newpDC)
{
	pDC=newpDC;
}

void CDlgNeuron::setRect(CRect newRect)
{
	rect=newRect;
}

void CDlgNeuron::setFunction(int funIndex)
{
	m_nFunction=funIndex;
}

void CDlgNeuron::OnDelete() 
{
	// TODO: Add your control notification handler code here
	CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd();
	CNeuralNetworkDoc* pDoc = (CNeuralNetworkDoc*) pMainFrame->GetActiveDocument();
	//=========删除当前神经元=========
	pDoc->neuralNetwork.deleteNeuron(pDC,rect);
	CDialog::OnCancel();
}

void CDlgNeuron::OnFunctionDetail() 
{
	// TODO: Add your control notification handler code here
	CDlgFunction dlgFunction;
	dlgFunction.DoModal();
}

⌨️ 快捷键说明

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