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

FirstLayerError:array[1 FirstLayerUnits] of real;

dWeightSecondThird:array[1 ThirdLayerUnits,1 SecondLayerUnits] of real;

dWeightFirstSecond:array[1 SecondLayerUnits,1 FirstLayerUnits] of real;

dWeight:real;

krandom:integer;

begin

indexBtnNextClick:=indexBtnNextClick+1;

for m:=1 to FirstLayerUnits do begin

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

begin

v[indexBtnNextClick,m]:=1;

end

else

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

begin

v[indexBtnNextClick,m]:=-1;

end;

end;

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

if RadioButtonFigure.Checked then

begin

target[indexBtnNextClick,1]:=0.9;//1;

target[indexBtnNextClick,2]:=0.1;//-1;

end

else

if RadioButtonLetter.Checked then

begin

target[indexBtnNextClick,1]:=0.1;//-1;

target[indexBtnNextClick,2]:=0.9;//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;

LabelInput.Visible:=True;

end

else

begin

BtnNext.Caption:='next';

end;

end;

//***********************MAIN**************************

if (indexBtnNextClick)=numberpatterns then

begin

repeat

stop:=false;

for m := 1 to numberpatterns do

begin

for i := 1 to SecondLayerUnits do

begin

sumFirstSecond:=0;

for j := 1 to FirstLayerUnits do

begin

sumFirstSecond:=sumFirstSecond+wFirstSecond[i,j]*v[m,j];

end;

OutputSecond[i]:=1/(1+exp(-sumFirstSecond));

end;

for i := 1 to ThirdLayerUnits do

begin

sumSecondThird:=0;

for j := 1 to SecondLayerUnits do

begin

sumSecondThird:=sumSecondThird+wSecondThird[i,j]*OutputSecond[j];

end;

OutputThird[i]:=1/(1+exp(-sumSecondThird));

end;

neterror:=0;

for i := 1 to ThirdLayerUnits do

begin

output:=OutputThird[i];

err:=target[m,i]-output;

OutLayerError[i]:=output*(1-output)*err;

neterror:=neterror+0.5*sqr(err);

end;

if neterror<epsilon then

begin

stop:=true;

end;

end;//*** for m:= . ******

//****************обучение**************

if not stop then

begin

Randomize;

for krandom:=1 to 10*numberpatterns do

begin

m:=1+Round(Random(numberpatterns));

//***********PROPAGATION************

for i := 1 to SecondLayerUnits do

begin

sumFirstSecond:=0;

for j := 1 to FirstLayerUnits do

begin

sumFirstSecond:=sumFirstSecond+wFirstSecond[i,j]*v[m,j];

end;

OutputSecond[i]:=1/(1+exp(-sumFirstSecond));

end;

for i := 1 to ThirdLayerUnits do

begin

sumSecondThird:=0;

for j := 1 to SecondLayerUnits do

begin

sumSecondThird:=sumSecondThird+wSecondThird[i,j]*OutputSecond[j];

end;

OutputThird[i]:=1/(1+exp(-sumSecondThird));

end;

neterror:=0;

for i := 1 to ThirdLayerUnits do

begin

output:=OutputThird[i];

err:=target[m,i]-output;

OutLayerError[i]:=output*(1-output)*err;

neterror:=neterror+0.5*sqr(err);

end;

//*********BACKPROPAGATION**************

for i := 1 to SecondLayerUnits do

begin

output:=OutputSecond[i];

err:=0;

for j := 1 to ThirdLayerUnits do

begin

err:=err+wSecondThird[j,i]*OutLayerError[j];

end;

SecondLayerError[i]:=output*(1-output)*err;

end;

for i := 1 to FirstLayerUnits do

begin

output:=v[m,i];

err:=0;

for j := 1 to SecondLayerUnits do

begin

err:=err+wFirstSecond[j,i]*SecondLayerError[j];

end;

FirstLayerError[i]:=output*(1-output)*err;

end;

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

for i := 1 to SecondLayerUnits do

begin

for j := 1 to FirstLayerUnits do

begin

dWeightFirstSecond[i,j]:=0;

end;

end;

for i := 1 to ThirdLayerUnits do

begin

for j := 1 to SecondLayerUnits do

begin

dWeightSecondThird[i,j]:=0;

end;

end;

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

dWeight:=0;

for i := 1 to SecondLayerUnits do

begin

for j := 1 to FirstLayerUnits do

begin

output:=v[m,j];

err:=SecondLayerError[i];

dWeight:=dWeightFirstSecond[i,j];

wFirstSecond[i,j]:=wFirstSecond[i,j]+eta*err*output+alpha*dWeight;

dWeightFirstSecond[i,j]:=eta*err*output;

end;

end;

dWeight:=0;

for i := 1 to ThirdLayerUnits do

begin

for j := 1 to SecondLayerUnits do

begin

output:=OutputSecond[j];

err:=OutLayerError[i];

dWeight:=dWeightSecondThird[i,j];

wSecondThird[i,j]:=wSecondThird[i,j]+eta*err*output+alpha*dWeight;

dWeightSecondThird[i,j]:=eta*err*output;

end;

end;

end;//****for krandom:= .***********

end;

until stop;

end;//*** IF ********

end;

procedure TFrmBack.ButtonOutClick(Sender: TObject);

var m,i,j:byte;

z:array[1 FirstLayerUnits] of shortint;

sumFirstSecond,sumSecondThird:real;

OutputSecond:array[1 SecondLayerUnits] of real;

OutputThird:array[1 ThirdLayerUnits] of real;

begin

for m:=1 to FirstLayerUnits do begin

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

begin

z[m]:=1;

end

else

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

begin

z[m]:=-1;

end;

end;

for i := 1 to SecondLayerUnits do

begin

sumFirstSecond:=0;

for j := 1 to FirstLayerUnits do

begin

sumFirstSecond:=sumFirstSecond+wFirstSecond[i,j]*z[j];

end;

OutputSecond[i]:=1/(1+exp(-sumFirstSecond));

end;

for i := 1 to ThirdLayerUnits do

begin

sumSecondThird:=0;

for j := 1 to SecondLayerUnits do

begin

sumSecondThird:=sumSecondThird+wSecondThird[i,j]*OutputSecond[j];

end;

OutputThird[i]:=1/(1+exp(-sumSecondThird));

end;

if (OutputThird[1]>OutputThird[2]) then

begin

LabelFigure.Font.Color:=clRed;

LabelLetter.Font.Color:=clWindowText;

end

else begin

if (OutputThird[2]>OutputThird[1]) then

begin

LabelLetter.Font.Color:=clRed;

LabelFigure.Font.Color:=clWindowText;

end;

end;

end;

end.

Программа, моделирующая сеть Хопфилда

unit UHop;

interface

uses

Windows, Messages, SysUtils,

Classes, Graphics, Controls,

Forms, Dialogs, StdCtrls, Buttons, Percept_Field;

const numberneurons=35;

type

TFrmHop = class(TForm)

BitBtnClose: TBitBtn;

GrpBoxTraining: TGroupBox;

GrpBoxInitial: TGroupBox;

EditThres: TEdit;

EditNumPat: TEdit;

LabelThres: TLabel;


Страница: