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

📄 unit1.pas

📁 感知器算法,通常用于模式识别中.使用DELPHI 7 编制.
💻 PAS
字号:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Button1: TButton;
    Button2: TButton;
    Image1: TImage;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Button3: TButton;
    Button4: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
 var
 str,s1,s2,s3:string;
 num1,num2,num3,num4,num5,num6:array [1..3]of integer;
 t1,t2,t3,t4,t5,t6,c,w1,w2,w3:integer;
procedure TForm1.Button1Click(Sender: TObject);
begin
str:=edit1.Text;
s1:=copy(str,1,1);
s2:=copy(str,3,1);
S3:=copy(str,5,1);
w1:=strtoint(s1);
w2:=strtoint(s2);
w3:=strtoint(s3);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  num1[1]:=0; num1[2]:=1; num1[3]:=1;
num2[1]:=0; num2[2]:=0; num2[3]:=-1;
num3[1]:=-1;num3[2]:=0; num3[3]:=-1;
num4[1]:=1; num4[2]:=1; num4[3]:=1;
num5[1]:=-2;num5[2]:=0; num5[3]:=-1;
num6[1]:=2; num6[2]:=1; num6[3]:=1;
{w1:=1;w2:=1;w3:=1;}
c:=2;
repeat

t1:=w1*num1[1]+w2*num1[2]+w3*num1[3];
if t1<=0 then
begin
w1:=w1+c*num1[1];
w2:=w2+c*num1[2];
w3:=w3+c*num1[3];
end ;
t2:=w1*num2[1]+w2*num2[2]+w3*num2[3];
if t2<=0 then
begin
w1:=w1+c*num2[1];
w2:=w2+c*num2[2];
w3:=w3+c*num2[3];
end;
t3:=w1*num3[1]+w2*num3[2]+w3*num3[3];
if t3<=0 then
begin
w1:=w1+c*num3[1];
w2:=w2+c*num3[2];
w3:=w3+c*num3[3];
end;
t4:=w1*num4[1]+w2*num4[2]+w3*num4[3];
if t4<=0 then
begin
w1:=w1+c*num4[1];
w2:=w2+c*num4[2];
w3:=w3+c*num4[3];
end;
 t5:=w1*num5[1]+w2*num5[2]+w3*num5[3];
if t5<=0 then
begin
w1:=w1+c*num5[1];
w2:=w2+c*num5[2];
w3:=w3+c*num5[3];
end;
t6:=w1*num6[1]+w2*num6[2]+w3*num6[3];
if t6<=0 then
begin
w1:=w1+c*num6[1];
w2:=w2+c*num6[2];
w3:=w3+c*num6[3];
end;
{repeat}
until ((w1*num1[1]+w2*num1[2]+w3*num1[3]>0)and(w1*num2[1]+w2*num2[2]+w3*num2[3]>0)
and(w1*num3[1]+w2*num3[2]+w3*num3[3]>0)and(w1*num5[1]+w2*num5[2]+w3*num5[3]>0)
and(w1*num4[1]+w2*num4[2]+w3*num4[3]>0)and(w1*num6[1]+w2*num6[2]+w3*num6[3]>0));

edit2.text:=inttostr(w1);
edit3.text:=inttostr(w2);
edit4.text:=inttostr(w3);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  with image1.Canvas do
begin
pen.Color:=clred;
PEN.WIDTH:=5;
moveto(0,0);
LINETO(0,0);
moveto(100,0);
lineto(100,0);
moveto(200,0);
lineto(200,0);
pen.Color:=clblue;
moveto(0,100);
lineto(0,100);
moveto(100,100);
lineto(100,100);
 moveto(200,100);
lineto(200,100);
end;
end;

procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
  var
  startp:tpoint;
  isdown:boolean;
  begin
startp.x:=x;
  startp.Y:=y;
  isdown:=true;

  with image1.canvas do
  begin
  moveto(x,y);
  pen.Width:=5;
  if(w1*x+w2*y+w3*100<0)then
  pen.color:=clred
  else
  pen.color:=clblue;
  lineto(x,y);
end;
 end;
procedure TForm1.Button3Click(Sender: TObject);
var
x,y:integer;
begin
with image1.Canvas do
begin
pen.Width:=2;
pen.Color:=clblack;
x:=1;
y:=trunc(-(w1*x+100*w3)/w2);
moveto(x,y);
x:=350;
y:=trunc(-(w1*x+100*w3)/w2);
lineto(x,y);
end;
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
with image1.Canvas do
begin
Brush.Color := ClWhite;
FillRect(Canvas.ClipRect);
pen.Color:=clred;
PEN.WIDTH:=5;
moveto(0,0);
LINETO(0,0);
moveto(100,0);
lineto(100,0);
moveto(200,0);
lineto(200,0);
pen.Color:=clblue;
moveto(0,100);
lineto(0,100);
moveto(100,100);
lineto(100,100);
 moveto(200,100);
lineto(200,100);
end;
end;

end.

⌨️ 快捷键说明

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