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

📄 modularnetdlg.cpp

📁 本源代码是本人亲自编写的关于模糊神经网络模型的实现
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// ModularNetDlg.cpp : implementation file
//

#include "stdafx.h"
#include "ModularNet.h"
#include "ModularNetDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	afx_msg void OnHelpmodular();
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
	ON_BN_CLICKED(IDC_HELPMODULAR, OnHelpmodular)
	ON_WM_LBUTTONDOWN()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CModularNetDlg dialog

CModularNetDlg::CModularNetDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CModularNetDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CModularNetDlg)
	m_trainradio = 0;
	m_trainnetStr = _T("");
	m_studyrate = 0.0f;
	m_rulenum = 0;
	m_saveU = _T("");
	m_saveZ = _T("");
	m_nITNUM = 0;
	m_saveSample = _T("");
	m_error = _T("");
	
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CModularNetDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CModularNetDlg)
	DDX_Control(pDX, IDC_SticSAMPLE, m_SticCtlSample);
	DDX_Control(pDX, IDC_SticSAVEZ, m_SticCtlSaveZ);
	DDX_Control(pDX, IDC_SticSAVEU, m_SticCtlSaveU);
	DDX_Control(pDX, IDC_EDITSAVEZ, m_ctlsavez);
	DDX_Control(pDX, IDC_EDITITNUM, m_ctlitnum);
	DDX_Control(pDX, IDC_EDITERROR, m_ctlerror);
	DDX_Control(pDX, IDC_EDITSTUDYRATE, m_ctlstudyrate);
	DDX_Control(pDX, IDC_EDITRULENUM, m_ctlrulenum);	
	DDX_Control(pDX, IDC_BTNSAVE, m_BtnCtlSave);
	DDX_Control(pDX, IDC_BTNTRAIN, m_BtnCtlLoad);
	DDX_Control(pDX, IDC_SticERROR, m_SticCtlError);
	DDX_Control(pDX, IDC_SticTRAIN_NET, m_SticCtlTrainNet);
	DDX_Radio(pDX, IDC_RADIOTRAIN, m_trainradio);
	DDX_Text(pDX, IDC_EDITTRAIN_NET, m_trainnetStr);
	DDX_Text(pDX, IDC_EDITSTUDYRATE,m_studyrate);
	DDX_Text(pDX, IDC_EDITRULENUM,m_rulenum);
	DDX_Text(pDX, IDC_EDITSAVEU, m_saveU);
	DDX_Text(pDX, IDC_EDITSAVEZ, m_saveZ);
	DDX_Text(pDX, IDC_EDITITNUM, m_nITNUM);
	DDX_Text(pDX, IDC_EDITSAVESAMPLE, m_saveSample);
	DDX_Text(pDX, IDC_EDITERROR, m_error);
	
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CModularNetDlg, CDialog)
	//{{AFX_MSG_MAP(CModularNetDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_RADIOTRAIN, OnRadiotrain)
	ON_BN_CLICKED(IDC_RADIOPREDICT, OnRadiopredict)
	ON_BN_CLICKED(IDC_BTNTRAIN_NET, OnBtntrainNet)
	ON_BN_CLICKED(IDC_BTNSAVEZ, OnBtnsavez)
	ON_BN_CLICKED(IDC_BTNTRAIN, OnBtntrain)
	ON_BN_CLICKED(IDC_BTNSAVE, OnBtnsave)
	ON_BN_CLICKED(IDC_BTNSAVEU, OnBtnsaveu)
	ON_BN_CLICKED(IDC_ABOUTUS, OnAboutus)
	ON_BN_CLICKED(IDC_BTNSAMPLE, OnBtnsample)
	
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CModularNetDlg message handlers

BOOL CModularNetDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// 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
	
	//////////////////////////////////////////////////////////
	//////*************************************
	CString itnum="300000";
	m_ctlitnum.SetWindowText(itnum);
	(CModularNetDlg *)GetDlgItem(IDC_EDITERROR)->EnableWindow(FALSE);
	(CModularNetDlg *)GetDlgItem(IDC_EDITITNUM)->EnableWindow(FALSE);
	/////////数组初始化	****************************
///	m_matrixUapt.SetMatrixRowAndCol(M_nSample,M_Rule_num);
//	m_matrixZvector.SetMatrixRowAndCol(M_Rule_num,M_xSample);
//	m_matrixBquan.SetMatrixRowAndCol(M_xSample+1,M_Rule_num);
	err=0.0;
	Qresult=0.0;
	//////**************************************
	//////////////////////////////////////////////////////////
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CModularNetDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// 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 CModularNetDlg::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 CModularNetDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}
//********确定是训练数据还是预测数据
void CModularNetDlg::OnRadiotrain() 
{
m_trainradio=0;	//训练
m_SticCtlError.SetWindowText("学习误差");
m_SticCtlTrainNet.SetWindowText("打开训练数据文件");
m_SticCtlSaveU.SetWindowText("保存专家网络权值结果");
m_SticCtlSaveZ.SetWindowText("保存中心向量结果");
m_SticCtlSample.SetWindowText("保存训练结果");
m_BtnCtlLoad.SetWindowText("训练学习");
ClearAll();
UpdateData(FALSE);
}

void CModularNetDlg::OnRadiopredict() 
{
m_trainradio=1;	//预测
m_SticCtlError.SetWindowText("仿真误差");
m_SticCtlTrainNet.SetWindowText("打开仿真数据文件");
m_SticCtlSaveU.SetWindowText("打开专家网络权值文件");
m_SticCtlSaveZ.SetWindowText("打开中心向量文件");
m_SticCtlSample.SetWindowText("保存样本仿真结果");
m_BtnCtlLoad.SetWindowText("结果仿真");
ClearAll();
UpdateData(FALSE);
}
//************************************

void CModularNetDlg::OnBtntrainNet() 
{
	SelOpenFile(IDC_EDITTRAIN_NET,m_trainnetStr);
}
void CModularNetDlg::OnBtnsavez() 
{
	UpdateData(TRUE);
	switch(m_trainradio)
	{
	case 0://
		{
			SelSaveFile(IDC_EDITSAVEZ,m_saveZ);
			break;
		}
	case 1:
		{
			SelOpenFile(IDC_EDITSAVEZ,m_saveZ);
			break;
		}
	default:{break;}
	}	
}
void CModularNetDlg::OnBtnsaveu() 
{
	UpdateData(TRUE);
	switch(m_trainradio)
	{
	case 0://
		{
			SelSaveFile(IDC_EDITSAVEU,m_saveU);break;
		}
	case 1:
		{
			SelOpenFile(IDC_EDITSAVEU,m_saveU);break;
		}
	default:{break;}
	}	
}
void CModularNetDlg::OnBtnsample() 
{
	SelSaveFile(IDC_EDITSAVESAMPLE,m_saveSample);
}
//*******************************************************************************88888
void CModularNetDlg::DFCM()
{
	FCM(m_nPattern,m_xPattern,m_rulenum,err,m_matrixZvector,m_matrixUapt,m_matrixPattern);
}

void CModularNetDlg::DEXPERT_NET()
{
	//m_matrixUapt.SaveDataToFile(m_saveU);
	EXPERT_NET(m_nPattern,m_xPattern,m_rulenum,err,Qresult,m_matrixBquan,m_matrixPattern,m_matrixUapt,m_Yp);
}

void CModularNetDlg::DGATING_NET()
{
	GATING_NET(m_nPattern,m_xPattern,m_rulenum,m_matrixUapt,m_matrixPattern,m_matrixZvector);
}

void CModularNetDlg::DPREDICT()
{
	PREDICT(m_nPattern,m_xPattern,m_rulenum,err,Qresult,m_matrixPattern,m_matrixBquan,m_matrixUapt,m_Yp);
	
}
//***********************************************************************************
//样本训练//
void CModularNetDlg::OnBtntrain() 
{
	UpdateData(TRUE);
	switch(m_trainradio)
	{
	case 0://样本训练
		{
			if(m_rulenum<=0||m_rulenum>6)
			{
				::MessageBox (this->m_hWnd, _T("请输入规则数!(不超过6条)"), _T(":("), MB_OK);				

⌨️ 快捷键说明

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