brainevent.csr_apply_on_post

brainevent.csr_apply_on_post#

brainevent.csr_apply_on_post(rule, edge_state, indices, indptr, post_spike, *, pre_vals=None, post_vals=None, params=None, shape)[source]#

Apply a per-edge plasticity rule to the edges of active postsynaptic neurons.

For every stored edge e = (i, j) of a CSR matrix with shape = (n_pre, n_post), evaluate

new_e = rule(edge_state[e], pre_vals[i], post_vals[j], params)

and return new_e where postsynaptic neuron j is active and the unchanged edge_state[e] elsewhere. The edge state stays in CSR data order: the post id of every edge is indices[e], so no CSC permutation is needed.

Parameters:
  • rule (Callable[[Any, Any, Any, Any], Any]) – rule(edge_e, pre_e, post_e, params) -> new_edge_e; see csr_apply_on_pre().

  • edge_state (pytree) – Per-edge state in CSR data order; every leaf has leading dimension nse.

  • indices (jax.Array) – CSR column indices, shape (nse,).

  • indptr (jax.Array) – CSR row pointers, shape (n_pre + 1,).

  • post_spike (Array) – Postsynaptic spikes (bool or numeric), shape (n_post,).

  • pre_vals (pytree or None, optional) – Per-presynaptic-neuron values (leading dimension n_pre).

  • post_vals (pytree or None, optional) – Per-postsynaptic-neuron values (leading dimension n_post).

  • params (pytree or None, optional) – Rule parameters, broadcast to every edge (differentiable).

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

Returns:

The new edge state, with the structure of edge_state and leaves of the same shape and dtype.

Return type:

pytree

Raises:
  • TypeError – If rule returns a pytree whose structure differs from edge_state.

  • ValueError – If a leaf has the wrong leading dimension, or post_spike / indptr do not match shape.

See also

csr_apply_on_pre

Presynaptic-spike-triggered counterpart.

update_csr_on_binary_post

Fast event-driven kernel for the additive rule w += pre_trace.

CSR.apply_on_post

Method form on a CSR matrix.

Notes

Cost and gradient behaviour are as in csr_apply_on_pre().

Examples

>>> import jax.numpy as jnp
>>> import brainevent
>>> csr = brainevent.CSR.fromdense(jnp.array([[1., 0.5], [0., 2.]]))
>>> def depress(w, pre, post, lr):
...     return w - lr * w * pre
>>> brainevent.csr_apply_on_post(
...     depress, csr.data, csr.indices, csr.indptr, jnp.array([0., 1.]),
...     pre_vals=jnp.array([1., 0.5]), params=0.1, shape=csr.shape,
... )
Array([1.  , 0.45, 1.9 ], dtype=float32)