Graph Edge Weight?

User 512 | 1/30/2015, 11:32:09 PM

Is there any way to specify the weight for the edges? For example, Vertex 1 has five links to Vertex 2, so the weight here is 5

Or do I need to duplicate the linkage 5 times in the raw data?


User 1190 | 1/31/2015, 8:28:16 PM

You can have any field you like on vertices and edges. For example <pre><code> g.edges['weight'] = 1 </code></pre> will create a "weight" field to every edge and initialize it to one.

Now, how do you want to specify different weight for every edge? The weight either comes from the input data or can be computed. In the first case, add_edges should be able to incorporate any edge fields in your original data. In the second case, you can use apply or triple_apply to compute the weight for each edge based on data of adjacent vertices.

Finally, if your original edge data SFrame comes with duplicate edges, and you want to deduplicate and use the number of occurrence of the same edge in the SFrame as the weight field for the SGraph, you can use SFrame.groupby to compute the weight.

<pre><code> edgesframewithweights = edgesframe.gropuby(["src_id", "dst_id"], {'weight': gl.aggregate.COUNT}) </code></pre>

User 512 | 2/2/2015, 6:05:47 PM

Thanks, Jay! Another question would be how to incorporate the edge weight when creating the graph models? I guess the weight will influence the page rank value, is there any way to use the weight in the "add_edges" statement, something like,

SGraph.addedges(data, srcfield=srcnode, dstfield=dstnode, weight=edgeweight)?

User 92 | 2/3/2015, 2:12:14 AM

Hi Shuning,

From GraphLab Create SGraph's point of view, weight is just another property in the edge, so there is no need to have a separate parameter in addedges() API to emphasize that. When you do sgraph.addedges(), all fields in the 'data' will be stored as edge property in the graph.

Let me know if you have more questions.


User 512 | 2/3/2015, 4:35:18 PM

Thanks, Ping! I am sorry my question is probably not very clear. I guess what I really want to know is to incorporate the edge weight into the graph models, for example, could I use the edge weight to calculate the Pagerank? I can imagine different edge weights should come up with different Pagerank values, right?

User 512 | 2/3/2015, 4:39:50 PM

A related question to this, when calculating Pagerank, if there are five links between two nodes, will GraphLab treat the link as 1 or as 5?

User 1190 | 2/3/2015, 6:21:57 PM

The same link is independently treated 5 times.

User 92 | 2/3/2015, 6:38:10 PM

Hi Shuqing,

Regarding your previous question about how to incorporate the edge weight into the graph models -- the built-in graph model does not take that into account, but you can definitely leverage by creating your own graph model by leveraging triple-apply functionality we use. Take a look at the following document: