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^Trow-major; structurally equivalent tobrainevent.CSC).dataandindiceshave shape(num_post, num_conn); the equivalent dense matrix isW[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
matis encoded withnum_connincoming 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 thannum_connraisesValueError.backend (str, optional) – Backend tag forwarded to the constructor.
- Returns:
Encoded fixed-connection matrix,
shapeequal tomat.shape.- Return type:
- Raises:
ValueError – If
matis not 2-D, if per-column counts are non-uniform andnum_connis omitted, or if a column exceedsnum_conn.
See also
tocscInverse-direction conversion to CSC.
brainevent.CSC.fromdenseFor irregular matrices.
- slice_rows(index)[source]#
Return
W[rows, :]as aCSR(outsidejax.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-Wview; the output non-zero count is data-dependent, soindexmust be concrete.
- 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:
- 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).