Shared.csgraph

Shared.csgraph(weight=None, respect_bounds: bool = True, backward_positive: bool = False, dtype=None) scipy.sparse.csr.csr_matrix[source]

Get the compressed sparse graph, shape (n, n).

A network/graph with n nodes can be represented by an node to node adjacency matrix H. If there is a connection from node i to node j, then H[i, j] = w, where w is the weight of the connection.

Parameters
weightndarray

Weight on network edges, shape (m, ).

respect_boundsbool, default=True

If True, an undirected edge from s to t with lb<0 and ub>0 will lead to separate entries in H. I.e., H[s, t] = w and H[t, s] = w.

backward_positivebool, default=False

Whether to negate weight for undirected edges if respect_bounds is True. I.e., H[s, t] = w and H[t, s] = -w.

dtypedtype, optional

Datatype of csgraph.

Returns
csr_matrix

Compressed sparse network graph.

Examples

SiouxFalls:

>>> import paminco
>>> net = paminco.net.load_sioux()
>>> H = net.shared.csgraph(np.arange(net.m) + 1)
>>> H[:5, :5].toarray()
array([[ 0.,  1.,  2.,  0.,  0.],
       [ 3.,  0.,  0.,  0.,  0.],
       [ 5.,  0.,  0.,  6.,  0.],
       [ 0.,  0.,  8.,  0.,  9.],
       [ 0.,  0.,  0., 11.,  0.]])