diff --git a/rectipy/utility.py b/rectipy/utility.py index ffdf7d8..047e10b 100644 --- a/rectipy/utility.py +++ b/rectipy/utility.py @@ -113,6 +113,43 @@ def circular_connectivity(N: int, p: float, spatial_distribution: rv_discrete, h return C +def line_connectivity(N: int, p: float, spatial_distribution: rv_discrete, homogeneous_weights: bool = True) -> np.ndarray: + """Generate a coupling matrix between nodes aligned on a circle. + + Parameters + ---------- + N + Number of nodes. + p + Connection probability. + spatial_distribution + Probability distribution defined over space. Will be used to draw indices of nodes from which each node in the + circular network receives inputs. + homogeneous_weights + + Returns + ------- + np.ndarray + 2D coupling matrix (N x N). + """ + C = np.zeros((N, N)) + n_conns = int(N*p) + for n in range(N): + idxs = spatial_distribution.rvs(size=n_conns) + signs = 1 * (bernoulli.rvs(p=0.5, loc=0, size=n_conns) > 0) + signs[signs == 0] = -1 + conns = n + idxs*signs + conns = conns[conns > 0] + conns = conns[conns < N] + conns_unique = np.unique(conns) + if homogeneous_weights: + C[n, conns_unique] = 1.0/len(conns_unique) + else: + for idx in conns_unique: + C[n, idx] = np.sum(conns == idx)/len(conns) + return C + + def random_connectivity(n: int, m: int, p: float, normalize: bool = True) -> np.ndarray: """Generate a random coupling matrix.