brainevent.jitnmm#
- brainevent.jitnmm = <NameScope(brainevent.jitnmm)>#
JIT normally-distributed matrix-matrix product.
Computes
W @ B(orW.T @ B) whereWis a random matrix with entries drawn fromNormal(w_loc, w_scale)masked by Bernoulli(prob), without materialisingW.- Parameters:
w_loc (scalar or Quantity) – Mean of the normal weight distribution.
w_scale (scalar or Quantity) – Standard deviation. Must share units with w_loc.
prob (float) – Connection probability in
[0, 1].B (jax.Array or Quantity) – Right-hand matrix of shape
(k, n)wherekequalsshape[0]when transpose isTrue, orshape[1]otherwise.seed (int or None, optional) – RNG seed.
Nonegenerates a random seed.shape (tuple of int) – Logical matrix shape
(n_pre, n_post).transpose (bool, optional) – If
True, multiply by the transpose. Default isFalse.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) – Compute backend.
- Returns:
Output matrix of shape
(shape[1], n)when transpose isTrue, or(shape[0], n)otherwise.- Return type:
jax.Array or Quantity
- Raises:
ValueError – If
probis not a scalar, is not finite, or is outside[0, 1].ValueError – If B is not 2-D or its leading dimension does not match the matrix shape.
Notes
The connectivity matrix
Wof shape(m, n)follows the model:W[i, j] = N(w_loc, w_scale) * B_mask[i, j]where
N(w_loc, w_scale)is a normal draw andB_mask[i, j] ~ Bernoulli(prob)is a binary mask, both determined byseed.The matrix-matrix product computes:
Y[i, c] = sum_{j=0}^{n-1} W[i, j] * B[j, c]When
transpose=True, the operation becomesY = W^T @ B:Y[j, c] = sum_{i=0}^{m-1} W[i, j] * B[i, c]The matrix
Wis never materialised; weights are generated and consumed on the fly.Examples
>>> import jax.numpy as jnp >>> from brainevent._jit_normal.float import jitnmm >>> B = jnp.ones((50, 10)) >>> Y = jitnmm(0.0, 1.0, 0.1, B, seed=42, shape=(100, 50)) >>> Y.shape (100, 10)