igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] graph matching with igraph


From: Tamas Nepusz
Subject: Re: [igraph] graph matching with igraph
Date: Mon, 12 Jan 2015 11:06:06 +0100
User-agent: Mutt/1.5.23 (2014-03-12)

Hello,

Your question is very broad so I can respond to only the more concrete parts of
it:

> Conceptually, the idea is simple, but in practice I don't know how I can
> iterate over the nodes, and how I can create the second  weighted graph using
> igraph. 
Nodes can be iterated over as follows:

for vertex in graph.vs:
    ...

where graph.vs is a VertexSeq object that represents the sequence of vertices
in the graph (and can be used as a Python list in most contexts). When the
VertexSeq is iterated over, it yields Vertex objects, which can be used like
Python dictionaries to access their attributes. Vertex objects also have an
attribute named "index", returning the index of the vertex within the vertex
sequence of the graph.

Creating another weighted graph is probably easiest by collecting the edges and
weights into a dictionary and the calling Graph.TupleList() to construct the
new graph. So, something like:

edges = dict()
for v1 in source_graph.vs:
    for v2 in target_graph.vs:
            similarity = calculate_similarity_somehow(v1, v2)
                if similarity >= threshold:
                    edges[v1, v2] = similarity

similarity_graph = Graph.TupleList(\
        ((v1, v2, weight) for (v1, v2), weight in edges.iteritems()),
        weights=True
)

Best,
-- 
T.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]