brainevent.update_coo_on_binary_post

brainevent.update_coo_on_binary_post#

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

Update synaptic weights in COO format driven by postsynaptic spike events.

For each synapse i stored in COO format, if the postsynaptic neuron fires (post_spike[post_ids[i]] is nonzero), the weight is updated according to:

weight[i] = weight[i] + pre_trace[pre_ids[i]]

After the additive update, the result is clipped to [w_min, w_max] when the bounds are provided. Physical units attached to weight and pre_trace are handled transparently via brainunit.

Parameters:
  • weight (Quantity | Array) – Sparse synaptic weight values stored in COO format, shape (n_synapses,).

  • pre_ids (Array) – Presynaptic neuron index for every synapse, shape (n_synapses,).

  • post_ids (Array) – Postsynaptic neuron index for every synapse, shape (n_synapses,).

  • pre_trace (Quantity | Array) – Trace values accumulated at each presynaptic neuron, shape (n_pre,). Converted to the same unit as weight before the update.

  • post_spike (Array) – Binary or boolean array indicating which postsynaptic neurons fired, shape (n_post,). Non-boolean arrays are treated as active when the value is nonzero.

  • w_min (Quantity | Array | None) – Lower bound for weight clipping. Must carry the same unit as weight when units are used. Default is None (no lower bound).

  • w_max (Quantity | Array | None) – Upper bound for weight clipping. Must carry the same unit as weight when units are used. Default is None (no upper bound).

  • backend (str | None) – Compute backend to use for the underlying kernel. Accepted values depend on the platform (e.g., 'numba', 'pallas'). When None, the default backend for the current platform is used.

Returns:

Updated weight array with the same shape and unit as the input weight, after the additive plasticity update and optional clipping.

Return type:

jax.Array or brainunit.Quantity

Raises:

AssertionError – If weight, pre_ids, or post_ids do not all have matching 1-D shapes, or if pre_trace / post_spike are not 1-D.

See also

update_coo_on_binary_pre

Analogous update driven by presynaptic spikes.

update_coo_on_binary_post_p

Low-level XLA custom-kernel primitive used internally.

Notes

This operation is the post-synaptic half of a spike-timing-dependent plasticity (STDP) rule expressed in COO sparse format. In the standard pair-based STDP formulation, when postsynaptic neuron i fires the update for every synapse (i, j) that exists in the connectivity is:

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

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

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

Here pre_trace is an eligibility trace that typically decays exponentially between presynaptic spikes, so synapses whose presynaptic neuron fired recently receive a larger update.

In COO storage the loop iterates over every stored synapse index s: if post_spike[post_ids[s]] is active, then weight[s] += pre_trace[pre_ids[s]].

The kernel is dispatched through update_coo_on_binary_post_p, an XLACustomKernel instance that selects among Numba (CPU) and Pallas/Triton (GPU) implementations according to backend and the runtime platform.

Examples

>>> import jax.numpy as jnp
>>> from brainevent._coo.plasticity_binary import update_coo_on_binary_post
>>> weight = jnp.array([0.5, 0.3, 0.8])
>>> pre_ids = jnp.array([0, 1, 0])
>>> post_ids = jnp.array([1, 0, 2])
>>> pre_trace = jnp.array([0.1, 0.2])
>>> post_spike = jnp.array([True, False, True])
>>> new_w = update_coo_on_binary_post(
...     weight, pre_ids, post_ids, pre_trace, post_spike,
...     w_min=0.0, w_max=1.0,
... )