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
ithat fires (pre_spike[i]isTrueor 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,)wherenseis the number of stored elements. May carry physical units viabrainunit.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,Trueindicates 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 withweight.w_min (
Quantity|Array|Number|None) – Lower bound for weight clipping. Must have the same units asweight. IfNone, no lower bound is applied.w_max (
Quantity|Array|Number|None) – Upper bound for weight clipping. Must have the same units asweight. IfNone, 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', orNonefor automatic selection.
- Returns:
Updated weight array with the same shape
(nse,)and units as the inputweight.- Return type:
jax.Array or Quantity
- Raises:
AssertionError – If
weightis not 1-D, ifpre_spikeis not 1-D, ifpost_traceis not 1-D, ifshape[0] != pre_spike.shape[0],shape[1] != post_trace.shape[0], or ifweight.shape[0] != indices.shape[0]. These checks are performed by the underlyingcsr_on_pre_prim_call().
See also
update_csr_on_binary_postPost-synaptic-spike-triggered weight update.
update_csr_on_binary_pre_pLow-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
Wwith shape(n_pre, n_post)is stored in CSR format. When presynaptic neuronjfires, 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_traceis 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_traceto the same unit asweightbefore 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), ... )