DenseGraph

experimental.network_dynamics.graph.DenseGraph(
    weights,
    region_labels=None,
    symmetric=None,
)

Dense graph representation.

Standard dense matrix representation of network topology. Suitable for most brain networks which are typically 50-90% dense.

Args: weights: Weight matrix [n_nodes, n_nodes] region_labels: Optional sequence of region labels (list, tuple, or array). If None, defaults to [‘Region_0’, ‘Region_1’, …] symmetric: Whether to treat as symmetric (None = auto-detect)

Attributes

Name Description
density Fraction of non-zero connections (excluding diagonal).
n_nodes Number of nodes in the network.
region_labels Labels for each node/region in the network.
symmetric Check if the graph is symmetric (undirected).
weights Weight matrix [n_nodes, n_nodes].

Methods

Name Description
gather_edges Flatten [target, source] values in target-major edge order.
plot Plot connectivity matrix and weight distribution.
random Create a random graph with brain-like connectivity.
tree_flatten Flatten Graph for JAX PyTree.
tree_unflatten Reconstruct Graph from PyTree data.
verify Verify graph structure and properties.

gather_edges

experimental.network_dynamics.graph.DenseGraph.gather_edges(graph_shaped)

Flatten [target, source] values in target-major edge order.

Dense graphs define every matrix cell as an edge, so their public edge order is simply row-major flattening: all sources for target 0, then all sources for target 1, and so on.

plot

experimental.network_dynamics.graph.DenseGraph.plot(
    log_scale_weights=False,
    figsize=(12, 5),
)

Plot connectivity matrix and weight distribution.

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

random

experimental.network_dynamics.graph.DenseGraph.random(
    n_nodes,
    density=1.0,
    symmetric=True,
    weight_dist='lognormal',
    allow_self_loops=False,
    key=None,
)

Create a random graph with brain-like connectivity.

Args: n_nodes: Number of nodes in the network density: Fraction of connections present (1.0 = fully connected, 0.3 = 30% dense) symmetric: Whether to create undirected (symmetric) connectivity weight_dist: Weight distribution (‘lognormal’, ‘uniform’, or ‘binary’) allow_self_loops: Whether to allow self-connections (diagonal) key: JAX random key (if None, creates one with seed 0)

Returns: DenseGraph with random connectivity

Example: >>> import jax >>> key = jax.random.key(42) >>> graph = DenseGraph.random(n_nodes=10, density=0.5, key=key)

tree_flatten

experimental.network_dynamics.graph.DenseGraph.tree_flatten()

Flatten Graph for JAX PyTree.

tree_unflatten

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

Reconstruct Graph from PyTree data.

verify

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

Verify graph structure and properties.

Checks: - Finite values in weight matrix - Consistent shape - Symmetric flag consistency (if provided)

Args: verbose: Whether to print verification details

Returns: True if verification passes, False otherwise