==== NearestNeighbor[] graph from Adjacency Matrix - typically from matrix computation ====
​
===== INPUT =====
In[]:=
vertices={"A","B","C","D"};
In[]:=
adjM=​​{{0,0.1,0.4,0.2},​​{0.1,0,0.1,0.5},​​{0.4,0.1,0,0.2},​​{0.2,0.5,0.2,0}};
​
===== COMPUTATION =====
In[]:=
vcount=Length[vertices];
In[]:=
indicesHash=CreateDataStructure["HashTable"];
In[]:=
Do[indicesHash["Insert",vertices[[i]]i],{i,1,vcount}];
In[]:=
vdistance[x_,y_]:=adjM[[indicesHash["Lookup",x],indicesHash["Lookup",y]]];
In[]:=
edges=EdgeList@NearestNeighborGraph[​​vertices,​​DirectedEdgesFalse,​​DistanceFunctionvdistance]
Out[]=
{AB,AD,BC,CD}
In[]:=
edgelabels=Flatten[​​{(#)->adjM[[indicesHash["Lookup",#[[1]]],indicesHash["Lookup",#[[2]]]]]}&/@edges]
Out[]=
{AB0.1,AD0.2,BC0.1,CD0.2}
​
===== OUTPUT =====
In[]:=
nng=NearestNeighborGraph[​​vertices,​​DirectedEdgesFalse,​​DistanceFunctionvdistance,​​VertexLabelsAll,​​VertexLabelStyle"Medium",​​EdgeLabelsedgelabels,​​EdgeLabelStyleMedium,​​ImageSizeSmall]
Out[]=
In[]:=
Dendrogram[vertices,DistanceFunctionvdistance]
Out[]=