Что делает аргумент «слабый» или «сильный» для scipy.sparse.csgraph.connected_components? - PullRequest
1 голос
/ 17 июня 2019

Приведенный ниже код демонстрирует, что ориентированный граф:

Nodes: 0, 1, 2
Edges: [0 -> 1], [2 -> 1]

считается одним слабосвязанным компонентом и тремя сильно связанными компонентами.

assert(scipy.sparse.csgraph.connected_components(np.array([[0,1,0], [0,0,0], [0,1,0]]), directed=True, connection='weak', return_labels=True) == (1, array([0, 0, 0], dtype=int32)))

assert(scipy.sparse.csgraph.connected_components(np.array([[0,1,0], [0,0,0], [0,1,0]]), directed=True, connection='strong', return_labels=True) == (3, array([1, 0, 2], dtype=int32)))

Я понимаю, почему сильноВозвращаемое значение подключенного компонента имеет смысл - я не могу перемещаться от 0 до 2, ни от 1 до 0, ни от 1 до 2.

Но в соответствии с документами:

directedbool, optional
    If True (default), then operate on a directed graph: only move
    from point i to point j along paths csgraph[i, j]. If False,
    then find the shortest path on an undirected graph: the
    algorithm can progress from point i to j along csgraph[i, j]
    or csgraph[j, i].

connectionstr, optional    
    [‘weak’|’strong’]. For directed graphs, the type of connection
    to use. Nodes i and j are strongly connected if a path exists
    both from i to j and from j to i. Nodes i and j are weakly
    connected if only one of these paths exists. If directed ==
    False, this keyword is not referenced.

The 'Компонент со слабой связью не должен существовать, потому что 2 не достижимо ни 1, ни 1 не достижимо 2.

Что здесь происходит?Документация правильная?

1 Ответ

1 голос
/ 17 июня 2019

Документация неверна и будет обновлена ​​в следующей версии Scipy.См. https://github.com/scipy/scipy/issues/9861

В будущей документации будет указано:

connection : str, optional
    ['weak'|'strong'].  For directed graphs, the type of connection to
    use.  Nodes i and j are strongly connected if a path exists both
    from i to j and from j to i. A directed graph is weakly connected
    if replacing all of its directed edges with undirected edges produces
    a connected (undirected) graph. If directed == False, this keyword
    is not referenced.

, что является стандартным определением для слабо подключенных.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...