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

📄 unit2.pas

📁 用来实现matlab的BP算法
💻 PAS
字号:
unit Unit2;

interface

uses
 // Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 // Dialogs, StdCtrls, ComCtrls;

  Windows, Messages, SysUtils,Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,Variants,activex,ComObj, Grids, ComCtrls;
type
  TForm2 = class(TForm)
    mmo1: TMemo;
    lbl1: TLabel;
    lbl2: TLabel;
    btn1: TButton;
    redt1: TRichEdit;
    redt2: TRichEdit;
    lbl3: TLabel;
    edt1: TEdit;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure btn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;
  Mb:variant;
  Hwnd: THandle;

implementation

{$R *.dfm}

procedure TForm2.FormCreate(Sender: TObject);
begin
  Mb:=CreateOleObject('Matlab.Application'); //Matlab.Application.6
                               //Mb:=GetActiveOleObject('Matlab.Application');
  Hwnd := (Findwindow(nil, 'MATLAB Server'));
  ShowWindow(Hwnd, SW_HIDE);  //SW_SHOW
end;

procedure TForm2.FormDestroy(Sender: TObject);
begin
  Mb.execute('clear');
end;

procedure TForm2.btn1Click(Sender: TObject);
var
  str,str2: string;
  strl: array of string;
  I: Integer;
begin
  str :=' P=[0.2286	0.209	  0.0442	0.2603	0.369	0.0359	0.1759	0.0724	0.2634; 0.1292	0.0947  0.088	0.1715	0.2222 0.1149	0.2347	0.1909	0.2258;0.072	0.1393  0.1147	0.0702	0.0562	0.123	0.1829	0.134	  0.1165;' ;
  str := str + ' 0.1592	0.1387  0.0563	0.2711	0.5157	0.546	0.1811	0.2409	0.1154; 0.1335	0.2558	0.3347	0.1491	0.1872	0.1977	0.2922	0.2842	0.1074; 0.0733	0.09	0.115	0.133	0.1614	0.1248	0.0655	0.045	0.0657;';
  str := str + ' 0.1159	0.0771	0.1453	0.0968	0.1425	0.0624	0.0774	0.0824	0.061; 0.094	0.0882	0.0429	0.1911	0.1506	0.0832	0.2273	0.1064	0.2623; 0.0522	0.0393	0.1818	0.2545	0.131	0.164	0.2056	0.1909	0.2588;';
  str := str + ' 0.1345	0.143	0.0378	0.0871	0.05	0.1002	0.0925	0.1586	0.1155;0.009	0.0126	0.0092	0.006	0.0078	0.0059	0.0078	0.0116	0.005;0.126	0.167	0.2251	0.1793	0.0348	0.1503	0.1852	0.1698	0.0978;';
  str := str +' 0.3619	0.245	0.1516	0.1002	0.0451	0.1837	0.3501	0.3644	0.1511; 0.069	0.0508	0.0858	0.0789	0.0707	0.1295	0.168	0.2718	0.2273; 0.1828	0.1328	0.067	0.0909	0.088	0.07	0.2668	0.2494	0.322];';
  str := str +' T=[1 1 1 0 0 0 0 0 0;0 0 0 1 1 1 0 0 0; 0 0 0 0 0 0 1 1 1];';
  str := str +' threshold=[0	1;0	1;0	1;0	1;0	1;0	1;0	1;0	1;0	1;0	1;0	1;0	1;0	1;0	1;0	1];';
  str := str +' net=newff(threshold,[31,3],{''tansig'',''logsig''},''trainlm'');';
  str := str +' net.trainParam.epochs=100; net.trainParam.goal=0.01; LP.lr=0.1; net=train(net,P,T);';
  redt1.Text:=Mb.execute(str);
  str2 := ' p_test=[0.2101 0.0950 0.1298 0.1359 0.2601 0.1001 0.0753 0.0890 0.0389 0.1451 0.0128 0.1590 0.2452 0.0512 0.1319;0.2593 0.1800 0.0711 0.2801 0.1501 0.1298 0.1001 0.1891 0.2531 0.0875 0.0058 0.1803 0.0992 0.0802 0.1002]'';';
 // str2 := str2 +' 0.2599 0.2235 0.1201 0.1171 0.1102 0.0683 0.0621 0.2597 0.2602 0.1167 0.0048 0.1002 .01521 0.2281 0.3205]'';' ;
  str2 := str2 +' Y=sim(net,p_test)';
  redt2.Text:=Mb.execute(str2);

  str:='';
  for I := 0 to 5 do    // Iterate
  begin
    SetLength(strl,6);
    strl[I] := redt2.Lines.Strings[I];
    str:=str + strl[I]+' ';
  end;
  edt1.Text := str;
end;

end.

⌨️ 快捷键说明

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