Eredeti program

SetDirectory[NotebookDirectory[]];
ClearAll[programk];
programk[s_String, k_Integer]:= Module[{adj,m,dd,skalazott,ddd2,ddd3,t,ddd,cc,v},
adj=Import[s,"AdjacencyMatrix"];
v=Import[s,"VertexCount"];
m=(adj/(Total[adj,2]));
dd=DiagonalMatrix[1/(Sqrt[m.ConstantArray[1.,v]])];
skalazott=dd.m.dd;
t=Table[Flatten[Take [Table[Eigenvectors[skalazott][[i]],{i,2,k+1}],All, {j,j}]],{j,v}];
ddd=dd.t;
cc=ClusteringComponents[ddd,k+1,1];
GraphPlot[AdjacencyGraph[adj],VertexRenderingFunction->({Hue[cc[[#2]]/(k+1)],EdgeForm[Black],Disk[#,.15]}&),ImageSize->800]]

Import["celegans_metabolic.net","Elements"]

programk["celegans_metabolic.net",1]

Legkisebb klaszter kitörlése

SetDirectory[NotebookDirectory[]];
ClearAll[p];
p[s_String, k_Integer]:= Module[{adj,m,dd,skalazott,ddd2,ddd3,t,ddd,cc,v},
adj=Import[s,"AdjacencyMatrix"];
v=Import[s,"VertexCount"];
m=(adj/(Total[adj,2]));
dd=DiagonalMatrix[1/(Sqrt[m.ConstantArray[1.,v]])];
skalazott=dd.m.dd;
t=Table[Flatten[Take [Table[Eigenvectors[skalazott][[i]],{i,2,k+1}],All, {j,j}]],{j,v}];
ddd=dd.t;
cc=ClusteringComponents[ddd,k+1,1]]

SetDirectory[NotebookDirectory[]];
ClearAll[tr];
tr[s_String, k_Integer]:= Module[{adj,m,dd,skalazott,t,ddd,cc,v,e,l,r,q,adj2,m2,dd2,skalazott2,t2,ddd2,cc2,v2,a,a0},
adj=Import[s,"AdjacencyMatrix"];
v=Import[s,"VertexCount"];
cc=p[s, k];

e=Table[Count[cc,j],{j,k+1}];
r=Flatten[Position[cc,Flatten[Position[e,Min[e]]][[1]]]];(*azok a helyek, amiket törölni kell*)
q=Complement[Range[v],r]; (*megmaradók helyei*)
a={};
For[i=1,i<Length[q],i++, AppendTo[a,adj[[q[[i]]]]]];
a0={};
adj2=Table[AppendTo[a0,{}],Range[Length[q]]];
Table[For[i=1,i<Length[q],i++, AppendTo[adj2[[j]],a[[j]][[q[[i]]]]]],{j,Length[a]}];
m2=(adj2/(Total[adj2,2]));
v2=Length[adj2];
dd2=DiagonalMatrix[1/(Sqrt[m2.ConstantArray[1.,v2]])];
skalazott2=dd2.m2.dd2;
t2=Table[Flatten[Take [Table[Eigenvectors[skalazott2][[i]],{i,2,k}],All, {j,j}]],{j,v2}];
ddd2=dd2.t2;
cc2=ClusteringComponents[ddd2,k,1]]

tr["karate.gml",2]