<<Combinatorica`

Import["C:\Documents and Settings\user\Asztal\karate.txt"]

SetDirectory[NotebookDirectory[]]

Import["karate.txt","Elements"]

l=Import["karate.txt","Words"];

csúcsok száma:

node=0;
n=1;
While[n<Length[l], If[l[[n]]=="node", node++]; n++]
node

Count[l,"node"]

az élek kezdőpontjai:

k={};
n=1;
While[n<Length[l], If[l[[n]]=="source", AppendTo[k,l[[n+1]]]]; n++]
Print[k]

az élek végpontjai:

v={};
n=1;
While[n<Length[l], If[l[[n]]=="target", AppendTo[v,l[[n+1]]]]; n++]
Print[v]

ellenőrzés:

Length[k]==Length[v]

h=Length[k]

edges={}
n=1;
While[n<h+1, AppendTo[edges, {k[[n]] -> v[[n]]}]; n++ ]
Print[edges]

graf=Flatten[edges]

GraphPlot[graf]

GraphPlot[graf,VertexLabeling->True, DirectedEdges->True]

<<"GraphUtilities`"

GraphPlot3D[graf, VertexLabeling->True]

GraphPlot3D[graf,EdgeRenderingFunction->(Cylinder[#1,.05]&),VertexRenderingFunction->({ColorData["Atoms"][RandomInteger[{1,117}]],Sphere[#1,.15]}&),PlotStyle->Directive[Specularity[White,20]]]

GraphPlot3D[graf,PlotStyle->Directive[PointSize[Large],Red],VertexRenderingFunction->Function[{p,l},{Green,Point[p]}]]

graf2={"2"->"1","3"->"1","3"->"2","4"->"1","4"->"2","4"->"3","5"->"1","6"->"1","7"->"1","7"->"5","7"->"6","8"->"1","8"->"2","8"->"3","8"->"4","9"->"1","9"->"3","10"->"3","11"->"1","11"->"5","11"->"6","12"->"1","13"->"1","13"->"4","14"->"1","14"->"2","14"->"3","14"->"4","17"->"6","17"->"7","18"->"1","18"->"2","20"->"1","20"->"2","22"->"1","22"->"2","26"->"24","26"->"25","28"->"3","28"->"24","28"->"25","29"->"3","30"->"24","30"->"27","31"->"2","31"->"9","32"->"1","32"->"25","32"->"26","32"->"29","33"->"3","33"->"9","33"->"15","33"->"16","33"->"19","33"->"21","33"->"23","33"->"24","33"->"30","33"->"31","33"->"32","34"->"9","34"->"10","34"->"14","34"->"15","34"->"16","34"->"19","34"->"20","34"->"21","34"->"23","34"->"24","34"->"27","34"->"28","34"->"29","34"->"30","34"->"31","34"->"32","34"->"33"};

Map[ToExpression,graf2,{2}]

TreeForm[graf2]

Plot[Tooltip[Sin[x]],{x,0,2π}]

Plot[]

Adatelőkészítés nélkül

SetDirectory[NotebookDirectory[]]

Import["karate.gml","Elements"]

adj=Import["karate.gml","AdjacencyMatrix"];

adj==Transpose[adj]

Máris szimmetrikus.

GraphPlot[adj,VertexLabeling->True,ImageSize->700]

v=Length[adj](*A csúcsok száma?*)

Total[adj,2]

(*normált adj mátrix*)m=(adj/(Total[adj,2]));

(*sorosszegek*)d=m.ConstantArray[1.,v](*normált fokszám, másképp?*)

Total[d]

dd=DiagonalMatrix[1/(Sqrt[d])];

MatrixForm[skalazott=dd.m.dd];

eval=Eigenvalues[skalazott]//Chop

ListLinePlot[Abs[eval]]

evec1=Eigenvectors[skalazott][[1]]

Norm[%]

(sq=Sqrt[d])==-evec1

Másképp

-evec1/sq

Ortogonálisak:

Eigenvectors[skalazott][[3]].Eigenvectors[skalazott][[5]]//Chop

Klaszterezés egy sajátvektorból

Column[{dd. Eigenvectors[skalazott][[1]],dd.Eigenvectors[skalazott][[2]]}]

ddd=dd.Eigenvectors[skalazott][[2]]

cc=ClusteringComponents[ddd,2]

Needs["Combinatorica`"]

Total[adj]

Ez nem megy:

Degrees[adj];

Ez sem:

Vertices[adj];

GraphPlot[AdjacencyGraph[adj],VertexRenderingFunction->({If[cc[[#2]]==1,Red,Blue],EdgeForm[Black],Disk[#,.15]}&),ImageSize->800]

GraphPlot[AdjacencyGraph[adj],VertexRenderingFunction->({White,EdgeForm[Black],Disk[#,.15],If[cc[[#2]]==1,Red,Blue],Text[Row[{Style[#2,Bold,10],":",Style[Total[adj][[#2]],Bold,Black,10]}],#1]}&),ImageSize->800]

Program egy (második) svektor esetére