Hello,
I would like to test nSBM on bipartite graphs but before going on I need to be sure I'm able to build a bipartite graph in graphtool starting from a matrix: A_nodes = np.arange(data.shape[0]) #nodes for rows start from 0 B_nodes = np.arange(data.shape[1]) + data.shape[0] # nodes from columns start from the last A_node g = gt.Graph(directed=True) # directed or not directed... maybe not important at all g.add_vertex(len(A_nodes) + len(B_nodes)) #add all needed nodes partition = g.new_vertex_property('bool') # create a property indicating the node type for x in A_nodes: partition[g.vertex(x)] = 0 # set all A nodes to 0 for x in B_nodes: partition[g.vertex(x)] = 1 # set all B to 1 idx = np.nonzero(data) # take the edge values weights = adata.X[idx] idx = (idx[0], idx[1] + len(A_nodes)) # node number of columns need to be augmented by the offset g.add_edge_list(np.transpose(idx)) #add weights ew = g.new_edge_property("double") ew.a = weights g.ep['weight'] = ew Is there a more straightforward way to go? d _______________________________________________ graphtool mailing list [hidden email] https://lists.skewed.de/mailman/listinfo/graphtool 
Administrator

Am 20.03.20 um 11:22 schrieb Davide Cittaro:
> Hello, > I would like to test nSBM on bipartite graphs but before going on I need to be sure I'm able to build a bipartite graph in graphtool starting from a matrix: > > A_nodes = np.arange(data.shape[0]) #nodes for rows start from 0 > B_nodes = np.arange(data.shape[1]) + data.shape[0] # nodes from columns start from the last A_node > > g = gt.Graph(directed=True) # directed or not directed... maybe not important at all > g.add_vertex(len(A_nodes) + len(B_nodes)) #add all needed nodes > partition = g.new_vertex_property('bool') # create a property indicating the node type > > for x in A_nodes: > partition[g.vertex(x)] = 0 # set all A nodes to 0 > > for x in B_nodes: > partition[g.vertex(x)] = 1 # set all B to 1 > > idx = np.nonzero(data) # take the edge values > weights = adata.X[idx] > > idx = (idx[0], idx[1] + len(A_nodes)) # node number of columns need to be augmented by the offset > > g.add_edge_list(np.transpose(idx)) #add weights > > ew = g.new_edge_property("double") > ew.a = weights > g.ep['weight'] = ew > > Is there a more straightforward way to go? via the eprops parameter, but otherwise the above is fine. Note that if your objective is to do SBM inference, it's better to make the graph undirected. Best, Tiago  Tiago de Paula Peixoto <[hidden email]> _______________________________________________ graphtool mailing list [hidden email] https://lists.skewed.de/mailman/listinfo/graphtool signature.asc (849 bytes) Download Attachment

Tiago de Paula Peixoto <tiago@skewed.de> 
Hi
> On 23 Mar 2020, at 15:24, Tiago de Paula Peixoto <[hidden email]> wrote: > > You can add the weights together with the edges in Graph.add_edge_list() > via the eprops parameter, but otherwise the above is fine. > Ok > Note that if your objective is to do SBM inference, it's better to make > the graph undirected. > Why so? Is this true in general? d > Best, > Tiago _______________________________________________ graphtool mailing list [hidden email] https://lists.skewed.de/mailman/listinfo/graphtool 
Administrator

(Please answer to the mailing list, not directly
Am 23.03.20 um 15:31 schrieb Davide Cittaro: >> Note that if your objective is to do SBM inference, it's better to make >> the graph undirected. >> > > Why so? Is this true in general? Well, if you have a bipartite network where it is important do distinct the direction of the edges, then you should use a directed model. Otherwise the model should be undirected. I assumed from your formulation that in your scenario the direction is unimportant.  Tiago de Paula Peixoto <[hidden email]> _______________________________________________ graphtool mailing list [hidden email] https://lists.skewed.de/mailman/listinfo/graphtool signature.asc (849 bytes) Download Attachment

Tiago de Paula Peixoto <tiago@skewed.de> 
Free forum by Nabble  Edit this page 