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

📄 unit1.cpp

📁 人工神经网络在模式识别
💻 CPP
字号:
/**
 *Title: AIR_BPNN_Recall-C++ *Description: Neural Network Recaller *Copyright: Copyleft (c) 2002 (See gpl.txt for details) *Company: www.air-robot.net *Author M. T. Li (mtli0913@yahoo.com) *Version 1.0 ; 2000.10.24 ; M. T. Li ; Rewriting from AIR_BPNN_Recall-C *Version 1.1 ; 2000.11.24 ; M. T. Li ; debug
 *Version 1.2 ; 2000.11.25 ; M. T. Li ; Parameter output
 *Version 1.3 ; 2000.11.25 ; M. T. Li ; Optimization
 *Version 1.4 ; 2001.04.06 ; M. T. Li ; Input array
 *Version 2.0 ; 2001.04.07 ; M. T. Li ; Show the sample
 *Version 2.1 ; 2001.04.08 ; M. T. Li ; Sample editor
 *Version 2.2 ; 2002.07.28 ; M. T. Li ; Distribute by GPL *Version 2.3 ; 2002.11.24 ; M. T. Li ; English version */


#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
#include "BPNN.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

DWORD CALLBACK ThreadFunc1(void* P)
{
    int i,j;
    AnsiString asTemp;
    double dTemp;

    //Step 1.BPNN Object
    AIR_BPNN BPNNO1;



    Form1->OpenDialog1->Title="Open Neural Network Data From File";
    Form1->OpenDialog1->FileName="NeuralNetwork.txt";
    Form1->OpenDialog2->Title="Open Recall Sample From File";
    Form1->SaveDialog1->Title="Save Recall Result To File";
    Form1->SaveDialog1->FileName="Recall.txt";
    if(Form1->OpenDialog1->Execute()&&Form1->OpenDialog2->Execute()&&Form1->SaveDialog1->Execute())
    {
        asTemp="*Open Neural Network Data From File:";
        Form1->Memo1->Lines->Add(asTemp);
        asTemp=Form1->OpenDialog1->FileName;
        Form1->Memo1->Lines->Add(asTemp);

        //Step 2. Load neural network from file
        BPNNO1.LoadNeuralNetwork(asTemp);

        asTemp="*Open Recall Sample From File:";
        Form1->Memo1->Lines->Add(asTemp);
        asTemp=Form1->OpenDialog2->FileName;
        Form1->Memo1->Lines->Add(asTemp);
        ifstream fin;    //File input stream
        fin.open(asTemp.c_str());

        asTemp="*Save Recall Result To File:";
        Form1->Memo1->Lines->Add(asTemp);
        asTemp=Form1->SaveDialog1->FileName;
        Form1->Memo1->Lines->Add(asTemp);
        ofstream fout;    //File output stream
        fout.open(asTemp.c_str());

        //Start to recall
        int iTrainSampleSetNum=Form1->Edit1->Text.ToInt();
        for(i=0;i<iTrainSampleSetNum;i++)
        {
            //Input the recall sample
            for(j=0;j<BPNNO1.OutputInputLayerNNNum();j++)
            {
                fin>>dTemp;
                BPNNO1.InputRecallInputSample(j,dTemp);
            }

            //Step 3. Recall
            BPNNO1.Recall();

            //Show the recall result
            for(j=0;j<BPNNO1.OutputOutputLayerNNNum();j++)
            {
                fin>>dTemp;
                fout<<dTemp;
                fout<<"\t";
                fout<<BPNNO1.OutputRecallResult(j);
            }
            fout<<"\n";

    }


    fin.close();
     
    
    fout.close();


    }

    Form1->Button1->Enabled=true;

    return 1;
}

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    Button1->Enabled=false;
    DWORD ThreadID;
    HANDLE hthread = CreateThread(
    0,           //Security attribute
    0,           //Initial Stack
    ThreadFunc1,  //Starting address of thread
    0,           // argument of thread
    0,           // Create flags
    &ThreadID);  // thread ID
    if (!hthread)
    MessageBox(Handle, "No Thread", 0, MB_OK);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)
{
   Memo1->Clear();        
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
    ShellExecute(Handle,"open","www.air-robot.net",NULL,NULL,SW_SHOWDEFAULT);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button3Click(TObject *Sender)
{
     ShellExecute(Handle,"open","mailto:mtli0913@yahoo.com",NULL,NULL,SW_SHOWDEFAULT);        
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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