?? 畢業設計dlg.cpp
字號:
// 畢業設計Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "畢業設計.h"
#include "畢業設計Dlg.h"
#include "DlgProxy.h"
#include <math.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
static double lastTime=COleDateTime::GetCurrentTime()*100000;
#define N 20//結點數目。
#define INP 2
#define OUP 2
#define T 100//時間幀長度。
double WWWW[N][N];//權矩陣
double WWWCL[N][N];//公共狀態樣本容器
double WWWCR[N][N];//公共狀態樣本容器
double bWWWW[N][N];//b權矩陣
double bWWWCL[N][N];//b公共狀態樣本容器
double bWWWCR[N][N];//b公共狀態樣本容器
double WWWP[N][1];//混合后的當前狀態矩陣
double WWWJ[N][1];//自我激發的狀態矩陣
double WWWB[N][1];//過去狀態矩陣
double WWWF[N][1];//未來狀態矩陣
CTime df;
double vinp[INP];//對內影響的值
int inps[INP];//對內影響的節點有哪些
double voup[OUP];//對外影響的值
int oups[OUP];//對外影響的節點有哪些
inline void swap(double &a,double &b){double c=a;a=b;b=c;};//交換大小
bool myTime(double t,double * lastTime1)//t為毫秒//全局計時器
{
if(COleDateTime::GetCurrentTime()*100000-*lastTime1>=t)
{
*lastTime1=COleDateTime::GetCurrentTime()*100000;
return true;
//CMyDlg::MessageBox("fdf",NULL,MB_OK) ;
}
return false;
}
//方形矩陣相乘。
void mulMatrix(double a[N][N],double b[N][N],double c[N][N])
{
int i,j,k=0,m=0,l=0;
for(i=0;i<N;i++)
{// vinp[0]=0.99f; 2 3 4 6
for(j=0;j<N;j++)
{
for(k=0;k<N;k++)
{
c[j][i]= c[j][i]+a[k][i]*b[j][k];
}
}
}
}
//線矩陣乘方式可逆矩陣。
void mulMatrix2(double a[N][1],double b[N][N],double c[N][1])
{
int j,k=0,m=0,l=0;
for(j=0;j<N;j++)
{
for(k=0;k<N;k++)
{
c[j][0]= c[j][0]+a[k][0]*b[j][k];
}
}
}
//矩陣求逆
bool DinV(double A[N][N])
{
int i,j,k;
double d;
int n=N;
int JS[N],IS[N];
for (k=0;k<n;k++)
{
d=0;
for (i=k;i<n;i++)
for (j=k;j<n;j++)
{
if (fabs(A[i][j])>d)
{
d=fabs(A[i][j]);
IS[k]=i;
JS[k]=j;
}
}
//-------------------------
if (d+1.0==1.0) return false;
//-----------------
if (IS[k]!=k)
for (j=0;j<n;j++)
swap(A[k][j],A[IS[k]][j]);
//-------------------------
if (JS[k]!=k)
for (i=0;i<n;i++)
swap(A[i][k],A[i][JS[k]]);
//---------------------------
A[k][k]=1/A[k][k];
for (j=0;j<n;j++)
if (j!=k) A[k][j]=A[k][j]*A[k][k];
//--------------------------
for (i=0;i<n;i++)
if (i!=k)
for (j=0;j<n;j++)
if (j!=k) A[i][j]=A[i][j]-A[i][k]*A[k][j];
//-------------
for (i=0;i<n;i++)
if (i!=k) A[i][k]=-A[i][k]*A[k][k];
}
//-------------
for (k=n-1;k>=0;k--)
{
for (j=0;j<n;j++)
if (JS[k]!=k) swap(A[k][j],A[JS[k]][j]);
for (i=0;i<n;i++)
if (IS[k]!=k) swap(A[i][k],A[i][IS[k]]);
}
return true;
}
/////////////////////////////////////////////////////////////////////////////
// CMyDlg dialog
IMPLEMENT_DYNAMIC(CMyDlg, CDialog);
CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMyDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMyDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_pAutoProxy = NULL;
}
CMyDlg::~CMyDlg()
{
// If there is an automation proxy for this dialog, set
// its back pointer to this dialog to NULL, so it knows
// the dialog has been deleted.
if (m_pAutoProxy != NULL)
m_pAutoProxy->m_pDialog = NULL;
}
void CMyDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
//{{AFX_MSG_MAP(CMyDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_CLOSE()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyDlg message handlers
BOOL CMyDlg::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
//初始化隨機種子。
lastTime=lastTime-COleDateTime::GetCurrentTime();
srand((int)lastTime);
double pp;
// srand((UINT)GetCurrentTime());
pp=rand()/(RAND_MAX+0.00);
//------初始化各存儲節點。
CMyDlg::clearAll();
//隨機初始化狀態容器左,保證容器左可力,并利用左容器矩陣與權矩陣計算出容器右。//隨機初始化自激發值
CMyDlg::initaiWWWC();
//進入幀。
SetTimer(0,T,NULL);
return TRUE; // return TRUE unless you set the focus to a control
}
///-----------------multMatrix
///-----------------------------------
void CMyDlg::clearAll()
{
int i,j;
for(i=0;i<N;i++)
{
WWWJ[i][0]=0.0f;
WWWP[i][0]=0.0f;
WWWB[i][0]=0.0f;
WWWF[i][0]=0.0f;
for(j=0;j<N;j++)
{
WWWW[i][j]=0.0f;
WWWCL[i][j]=0.0f;
WWWCR[i][j]=0.0f;
}
}
for(i=0;i<INP;i++)
{
//inps[i]=0;
vinp[i]=0.0f;
}
for(i=0;i<OUP;i++)
{
//oups[i]=0;
voup[i]=0.0f;
}
//inps[INP]={0,1};//輸入綁定的結點端口
inps[0]=0;
inps[1]=1;
//oups[OUP]={8,9};//輸出綁定的結點端口
//oups[0]=8;
//oups[1]=9;
}
void CMyDlg::clearframe()
{
int i,j=0;
for(i=0;i<N;i++)
{
// WWWJ[i][0]=0.0f;
WWWP[i][0]=0.0f;
WWWB[i][0]=0.0f;
}
for(i=0;i<INP;i++)
{
//inps[i]=0;
vinp[i]=0.0f;
}
for(i=0;i<OUP;i++)
{
//oups[i]=0;
voup[i]=0.0f;
}
}
void CMyDlg::clearmid()
{
int i,j;
for(i=0;i<N;i++)
{
WWWJ[i][0]=0.0f;
WWWP[i][0]=0.0f;
WWWB[i][0]=0.0f;
// WWWF[i][0]=0.0f;
for(j=0;j<N;j++)
{
// WWWW[i][j]=0.0f;
// WWWCL[i][j]=0.0f;
// WWWCR[i][j]=0.0f;
}
}
for(i=0;i<INP;i++)
{
//inps[i]=0;
vinp[i]=0.0f;
}
for(i=0;i<OUP;i++)
{
//oups[i]=0;
voup[i]=0.0f;
}
//inps[INP]={0,1};//輸入綁定的結點端口
//inps[0]=0;
//inps[1]=1;
//oups[OUP]={8,9};//輸出綁定的結點端口
//oups[0]=8;
//oups[1]=9;
}
//----------------初始化權矩陣,左右容器樣本,還有激發值。
void CMyDlg::initaiWWWC()
{
// srand(time(NULL));
int i,j;
line3:
for(i=0;i<N;i++)
{
for(j=0;j<N;j++)
{
WWWCL[j][i]=rand()/(RAND_MAX+0.00);
WWWCR[j][i]=rand()/(RAND_MAX+0.00);
}
}
//
if(DinV(WWWCL)!=true)//左是否是可逆矩陣,是直接返回到WWWCL
{goto line3;}
else
{
//--求出WWWCL逆矩陣后
// CMyDlg::MessageBox("FD",NULL,MB_OK);
mulMatrix(WWWCR,WWWCL,WWWW);
}
if(DinV(WWWW)!=true){goto line3;}
/*
//隨機選出一個右樣本作為激發值。
int pint;
line10:
CString sf;
pint=(int)(rand()*0.0003f*(double)(N/10.0f));
sf.Format("%d",pint);
CMyDlg::MessageBox(sf,NULL,MB_OK);
if(pint>=0&&pint<N){;}else{goto line10;}
*/
for(i=0;i<N;i++)
{
WWWJ[i][0]=rand()/(RAND_MAX+0.00);
}
DinV(WWWCL);//back
DinV(WWWW);//back
}
//---------------------進入幀運算
void CMyDlg::OnTimer(UINT nIDEvent)
{
int open=0;
CString stro;
stro.Format ("%s","On Thinking");
CMyDlg::SetDlgItemText(IDC_STATIC,stro);
//--------------------------------------------------------------------
//判斷如果存在輸入值,就把該影響值與自激發狀態值混合(以輸入值覆蓋自激發值)
int i,j,k=0,m=0;//不存在直接當前矩陣
//先把激發值傳入混合模版。
for(j=0;j<N;j++)
{
WWWP[j][0]=WWWJ[j][0];
}
//把影響值也加到混合模版。
for(i=0;i<INP;i++)
{
if(vinp[i]!=0.0f)
{
WWWP[inps[i]][0]=(double)vinp[i];
open=1;
//WWWJ[inps[INP]]=vinp[INP];
}
}
//goto line7;
if(open!=1)
{goto line7;}
else
{
//利用激發值矩陣和公共矩陣求出過去狀態矩陣值。(函數)
DinV(WWWW);//對矩陣求逆。
mulMatrix2(WWWJ,WWWW,WWWB);
DinV(WWWW);//反回
}
//goto line7;
//將過去狀態矩陣與當前狀態矩陣加入到,狀態容器中,加入的原則是,一樣的不加,不一樣的加,
//并且是隨機覆蓋原則。
int count;
for(j=0;j<N;j++)
{
count=0;
for(i=0;i<N;i++)
{
//看是否有一樣的記錄,一旦一個樣本記錄的數量,就認定為有一樣的,就退出,更新矩陣,真接用舊矩陣輸出新的WWWF。
if(WWWB[i][0]==WWWCL[i][j]&&WWWP[i][0]==WWWCR[i][j])
{count++;if(count==N-1){ goto line7;}}
}
}
//背份WWWCL和WWWCR以及 WWWW
for(i=0;i<N;i++)
{
for(j=0;j<N;j++)
{
bWWWW[j][i]=WWWW[j][i];
bWWWCL[j][i]=WWWCL[j][i];
bWWWCR[j][i]=WWWCR[j][i];
}
}
//隨機產生一個切入點。
int pint;
line10:
pint=(int)(rand()*0.0003f*(double)(N/10.0f));
if(pint>=0&&pint<N){;}else{goto line10;}
//利用隨機切入點保證,覆蓋左右容器。
for(i=0;i<N;i++)
{
WWWCL[i][pint]=WWWB[i][0];
WWWCR[i][pint]=WWWP[i][0];
}
//DinV(WWWCL,WWWCL);
//mulMatrix(WWWCR,WWWCL,WWWW);
//goto line7;
//然后得到的新的狀態容器,利用該容器,求這個新的權矩陣.(函數)
//判斷WWWCL是否是可逆矩陣,可逆的話,就利用容器求出該權矩陣。
//不可逆就把,重新生成一個切入點。
if(DinV(WWWCL)==false)
{ //用背份還原。
for(i=0;i<N;i++)
{
for(j=0;j<N;j++)
{
//WWWW[j][i]=bWWWW[j][i];
WWWCL[j][i]=bWWWCL[j][i];
WWWCR[j][i]=bWWWCR[j][i];
}
}
goto line7;
}
else
{
for(i=0;i<N;i++)
{
for(j=0;j<N;j++)
{
WWWW[j][i]=0;
}
}
mulMatrix(WWWCR,WWWCL,WWWW);
}
if(DinV(WWWW)==false)//判斷WWWW是否是一個可逆矩陣
{
for(i=0;i<N;i++)
{
for(j=0;j<N;j++)
{
WWWW[j][i]=bWWWW[j][i];
WWWCL[j][i]=bWWWCL[j][i];
WWWCR[j][i]=bWWWCR[j][i];
}
}
goto line7;
}
else
{
DinV(WWWW);//是可逆就回求,利用該矩陣來求,新的激發值。
}
//利用新的權矩陣,求當前矩陣的一下狀態,并釋放空間。
line7:
//CMyDlg::clearmid();
for(j=0;j<N;j++)
{
WWWJ[j][0]=0;
}
mulMatrix2(WWWP,WWWW,WWWJ);
//歸元化一輸出。
for(j=0;j<N;j++)
{
WWWJ[j][0]=1.0f/(exp(WWWJ[j][0])+1.0f);
}
//整個過程在時間幀中運行。
CString str;
CString strs;
CString str1;
CString strs1;
for( i=0;i<N;i++)
{
for( j=0;j<N;j++)
{
str.Format("%f",WWWCL[j][i]);
strs=strs + " ("+ str +") ";
}
}
CMyDlg::SetDlgItemText(IDC_EDIT1,strs);
//----------------------------
for( j=0;j<N;j++)
{
str1.Format("%f",WWWJ[j][0]);
strs1=strs1 + " "+ str1;
}
CMyDlg::SetDlgItemText(IDC_EDIT2,strs1);
//CMyDlg::clearframe();
//if(myTime(10,&lastTime)==true)
//{
// CMyDlg::MessageBox("fd",NULL,MB_OK);
//}
//----------------------------------------------------------------
CString stro2;
stro2.Format ("%s","Waiting to think!\n");
CMyDlg::SetDlgItemText(IDC_STATIC,stro2);
//-----------------------
CMyDlg::clearframe();
}
// 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 CMyDlg::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 CMyDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
// Automation servers should not exit when a user closes the UI
// if a controller still holds on to one of its objects. These
// message handlers make sure that if the proxy is still in use,
// then the UI is hidden but the dialog remains around if it
// is dismissed.
void CMyDlg::OnClose()
{
if (CanExit())
CDialog::OnClose();
}
void CMyDlg::OnOK()
{
if (CanExit())
CDialog::OnOK();
}
void CMyDlg::OnCancel()
{
if (CanExit())
CDialog::OnCancel();
}
BOOL CMyDlg::CanExit()
{
// If the proxy object is still around, then the automation
// controller is still holding on to this application. Leave
// the dialog around, but hide its UI.
if (m_pAutoProxy != NULL)
{
ShowWindow(SW_HIDE);
return FALSE;
}
return TRUE;
}
void CMyDlg::OnButton1()
{
vinp[0]=0.99f;
vinp[1]=0.001f;
/*
WWWCL[0][0]=2;
WWWCL[1][0]=3;
WWWCL[0][1]=3;
WWWCL[1][1]=5;
WWWW[0][0]=2;
WWWW[1][0]=-1;
WWWW[0][1]=-1;
WWWW[1][1]=1;
DinV(WWWW);
DinV(WWWW);
CString str;
CString strs;
CString str1;
CString strs1;
int i,j;
for(i=0;i<N;i++)
{
for( j=0;j<N;j++)
{
str.Format("%f",WWWW[j][i]);
strs=strs + " "+ str;
}
}
CMyDlg::SetDlgItemText(IDC_EDIT1,strs);
*/
/*
for( j=0;j<N;j++)
{
str1.Format("%f",WWWL[j][0]);
strs1=strs1 + " "+ str1;
}
CMyDlg::SetDlgItemText(IDC_EDIT2,strs1);
*/
// CMyDlg::KillTimer(0);
// lastTime=COleDateTime::GetCurrentTime()*100000;
// CString strp;
//char msd;
//char *ms;
//CMyDlg::GetDlgItemText(IDC_EDIT2,ms,1);
//strcpy(&msd,ms);
//strp.Format("%s",msd);
//CMyDlg::SetDlgItemText(IDC_EDIT1, msd);
/*
CString str1;
str1.Format("%f",(double)rand()*0.00003f);
CMyDlg::SetDlgItemText(IDC_EDIT1,str1);)*/
//myTime(10,&lastTime);
// str.Format("%f",lastTime);
// CMyDlg::SetDlgItemText(IDC_EDIT1,str);
}
void CMyDlg::OnButton2()
{
vinp[0]=0.001f;
vinp[1]=0.999f;
// TODO: Add your control notification handler code here
}
void CMyDlg::OnButton3()
{
vinp[0]=0.55f;
vinp[1]=0.55f;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -