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 withshape = (n_pre, n_post), evaluatenew_e = rule(edge_state[e], pre_vals[i], post_vals[j], params)and return
new_ewhere postsynaptic neuronjis active and the unchangededge_state[e]elsewhere. The edge state stays in CSR data order: the post id of every edge isindices[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; seecsr_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).
- Returns:
The new edge state, with the structure of
edge_stateand leaves of the same shape and dtype.- Return type:
pytree
- Raises:
TypeError – If
rulereturns a pytree whose structure differs fromedge_state.ValueError – If a leaf has the wrong leading dimension, or
post_spike/indptrdo not matchshape.
See also
csr_apply_on_prePresynaptic-spike-triggered counterpart.
update_csr_on_binary_postFast event-driven kernel for the additive rule
w += pre_trace.CSR.apply_on_postMethod form on a
CSRmatrix.
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)