SparseDelayGraph

experimental.network_dynamics.graph.SparseDelayGraph(
    weights,
    delays,
    region_labels=None,
    threshold=0.0,
)

Sparse graph with transmission delays.

Both weights and delays are stored as sparse BCOO matrices with the same sparsity pattern. Where weight is zero (no connection), delay is undefined.

Args: weights: Sparse weights (BCOO) or dense array delays: Sparse delays (BCOO) or dense array (same pattern as weights) region_labels: Optional sequence of region labels (list, tuple, or array). If None, defaults to [‘Region_0’, ‘Region_1’, …] threshold: Sparsity threshold for weights

Example: >>> # From dense >>> weights = jnp.array([[0, 0.5, 0], [0.3, 0, 0], [0, 0.2, 0]]) >>> delays = jnp.array([[0, 10.0, 0], [5.0, 0, 0], [0, 15.0, 0]]) >>> graph = SparseDelayGraph(weights, delays) >>> >>> # From dense delay graph >>> from network_dynamics.graph.base import DenseDelayGraph >>> dense_graph = DenseDelayGraph(weights, delays) >>> sparse_graph = SparseDelayGraph.from_dense(dense_graph, threshold=1e-10)

Attributes

Name Description
delays Sparse delay matrix in BCOO format (same pattern as weights).
max_delay Maximum delay across all connections.

Methods

Name Description
from_dense Convert dense delay graph to sparse.
plot Plot sparse connectivity matrix, delays, and their distributions.
random Create a random sparse delay graph with brain-like connectivity.
tree_flatten Flatten for JAX PyTree.
tree_unflatten Unflatten from JAX PyTree.
verify Verify graph structure and delays.

from_dense

experimental.network_dynamics.graph.SparseDelayGraph.from_dense(
    graph,
    threshold=1e-10,
)

Convert dense delay graph to sparse.

Applies the same sparsity pattern to both weights and delays.

Args: graph: Dense delay graph to convert threshold: Values with |weight| < threshold treated as zero

Returns: SparseDelayGraph with same connectivity pattern for weights and delays

plot

experimental.network_dynamics.graph.SparseDelayGraph.plot(
    log_scale_weights=False,
    figsize=(12, 10),
)

Plot sparse connectivity matrix, delays, and their distributions.

Args: log_scale_weights: If True, log-transform weights before plotting (helps reveal structure) figsize: Figure size (width, height)

Returns: fig, axes: Matplotlib figure and axes (2x2 grid)

Note: Converts sparse matrices to dense for visualization. Zeros are shown as white (background).

random

experimental.network_dynamics.graph.SparseDelayGraph.random(
    n_nodes,
    sparsity=0.7,
    symmetric=True,
    weight_dist='lognormal',
    max_delay=50.0,
    delay_dist='uniform',
    allow_self_loops=False,
    key=None,
)

Create a random sparse delay graph with brain-like connectivity.

Args: n_nodes: Number of nodes in the network sparsity: Fraction of connections present (0.7 = 70% dense) symmetric: Whether to create undirected (symmetric) connectivity weight_dist: Weight distribution (‘lognormal’, ‘uniform’, or ‘binary’) max_delay: Maximum transmission delay delay_dist: Delay distribution (‘uniform’ or ‘constant’) allow_self_loops: Whether to allow self-connections (diagonal) key: JAX random key (if None, creates one with seed 0)

Returns: SparseDelayGraph with random connectivity and delays

Example: >>> import jax >>> key = jax.random.key(42) >>> graph = SparseDelayGraph.random(n_nodes=100, sparsity=0.3, max_delay=20.0, key=key)

tree_flatten

experimental.network_dynamics.graph.SparseDelayGraph.tree_flatten()

Flatten for JAX PyTree.

tree_unflatten

experimental.network_dynamics.graph.SparseDelayGraph.tree_unflatten(
    aux_data,
    children,
)

Unflatten from JAX PyTree.

verify

experimental.network_dynamics.graph.SparseDelayGraph.verify(verbose=True)

Verify graph structure and delays.

Args: verbose: Whether to print verification details

Returns: True if verification passes, False otherwise