FixedNumPerPost#

class brainevent.FixedNumPerPost(data, indices=None, *, shape, backend=None, precompute_weight_indices=False, buffers=None)#

Sparse matrix with a fixed number of pre-synaptic connections per post-synaptic neuron (stores W^T row-major; structurally equivalent to brainevent.CSC).

data and indices have shape (num_post, num_conn); the equivalent dense matrix is W[indices[j, k], j] = data[j, k].

Examples

>>> import jax.numpy as jnp
>>> from brainevent import FixedNumPerPost
>>>
>>> data = jnp.array([[1., 2.], [3., 4.], [5., 6.]])
>>> indices = jnp.array([[0, 1], [1, 0], [0, 2]])
>>> mat = FixedNumPerPost(data, indices, shape=(3, 3))
>>> mat.shape
(3, 3)
classmethod fromdense(mat, *, num_conn=None, backend=None)[source]#

Construct from a dense matrix with a fixed number of connections per post.

Each post-synaptic column of mat is encoded with num_conn incoming connections (pre-synaptic ids).

Parameters:
  • mat (jax.Array or brainunit.Quantity) – Dense (num_pre, num_post) matrix. Explicit zeros are treated as absent connections.

  • num_conn (int, optional) – Connections per post-synaptic neuron. If None (default), inferred from the matrix, which must then have a uniform per-column non-zero count; otherwise short columns are padded with a zero-weight sentinel and a column with more non-zeros than num_conn raises ValueError.

  • backend (str, optional) – Backend tag forwarded to the constructor.

Returns:

Encoded fixed-connection matrix, shape equal to mat.shape.

Return type:

FixedNumPerPost

Raises:

ValueError – If mat is not 2-D, if per-column counts are non-uniform and num_conn is omitted, or if a column exceeds num_conn.

See also

tocsc

Inverse-direction conversion to CSC.

brainevent.CSC.fromdense

For irregular matrices.

slice_rows(index)[source]#

Return W[rows, :] as a CSR (outside jax.jit).

Selecting pre-synaptic rows breaks the fixed-per-post invariant (each post keeps a variable number of incoming pre), so the canonical row-major result is a CSR. Built from the cached CSR-of-W view; the output non-zero count is data-dependent, so index must be concrete.

Parameters:

index (int, list, tuple, array, or slice) – Row selector along axis 0 (pre-synaptic).

Returns:

Sparse sub-matrix of shape (len(rows), num_post).

Return type:

CSR

todense()[source]#

Convert to a dense matrix of shape (num_pre, num_post).

transpose(axes=None)[source]#

Transpose to a FixedNumPerPre (O(1); reinterprets indices).

Orientation flips, so the cached 'csc' mirror is not carried over; the new matrix rebuilds its own mirror lazily on first need.

Return type:

FixedNumPerPre

update_on_post(pre_trace, post_spike, w_min=None, w_max=None)[source]#

Post-spike STDP (favorable, row-driven) – mirrors brainevent.CSC.update_on_post().

update_on_pre(pre_spike, post_trace, w_min=None, w_max=None)[source]#

Pre-spike STDP (unfavorable) – mirrors brainevent.CSC.update_on_pre() (perm-fused).

with_data(data)[source]#

Return a new matrix with the same connectivity and replaced values.

Return type:

FixedNumPerPost