Ejemplo n.º 1
0
    def test_panther_similarity_weighted(self):
        numpy.random.seed(42)

        G = nx.Graph()
        G.add_edge("v1", "v2", weight=5)
        G.add_edge("v1", "v3", weight=1)
        G.add_edge("v1", "v4", weight=2)
        G.add_edge("v2", "v3", weight=0.1)
        G.add_edge("v3", "v5", weight=1)
        expected = {"v3": 0.75, "v4": 0.5, "v2": 0.5, "v5": 0.25}
        sim = nx.panther_similarity(G, "v1", path_length=2)
        assert sim == expected
Ejemplo n.º 2
0
    def test_panther_similarity_unweighted(self):
        numpy.random.seed(42)

        G = nx.Graph()
        G.add_edge(0, 1)
        G.add_edge(0, 2)
        G.add_edge(0, 3)
        G.add_edge(1, 2)
        G.add_edge(2, 4)
        expected = {3: 0.5, 2: 0.5, 1: 0.5, 4: 0.125}
        sim = nx.panther_similarity(G, 0, path_length=2)
        assert sim == expected