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

📄 unit1.~cpp

📁 人工神经网络BP算法 1、动态改变学习速率 2、加入动量项 3、运用了Matcom4.5的矩阵运算库(可免费下载,头文件matlib.h)
💻 ~CPP
字号:
//---------------------------------------------------------------------------

#include <vcl.h>

#pragma hdrstop

#include "Unit1.h"
#include "som/som.class.cpp"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------


void __fastcall TForm1::Button1Click(TObject *Sender)
{
//  Image1->Pictur
  int i,j;
  float r,g,b,c;

  
  srand(time(NULL));
  int NumSets = RandInt(1000, 1000);
  vector <vector <double> > TrainingSet;
  for (int s=0; s<NumSets; ++s)
  {
    vector<double> set;
    r = RandFloat();
    if (r < 0.5)
    {
    set.push_back(RandFloat());
    set.push_back(0);
    set.push_back(0);
    }
    else
    {
    set.push_back(0);
    set.push_back(RandFloat());
    set.push_back(RandFloat()+0.1);
    }

    TrainingSet.push_back(set);
  }

   Label1->Caption = "Apmokymas ... ";
   Label1->Refresh();
   SOM net(40,40,3,200);

   int width = (int) (Image1->Width / net.s_cols);
   int height =  (int)(Image1->Height / net.s_rows);

   while (!net.complete())
    {
        ProgressBar1->Position = 100 * (float)net.Iteration / 200;
        ProgressBar1->Refresh();

      //  Sleep(2000);
        net.Epoch(TrainingSet);
        Image1->Canvas->MoveTo(0,0);


         for (int j = 0; j < net.s_rows; j++)
            for (int i = 0; i < net.s_cols; i++)
              {
                   r = (int) 255* net.Latice[j][i].l_weights[0];
                   g = (int) 255* net.Latice[j][i].l_weights[1];
                   b = (int) 255* net.Latice[j][i].l_weights[2];

                   if (r > 255) r = 255;
                   if (g > 255) r = 255;
                   if (b > 255) b = 255;

                   c = (int)255*net.getErrorValue(j,i);

                    Image1->Canvas->Brush->Color = RGB(r,g,b);
                    Image1->Canvas->FillRect(Rect(i*width,j*height,(i+1)*width,(j+1)*height));

                   Image2->Canvas->Brush->Color = RGB(c,c,c);
                    Image2->Canvas->FillRect(Rect(i*width,j*height,(i+1)*width,(j+1)*height));

             //    if (CheckBox1->Checked)
            //      Image1->Canvas->Rectangle(i*width,j*height,(i+1)*width,(j+1)*height);
              }
        Image1->Repaint();
     

   }

  Label1->Caption = "Apmokymas baigtas ";
  Label1->Refresh();


}
//---------------------------------------------------------------------------
void __fastcall TForm1::Label2Click(TObject *Sender)
{
ShellExecute(0,"open","http://ai.hacker.lt",NULL,NULL,0);
}
//---------------------------------------------------------------------------





void __fastcall TForm1::FormCreate(TObject *Sender)
{
 Image2->Width = Image1->Width;
 Image2->Height = Image1->Height;        
}
//---------------------------------------------------------------------------


//---------------------------------------------------------------------------


⌨️ 快捷键说明

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