brainevent.update_csr_on_binary_pre

brainevent.update_csr_on_binary_pre#

brainevent.update_csr_on_binary_pre = <NameScope(brainevent.update_csr_on_binary_pre)>#

Update CSR synaptic weights triggered by presynaptic binary spike events.

Implements a spike-timing-dependent plasticity (STDP) rule for sparse connectivity matrices stored in Compressed Sparse Row (CSR) format. For each presynaptic neuron i that fires (pre_spike[i] is True or nonzero), the weights of all outgoing synapses from that neuron are updated by adding the corresponding postsynaptic trace values:

weight[indptr[i]:indptr[i+1]] += post_trace[indices[indptr[i]:indptr[i+1]]]

After the update, weights are optionally clipped to [w_min, w_max].

Parameters:
  • weight (Quantity | Array | Number) – Sparse synaptic weight array in CSR data format, with shape (nse,) where nse is the number of stored elements. May carry physical units via brainunit.Quantity.

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

  • indptr (ndarray | Array) – Row pointer array of the CSR format, with shape (n_pre + 1,) and integer dtype.

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

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

  • w_min (Quantity | Array | Number | None) – Lower bound for weight clipping. Must have the same units as weight. If None, no lower bound is applied.

  • w_max (Quantity | Array | Number | None) – Upper bound for weight clipping. Must have the same units as weight. If None, no upper bound is applied.

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

  • backend (str | None) – Compute backend to use. One of 'numba', 'pallas', or None for automatic selection.

Returns:

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

Return type:

jax.Array or Quantity

Raises:

AssertionError – If weight is not 1-D, if pre_spike is not 1-D, if post_trace is not 1-D, if shape[0] != pre_spike.shape[0], shape[1] != post_trace.shape[0], or if weight.shape[0] != indices.shape[0]. These checks are performed by the underlying csr_on_pre_prim_call().

See also

update_csr_on_binary_post

Post-synaptic-spike-triggered weight update.

update_csr_on_binary_pre_p

Low-level XLA custom kernel primitive for this operation.

Notes

This function implements the pre-synaptic component of an additive spike-timing-dependent plasticity (STDP) rule. In the standard pair-based STDP formulation the weight matrix W with shape (n_pre, n_post) is stored in CSR format. When presynaptic neuron j fires, the update for every synapse (i, j) that exists in the sparsity pattern is:

W[i, j] <- W[i, j] + post_trace[i]

After the additive update, weights are clipped element-wise:

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

Here post_trace is an eligibility trace that typically decays exponentially between postsynaptic spikes, so synapses that experienced a recent postsynaptic spike receive a larger update.

The function internally converts post_trace to the same unit as weight before performing arithmetic, so mixed-unit inputs are supported as long as the units are dimensionally compatible.

Examples

>>> import jax.numpy as jnp
>>> from brainevent._csr.plasticity_binary import update_csr_on_binary_pre
>>> weight = jnp.array([0.5, 0.3, 0.8, 0.2], dtype=jnp.float32)
>>> indices = jnp.array([0, 1, 0, 2], dtype=jnp.int32)
>>> indptr = jnp.array([0, 2, 4], dtype=jnp.int32)
>>> pre_spike = jnp.array([True, False])
>>> post_trace = jnp.array([0.1, 0.2, 0.05], dtype=jnp.float32)
>>> updated = update_csr_on_binary_pre(
...     weight, indices, indptr, pre_spike, post_trace,
...     shape=(2, 3),
... )