netsiphd / netrd

A library for network {reconstruction, distances, dynamics}
https://netrd.readthedocs.io/en/latest/
MIT License
166 stars 43 forks source link

Portrait divergence: unclear if weighted graphs are supported #288

Closed sdmccabe closed 4 years ago

sdmccabe commented 4 years ago

PD converts to unweighted, then handles negative weights. The implication here is that it should support weights.

        G1 = ensure_unweighted(G1)
        G2 = ensure_unweighted(G2)

        adj1 = nx.to_numpy_array(G1)
        adj2 = nx.to_numpy_array(G2)

        ## NOTE dijkstra cannot handle negative weights
        if (adj1 < 0).any() or (adj2 < 0).any():
            adj1 = np.abs(adj1)
            adj2 = np.abs(adj2)
            G1 = nx.from_numpy_array(adj1)
            G2 = nx.from_numpy_array(adj2)
sdmccabe commented 4 years ago

The paper itself has an appendix on handling weighted graphs, and since the primary difference is using Dijkstra instead of BFS, I think this implementation should support weighted graphs.

leotrs commented 4 years ago

Let's support them

sdmccabe commented 4 years ago

Yeah, it should hopefully be an easy fix.