Population Recurrence
- driada.recurrence.population.population_recurrence_graph(recurrence_graphs, method='joint', threshold=1.0, binarize_threshold=None)[source]
Combine per-neuron recurrence graphs into a population graph.
- Parameters:
recurrence_graphs (list of RecurrenceGraph) – Individual recurrence graphs. All must have the same number of nodes.
method ({'joint', 'mean'}) –
Combination strategy: - ‘joint’: Thresholded element-wise AND (JRP). A point (i,j) is kept
if at least
thresholdfraction of neurons recur there. threshold=1.0 is strict AND, threshold=0.5 is majority voting.’mean’: Average recurrence matrices. Values in [0, 1]. Optionally binarize with
binarize_threshold.
threshold (float, default=1.0) – For method=’joint’: fraction of neurons that must recur.
binarize_threshold (float, optional) – For method=’mean’: if given, binarize the averaged matrix.
- Returns:
Population-level recurrence graph (via from_adjacency).
- Return type:
- Raises:
ValueError – If graphs have different sizes or method is unknown.
- driada.recurrence.population.pairwise_jaccard_sparse(matrices, trim_to_min=False)[source]
Compute pairwise Jaccard similarity for sparse binary matrices.
Uses sparse matrix multiplication to compute all pairwise intersection counts in a single operation, avoiding O(N²) Python loops.
- Parameters:
matrices (list of scipy.sparse matrices or RecurrenceGraph objects) – Square binary adjacency matrices. RecurrenceGraph objects are accepted (uses
.adj).trim_to_min (bool, default=False) – If True, matrices with different sizes (e.g., from per-neuron embeddings with different tau/dim) are trimmed to the smallest common size before comparison. If False (default), different sizes raise ValueError.
- Returns:
Symmetric matrix of Jaccard indices. Diagonal is 1.0 for non-empty matrices, 0.0 for empty ones.
- Return type:
ndarray of shape (N, N)
- Raises:
ValueError – If list is empty, or if matrices have different shapes and trim_to_min is False.