Skip to content
Prev 164538 / 398503 Next

i graph library: how can generates a fully connected graph from a similarity matrix

On Fri, Dec 12, 2008 at 2:10 AM, dinesh kumar <barupal at gmail.com> wrote:
Actually your matrix is only 87x87.

If you mean that you want a graph with 87 vertices, and some edge
weights being zero, then you can simply do (assuming there are no
negative edge weights)

G <- graph.adjacency(adjmat+1, mode="undirected", weighted=TRUE)
E(G)$weight <- E(G)$weight - 1

If you mean that you want to remove isolate vertices after creating
the graph, that would be:

G <- graph.adjacency(adjmat, mode="undirected", weighted=TRUE)
G <- remove.vertices(G, V(G)[ degree(G)==0 ])

(For your data nothing really happens, there are no isolate vertices.)
You can remove it initially, from the matrix:

adjmat2 <- adjmat
adjmat2[ adjmat2 < 0.7 ] <- 0
G <- graph.adjacency(adjmat2, mode="undirected", weighted=TRUE)

or after, from the graph itself:

G <- graph.adjacency(adjmat+1, mode="undirected", weighted=TRUE)
E(G)$weight <- E(G)$weight - 1
G2 <- delete.edges(G, E(G)[ weight < 0.7 ])

Gabor

ps. there is also an igraph mailing list, you can find it from the
igraph homepage. Just in case I miss your messages here.