brainevent.binary_jitsmv#
- brainevent.binary_jitsmv = <NameScope(brainevent.binary_jitsmv)>#
Perform the \(y=M@v\) or \(y=M.T@v\) operation, where \(M\) is just-in-time randomly generated with a scalar weight at each position.
In this operation, \(M\) is the random matrix with a connection probability conn_prob, and at each connection the value is the same scalar weight.
When
transpose=True, we perform an operation of \(y=M^T@v\).Note
Note that the just-in-time generated \(M\) (transpose=False) is different from the generated \(M^T\) (transpose=True).
If you pursue the same \(M\) and \(M^T\) when performing the just-in-time matrix generation, you should set
corder=True, with the sacrifice of the speed compared withcorder=False.- Parameters:
weight (Array, ndarray, Quantity, float) – The value of the random matrix.
prob (float) – The connection probability.
vector (Array, ndarray, Quantity) – The vector.
seed (int) – The random number generation seed.
transpose (bool) – Transpose the random matrix or not.
corder (bool, default=True) – Which index owns a random stream.
True: one stream per output row, walked over the input (a gather, no atomics).False: one stream per input index, scattered into the output (zero inputs are skipped). The two values draw different matrices;transpose=True, corder=not cuses exactly the transpose of the matrix drawn bytranspose=False, corder=c.backend (str or None, optional) – The computation backend to use. If
None, the default backend is selected automatically.
- Returns:
out – The output of \(y = M @ v\) if
transpose=False, or the output of \(y = M^T @ v\) iftranspose=True.- Return type:
Array, ndarray, Quantity
- Raises:
ValueError – If
probis not a scalar, is not finite, or is outside[0, 1].AssertionError – If the matrix shape and vector length are incompatible.
See also
binary_jitsmmEvent-driven matrix-matrix multiplication with scalar weight.
jitsmvFloat matrix-vector multiplication with scalar weight.
Notes
This function computes an event-driven (spike-based) matrix-vector product where the connectivity matrix
Mhas the structure:M[i, j] = w * Bernoulli(prob)and the input
vectoris treated as a binary event vector (spikes). The output for each element is:y[i] = sum_{j in C(i)} w * spike[j]where
C(i)is the deterministic random connection set for rowi(determined by the seed), andspike[j]is 1 ifvector[j]isTrue(boolean) or non-zero (numeric; negative values and NaN are active).Since the input is binary, the operation reduces to counting the number of active (spiking) presynaptic neurons that connect to each postsynaptic neuron, then scaling by
w:y[i] = w * |{j in C(i) : spike[j] = 1}|The matrix is never materialized in memory. The connectivity pattern is regenerated on-the-fly from
seedandprob.Examples
>>> import jax.numpy as jnp >>> from brainevent._jit_scalar.binary import binary_jitsmv >>> weight = 0.5 >>> events = jnp.array([True, False, True, True, False]) >>> result = binary_jitsmv(weight, 0.5, events, seed=42, ... shape=(3, 5)) >>> result.shape # (3,)