Message Boards Message Boards

GROUPS:

Is there a predefined DistanceFunction for numerically weighted graphs?

Posted 1 year ago
1381 Views
|
3 Replies
|
0 Total Likes
|

Here's a scaled-down example. I have graphs with weighted edges that I'd like to use in NearestNeighborGraph, Dendrogram, ClusteringTree, etc. So far I've only had success with Graph[] and GraphDistance[].

vertices = {"A", "B", "C", "D"} ;
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}} ;
edges = Flatten[
   Table[Table[
     Annotation[
      Extract[vertices, i] \[UndirectedEdge] Extract[vertices, j], 
      EdgeWeight -> Extract[Extract[adjM, i], j]], {j, i + 1, 4}], {i,
      1, 3}]] ;
g4 = Graph[edges];
Graph[g4,
 VertexLabels -> All,
 VertexLabelStyle -> "Medium",
 EdgeLabels -> "EdgeWeight",
 EdgeLabelStyle -> Medium,
 GraphLayout -> "RadialDrawing",
 ImageSize -> Small]

GraphDistance[g4, "A", "C"]
0.2
NearestNeighborGraph[edges]
    NearestFunction: The default distance function does not give a real number distance when applied to the point pair A\[UndirectedEdge]B and A\[UndirectedEdge]C

Dendrogram[edges]
    (unweighted output)
3 Replies

Please include the definitions for edgeweightrules265 and graph265 and the arguments to NearestNeighborGraph.

Why is edgerule1 set to a FullForm?

Thank you, please see edited 1st post above.

Here's a solution for the above example.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract