Сравнительный анализ нейросетевых реализаций алгоритмов распознавания образов
Рефераты >> Кибернетика >> Сравнительный анализ нейросетевых реализаций алгоритмов распознавания образов

Рис. 3.

Рис. 4.

Рис. 5.

Рис. 6.

Рис. 7.

Приложение 2.

Программа, моделирующая однослойную сеть.

unit UPerc;

interface

uses

Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,

Percept_Field, StdCtrls, Buttons, ExtCtrls;

const InputLayerUnits=35;

OutputLayerUnits=2;

eta=0.05;

epsilon=0.000001;

numberpatterns=36;

type

TFrmPerceptron = class(TForm)

Percept_FieldPerc: TPercept_Field;

GroupBoxTrain: TGroupBox;

GroupBoxInit: TGroupBox;

ComboBoxABC: TComboBox;

ComboBoxDigits: TComboBox;

BtnNext: TButton;

BitBtnClose: TBitBtn;

EditNumPat: TEdit;

LabelNumPat: TLabel;

GroupBoxRec: TGroupBox;

LabelInput: TLabel;

BtnOutput: TButton;

LabelOdd: TLabel;

RadioGroupTarget: TRadioGroup;

RadioButtonOdd: TRadioButton;

RadioButtonEven: TRadioButton;

LabelOr: TLabel;

LabelEven: TLabel;

procedure ComboBoxABCChange(Sender: TObject);

procedure ComboBoxDigitsChange(Sender: TObject);

procedure Percept_FieldPercMouseDown(Sender: TObject;

Button: TMouseButton; Shift: TShiftState; X, Y: Integer);

procedure BitBtnCloseClick(Sender: TObject);

procedure FormCreate(Sender: TObject);

procedure BtnNextClick(Sender: TObject);

procedure BtnOutputClick(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

FrmPerceptron: TFrmPerceptron;

var

w:array[1 OutputLayerUnits,1 InputLayerUnits] of real;

indexBtnNextClick:byte;

activation:array[1 OutputLayerUnits] of real;

OutputLayerOutput:array[1 OutputLayerUnits] of shortint;

target:array[1 numberpatterns,1 OutputLayerUnits] of shortint;

v:array[1 numberpatterns,1 InputLayerUnits] of shortint;

implementation

{$R *.DFM}

procedure TFrmPerceptron.Percept_FieldPercMouseDown(Sender: TObject;

Button: TMouseButton; Shift: TShiftState; X, Y: Integer);

var m,k:BYTE;

correctRect:shortint;

L,T,H,V:INTEGER;

begin

L:=0;

T:=0;

H:=Percept_FieldPerc.UnitHorizontal;

V:=Percept_FieldPerc.UnitVertical;

for m :=1 to Percept_FieldPerc.UnitRectVert do

begin

for k :=1 to Percept_FieldPerc.UnitRectHorz do

begin

if (X<H) and (X>L) and (Y<V) and (Y>T) then

begin

correctRect:=k+Percept_FieldPerc.UnitRectHorz*(m-1);

if (Button=mbLeft) and

(Percept_FieldPerc.Brushes[correctRect]=Percept_FieldPerc.BackGroundBrush) then

begin

Percept_FieldPerc.Brushes[correctRect]:=Percept_FieldPerc.RectBrush;

end

else

if (Button=mbRight) and

(Percept_FieldPerc.Brushes[correctRect]=Percept_FieldPerc.RectBrush)then

begin

Percept_FieldPerc.Brushes[correctRect]:=Percept_FieldPerc.BackGroundBrush;

end;

end;

inc(L,Percept_FieldPerc.UnitHorizontal);

inc(H,Percept_FieldPerc.UnitHorizontal);

end;

inc(T,Percept_FieldPerc.UnitVertical);

inc(V,Percept_FieldPerc.UnitVertical);

L:=0;

H:=Percept_FieldPerc.UnitHorizontal;

end;

end;

procedure TFrmPerceptron.BitBtnCloseClick(Sender: TObject);

begin

Close;

end;

procedure TFrmPerceptron.FormCreate(Sender: TObject);

var i,j:byte;

rand:real;

begin

//numberpatterns:=2;//10;

EditNumPat.Text:=inttostr(numberpatterns);

BtnNext.Font.Color:=clRed;

indexBtnNextClick:=0;

LabelInput.Visible:=False;

// *********************************************

Randomize;// случайные веса (-0.5,0.5)

for i := 1 to OutputLayerUnits do

begin

for j := 1 to InputLayerUnits do

begin

rand:=Random-0.5;

w[i,j]:=rand;

end;

end;

end;

procedure TFrmPerceptron.BtnNextClick(Sender: TObject);

var i,j,m:byte;

sum:real;

neterror,err:real;

error:array[1 OutputLayerUnits] of real;

stop:boolean;

krandom:integer;

begin

indexBtnNextClick:=indexBtnNextClick+1;

for m:=1 to InputLayerUnits do begin

if (Percept_FieldPerc.Brushes[m]=Percept_FieldPerc.RectBrush) then

begin

v[indexBtnNextClick,m]:=1;

end

else

if (Percept_FieldPerc.Brushes[m]=Percept_FieldPerc.BackGroundBrush) then

begin

v[indexBtnNextClick,m]:=-1;

end;

end;

// ******************ODD or EVEN*********************

if RadioButtonOdd.Checked then

begin

target[indexBtnNextClick,1]:=1;

target[indexBtnNextClick,2]:=-1;

end

else

if RadioButtonEven.Checked then

begin

target[indexBtnNextClick,1]:=-1;

target[indexBtnNextClick,2]:=1;

end;

// ***************************************************

if (indexBtnNextClick+1)=numberpatterns then

begin

BtnNext.Caption:='last';

end

else

begin

if (indexBtnNextClick)=numberpatterns then

begin

BtnNext.Font.Color:=clWindowText;

BtnNext.Caption:='finished';

LabelInput.Font.Color:=clRed;


Страница: