Смекни!
smekni.com

Кластеризация групп входящих пакетов с помощью нейронных сетей конкурирующего типа (стр. 7 из 7)

for i:=0 to Q-1 do

begin

MyList.Clear;

Read(F,j);

MyList.Add(IntToStr(j));

//Memo4.Lines.Add(IntToStr(j));

Read(F,Ch);

Read(F,Ch);

Read(F,Ch);

Prot[i]:='';

While(ch<>' ') do

begin

Prot[i]:=Prot[i]+Ch;

Read(F,Ch);

end;

MyList.Add(Prot[i]);

Read(F,Ch);

Read(F,Ch);

Read(F,Ch);

Host[i]:='';

While(ch<>' ') do

begin

Host[i]:=Host[i]+Ch;

Read(F,Ch);

end;

MyList.Add(Host[i]);

Read(F,Ch);

Read(F,Ch);

Str:='';

While(ch<>' ') do

begin

Str:=Str+Ch;

Read(F,Ch);

end;

MyList.Add(Str);

if Str='YES' then LocalH[i]:=1 else LocalH[i]:=0;

Read(F,Ch);

Read(F,Ch);

Str:='';

While(ch<>' ') do

begin

Str:=Str+Ch;

Read(F,Ch);

end;

MyList.Add(Str);

if Str='YES' then Frag[i]:=1 else Frag[i]:=0;

Read(F,Size[i]);

MyList.Add(IntToStr(Size[i]));

Read(F,Proc[i]);

MyList.Add(IntToStr(Proc[i]));

Read(F,Ch);

Read(F,Ch);

Read(F,Ch);

Str:='';

While(ch<>' ') do

begin

Str:=Str+Ch;

Read(F,Ch);

end;

MyList.Add(Str);

if Str='YES' then Active[i]:=1 else Active[i]:=0;

StringGrid1.Rows[j]:=MyList;

Read(F,Ch);

if Ch='H' then HACK[i]:=1 else HACK[i]:=0;

//Memo4.Lines.Add('**************');

end;

//Memo4.Lines.Add(IntToStr(Q));

CloseFile(F);

SetLength(Temp,10);

SetLength(Mass,(Q-1)*11);

SetLength(SHack,Q-1);

for i:=0 to Q-12 do

begin

Mass[12*i]:=0;

for j:=0 to 9 do Mass[12*i]:=Mass[12*i]+LocalH[i+j];

Mass[12*i+1]:=0;

for j:=0 to 9 do Mass[12*i+1]:=Mass[12*i+1]+Frag[i+j];

Mass[12*i+2]:=0;

Mass[12*i+3]:=0;

for j:=0 to 9 do

if Prot[i+j]='TCP' then Mass[12*i+2]:=Mass[12*i+2]+1;

for j:=0 to 9 do

if Prot[i+j]='UDP' then Mass[12*i+3]:=Mass[12*i+3]+1;

Sum:=1;

s1:=0;

for j:=0 to 9 do

begin

Str:=Host[i+j];

p:=0;

for k:=0 to 9 do

begin

if Str=Host[i+k] then

begin

p:=p+1;

s2:=k;

end;

end;

if p>Sum then

begin

Sum:=p;

s1:=s2;

end;

end;

Mass[12*i+4]:=Sum;

Mass[12*i+5]:=LocalH[i+s1];

Sum:=0;

for j:=0 to 9 do Sum:=Sum+Proc[i+j];

Mass[12*i+6]:=Sum/10;

Mass[12*i+7]:=Proc[i+9]-Proc[i];

Sum:=0;

for j:=0 to 9 do Sum:=Sum+Size[i+j];

Mass[12*i+8]:=Sum/10;

Sum:=0;

for j:=0 to 9 do

if (Size[i+j]>=0.8*Mass[12*i+8])and

(Size[i+j]<=1.2*Mass[12*i+8]) then Sum:=Sum+1;

Mass[12*i+9]:=Sum;

Sum:=0;

for j:=0 to 9 do Sum:=Sum+Active[i+j];

Mass[12*i+10]:=Sum;

for j:=0 to 9 do Temp[j]:=Host[i+j];

for j:=0 to 8 do

begin

Str:=Temp[j];

for k:=0 to 9 do

if k<>j then

if Str=Temp[k] then Temp[k]:='';

end;

Sum:=0;

for j:=0 to 9 do

if Temp[j]<>'' then Sum:=Sum+1;

Mass[12*i+11]:=Sum;

Sum:=0;

for j:=0 to 9 do Sum:=Sum+HACK[i+j];

SHAck[i]:=Sum;

end;

end;

end;

procedure TForm1.InitializationMap;

var i,j,p : integer;

begin

for i:=0 to H*W-1 do

begin

p:=Random(Q-13);

for j:=0 to 10 do

KMap.Neurons[i].MassWeight[j+1]:=Mass[12*p+j];

end;

end;

procedure TForm1.Button3Click(Sender: TObject);

var i,j,p,k,m : integer;

Quant,Winner : integer;

Part : TExtArray;

SMax,SMin : Extended;

begin

InitializationMap;

for i:=0 to Image1.Height-1 do

for j:=0 to Image1.Width-1 do

Image1.Picture.Bitmap.Canvas.Pixels[i,j]:=RGB(150,150,150);

Quant:=StrToInt(Edit3.Text);

Part:=TExtArray.Init(12);

SMax:=0.7;

SMin:=0.0001;

ProgressBar1.Max:=Quant;

ProgressBar1.Position:=0;

for i:=0 to Quant-1 do

begin

KMap.SigmaInit(10*(1-i/Quant)+0.1);

p:=Random(Q-12);

for j:=0 to 11 do Part.Value[j]:=Mass[12*p+j];

KMap.GetInputValues(@Part);

KMap.Excitement;

Case RadioGroup1.ItemIndex of

0:

begin

Winner:=KMap.Classic;

if CheckBox1.Checked then KMap.LearningNeib(Winner,SMax-(SMax-SMin)*i/Quant)

else KMap.Learning(Winner,SMax-(SMax-SMin)*i/Quant);

end;

1:

begin

Winner:=KMAp.TheWinnerTakesItAll;

if CheckBox1.Checked then KMap.LearningNeib(Winner,SMax-(SMax-SMin)*i/Quant)

else KMap.Learning(Winner,SMax-(SMax-SMin)*i/Quant)

end;

2:

begin

KMap.NeuralGaz(SMax-(SMax-SMin)*i/Quant);

end;

end;

ProgressBar1.StepBy(1);

end;

ProgressBar1.Position:=0;

for i:=0 to KMap.QNeurons-1 do

KMap.Neurons[i].MassWeight[0]:=0;

for i:=0 to Q-12 do

begin

for j:=0 to 11 do Part.Value[j]:=Mass[12*i+j];

KMap.GetInputValues(@Part);

KMap.Excitement;

Winner:=KMap.Classic;

KMap.Neurons[Winner].MassWeight[0]:=1;

//Memo4.Lines.Add(IntToStr(Winner));

if SHack[i]>=8 then

begin

for m:=0 to W1-1 do

for k:=0 to H1-1 do

Image1.Picture.Bitmap.Canvas.Pixels[(Winner div W)*W1+m,(Winner mod W)*H1+k]:=RGB(255,0,0);

end

else if SHack[i]=7 then

begin

for m:=0 to W1-1 do

for k:=0 to H1-1 do

Image1.Picture.Bitmap.Canvas.Pixels[(Winner div W)*W1+m,(Winner mod W)*H1+k]:=RGB(255,40,40);

end

else if SHack[i]=6 then

begin

for m:=0 to W1-1 do

for k:=0 to H1-1 do

Image1.Picture.Bitmap.Canvas.Pixels[(Winner div W)*W1+m,(Winner mod W)*H1+k]:=RGB(225,80,80);

end

else if SHack[i]=5 then

begin

for m:=0 to W1-1 do

for k:=0 to H1-1 do

Image1.Picture.Bitmap.Canvas.Pixels[(Winner div W)*W1+m,(Winner mod W)*H1+k]:=RGB(225,120,120);

end

else if SHack[i]=4 then

begin

for m:=0 to W1-1 do

for k:=0 to H1-1 do

Image1.Picture.Bitmap.Canvas.Pixels[(Winner div W)*W1+m,(Winner mod W)*H1+k]:=RGB(225,160,160);

end

else if SHack[i]=3 then

begin

for m:=0 to W1-1 do

for k:=0 to H1-1 do

Image1.Picture.Bitmap.Canvas.Pixels[(Winner div W)*W1+m,(Winner mod W)*H1+k]:=RGB(225,200,200);

end

else

begin

for m:=0 to W1-1 do

for k:=0 to H1-1 do

Image1.Picture.Bitmap.Canvas.Pixels[(Winner div W)*W1+m,(Winner mod W)*H1+k]:=RGB(225,225,225);

end;

//Image2.Picture.Bitmap.Canvas.

//.Pixels[j,i]:=RGB(

end;

for i:=0 to KMap.QNeurons-1 do

begin

if KMap.Neurons[i].MassWeight[0]=1 then

begin

Memo3.Lines.Add('Íåéðîí '+IntToStr(i));

for j:=0 to KMap.QInputs-1 do

Memo3.Lines.Add(FloatToStr(KMap.Neurons[i].MassWeight[j]));

end;

end;

end;