Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.rst
#	rectipy/__init__.py
#	rectipy/utility.py
  • Loading branch information
Richert committed Apr 20, 2023
2 parents 7178965 + 6d24a09 commit b93d3f5
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions rectipy/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit b93d3f5

Please sign in to comment.