Message Boards Message Boards

1
|
2356 Views
|
3 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Is there a predefined DistanceFunction for numerically weighted graphs?

Posted 4 years ago

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)
POSTED BY: Richard Frost
3 Replies
Posted 4 years ago

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

Why is edgerule1 set to a FullForm?

POSTED BY: Rohit Namjoshi

Thank you, please see edited 1st post above.

POSTED BY: Richard Frost

Here's a solution for the above example.

POSTED BY: Richard Frost
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