brainevent.update_csc_on_binary_pre

brainevent.update_csc_on_binary_pre#

brainevent.update_csc_on_binary_pre(weight, indices, indptr, pre_spike, post_trace, w_min=None, w_max=None, *, shape, backend=None)[source]#

Update CSC synaptic weights triggered by presynaptic binary spike events.

Implements the presynaptic component of additive spike-timing-dependent plasticity (STDP) for a weight matrix W of shape (n_pre, n_post) stored in Compressed Sparse Column (CSC) order. For each presynaptic neuron i that fires (pre_spike[i] is True or nonzero), every stored synapse (i, j) is updated:

W[i, j] <- clip(W[i, j] + post_trace[j], w_min, w_max)

This is the unfavorable direction for CSC (presynaptic spikes index the row axis, not the stored column axis). The function builds the row-major (CSR-like) view of the structure and a permutation perm mapping each row-major slot back to the canonical CSC weight order, then delegates to update_csr_on_binary_post(), which scatters the per-synapse updates back through perm.

Parameters:
  • weight (Quantity | Array | Number) – Sparse synaptic weight array in CSC data order, with shape (nse,). May carry physical units via brainunit.Quantity.

  • indices (ndarray | Array) – Row index array of the CSC format, with shape (nse,) and integer dtype.

  • indptr (ndarray | Array) – Column pointer array of the CSC format, with shape (n_post + 1,) and integer dtype.

  • pre_spike (Array) – Binary or boolean presynaptic spike array, with shape (n_pre,). Boolean True or any nonzero float indicates a spike.

  • post_trace (Quantity | Array) – Postsynaptic eligibility trace, with shape (n_post,). Must be unit-compatible with weight.

  • w_min (Quantity | Array | Number | None) – Lower/upper bounds for weight clipping (same units as weight). If None, the corresponding bound is not applied.

  • w_max (Quantity | Array | Number | None) – Lower/upper bounds for weight clipping (same units as weight). If None, the corresponding bound is not applied.

  • shape (Tuple[int, int]) – Full matrix shape (n_pre, n_post).

  • backend (str | None) – Compute backend forwarded to the underlying primitive.

Returns:

Updated weight array with the same shape (nse,) and units as the input weight, in canonical CSC order.

Return type:

jax.Array or Quantity

See also

update_csc_on_binary_post

Postsynaptic-spike-triggered CSC weight update.

update_csr_on_binary_post

The CSR primitive this reuses.

brainevent.csc_to_csr_index

Builds the CSR-like view and perm.

Examples

>>> import jax.numpy as jnp
>>> import brainevent
>>> W = jnp.array([[0.5, 0.0, 0.8],
...                [0.0, 0.3, 0.2]], dtype=jnp.float32)
>>> csc = brainevent.CSC.fromdense(W)
>>> pre_spike = jnp.array([True, False])
>>> post_trace = jnp.array([0.1, 0.2, 0.05], dtype=jnp.float32)
>>> new_w = brainevent.update_csc_on_binary_pre(
...     csc.data, csc.indices, csc.indptr, pre_spike, post_trace,
...     shape=csc.shape,
... )