brainevent.jitsmv

Contents

brainevent.jitsmv#

brainevent.jitsmv = <NameScope(brainevent.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 with corder=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.

  • shape (tuple of int) – The matrix shape.

  • 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 c uses exactly the transpose of the matrix drawn by transpose=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\) if transpose=True.

Return type:

Array, ndarray, Quantity

Raises:
  • ValueError – If prob is not a scalar, is not finite, or is outside [0, 1].

  • AssertionError – If the matrix shape and vector length are incompatible.

See also

jits

Generate the full JIT scalar matrix as a dense array.

jitsmm

Matrix-matrix product with JIT-generated scalar matrix.

binary_jitsmv

Event-driven (binary) variant of this operation.

Notes

The operation computes:

y[i] = sum_{j in C(i)} w * v[j]

where w is the scalar weight, v is the input vector, and C(i) is the deterministic random connection set for row i (determined by the seed and connection probability). This is equivalent to y = M @ v where M[i, j] = w * Bernoulli(prob).

The weight w and vector v may carry physical units from brainunit; the output will have the product of their units.

Examples

>>> import jax.numpy as jnp
>>> from brainevent._jit_scalar.float import jitsmv
>>> v = jnp.ones(50)
>>> result = jitsmv(0.01, 0.1, v, seed=42, shape=(100, 50))
>>> result.shape  # (100,)