WeightedArray#
- class brainevent.WeightedArray(value)#
Array wrapper for value-weighted (count or graded) events.
WeightedArrayrepresents a mostly-zero array whose non-zero entries carry a value, for example the number of spikes a neuron emitted in one step. Matrix multiplication with@is exact (x @ W) but only visits rows/columns where the event is non-zero.- Parameters:
value (array_like) – Event values. Integer (
int8,uint8,int16,int32) or floating-point dtypes; signed values are allowed. Boolean arrays are accepted and behave likeBinaryArray.
See also
BinaryArrayBinary events (the value is not used).
Notes
Given an event vector
xof shape(k,)and a weight matrixWof shape(k, n),x @ Wcomputesy[j] = sum_{i : x[i] != 0} x[i] * W[i, j]
Unlike
BinaryArray, the value is not binarised, and the derivatives are exact:d y / d W[i, j] = x[i];d y / d x[i] = W[i, :](integer events getfloat0cotangents).
WeightedArrayis not a subclass ofBinaryArray.Examples
>>> import jax.numpy as jnp >>> import brainevent as be >>> counts = be.WeightedArray(jnp.array([0, 2, 1], dtype=jnp.int8)) >>> W = jnp.array([[1., 2.], [3., 4.], [5., 6.]]) >>> counts @ W Array([11., 14.], dtype=float32)
- property T#
Transpose of the underlying array.
- Returns:
The transposed raw array (not wrapped in
WeightedArray).- Return type:
jax.Array
- transpose(*axes)[source]#
Return the underlying array with axes permuted.
- Parameters:
*axes (int, optional) – Axis permutation. If omitted, reverses the axis order.
- Returns:
The transposed raw array (not wrapped in
WeightedArray).- Return type:
jax.Array
- tree_flatten()[source]#
Flatten this instance for JAX PyTree serialisation.
- Returns:
children (tuple) –
(value,).aux_data (dict) – Empty dictionary (no static metadata).