FixedNumPerPre#
- class brainevent.FixedNumPerPre(data, indices=None, *, shape, backend=None, precompute_weight_indices=False, buffers=None)#
Sparse matrix with a fixed number of post-synaptic connections per pre-synaptic neuron (row-major ELL; structurally equivalent to
brainevent.CSR).dataandindiceshave shape(num_pre, num_conn); the equivalent dense matrix isW[i, indices[i, k]] = data[i, k].Examples
>>> import jax.numpy as jnp >>> from brainevent import FixedNumPerPre >>> >>> data = jnp.array([[1., 2.], [3., 4.]]) >>> indices = jnp.array([[0, 1], [1, 2]]) >>> mat = FixedNumPerPre(data, indices, shape=(2, 3)) >>> mat.shape (2, 3)
- classmethod fromdense(mat, *, num_conn=None, backend=None)[source]#
Construct from a dense matrix with a fixed number of connections per pre.
Each pre-synaptic row of
matis encoded withnum_connoutgoing connections (post-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 pre-synaptic neuron. If
None(default), inferred from the matrix, which must then have a uniform per-row non-zero count; otherwise short rows are padded with a zero-weight sentinel and a row 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-row counts are non-uniform andnum_connis omitted, or if a row exceedsnum_conn.
See also
tocsrInverse-direction conversion to CSR.
brainevent.CSR.fromdenseFor irregular matrices.
- slice_rows(index)[source]#
Return
W[rows, :]as a newFixedNumPerPre.Selecting pre-synaptic rows preserves the fixed-connection invariant (each selected row keeps its
num_connentries), so this is a static gather and is safe underjax.jit.
- transpose(axes=None)[source]#
Transpose to a
FixedNumPerPost(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 (unfavorable) – mirrors
brainevent.CSR.update_on_post()(perm-fused).
- update_on_pre(pre_spike, post_trace, w_min=None, w_max=None)[source]#
Pre-spike STDP (favorable, row-driven) – mirrors
brainevent.CSR.update_on_pre().