DataRepresentation#

class brainevent.DataRepresentation(*args, shape, buffers=None)[source]#
property buffers#

Dict of all registered buffer names to their current values.

dt2t(y_dim_arr, w_dim_arr)[source]#

Per-synapse w * y with y indexed by the row (pre) of W.

Part of the per-synapse eligibility protocol used by brainscale. Concrete subclasses implement this directly when their storage can produce one value per represented synapse.

Parameters:
  • y_dim_arr (Array | ndarray | Quantity) – Pre-synaptic (row) vector, sized shape[0].

  • w_dim_arr (Array | ndarray | Quantity) – Per-synapse weights.

Returns:

Per-synapse result.

Return type:

Array | Quantity

Raises:

See also

dt2t_transposed

y indexed by the column (post) of W.

Notes

This is the protocol for the \(\mathbf{D}^{t}\boldsymbol{\epsilon}^{t-1}\) term of the D-RTRL (diagonal real-time recurrent learning) sensitivity update rule

\[\boldsymbol{\epsilon}^{t} \approx \mathbf{D}^{t}\boldsymbol{\epsilon}^{t-1} + \mathrm{diag}(\mathbf{D}_{f}^{t}) \otimes \mathbf{x}^{t}\]

w_dim_arr supplies the per-synapse entries of the Jacobian \(\mathbf{D}^{t}\) and y_dim_arr supplies the previous-step eligibility trace \(\boldsymbol{\epsilon}^{t-1}\); the \(\mathrm{diag}(\mathbf{D}_{f}^{t}) \otimes \mathbf{x}^{t}\) term is accumulated separately by the caller (brainscale).

dt2t_transposed(y_dim_arr, w_dim_arr)[source]#

Per-synapse w * y with y indexed by the column (post) of W.

Adjoint counterpart of dt2t(). Part of the per-synapse eligibility protocol used by brainscale.

Parameters:
  • y_dim_arr (Array | ndarray | Quantity) – Post-synaptic (column) vector, sized shape[1].

  • w_dim_arr (Array | ndarray | Quantity) – Per-synapse weights.

Returns:

Per-synapse result.

Return type:

Array | Quantity

Raises:

See also

dt2t

y indexed by the row (pre) of W.

Notes

Adjoint counterpart of the \(\mathbf{D}^{t}\boldsymbol{\epsilon}^{t-1}\) protocol documented on dt2t() — see there for the full D-RTRL update-rule context.

classmethod fromdense(*args, **kwargs)[source]#

Construct a representation from a dense matrix.

The concrete signature is defined per family; every subclass takes the dense matrix as the first positional argument followed by format-specific keyword options. A permissive *args, **kwargs is used here so each subclass can declare its own parameters without violating the Liskov substitution principle.

Parameters:
  • dense (jax.Array or brainunit.Quantity) – Dense (num_pre, num_post) matrix to encode.

  • **kwargs – Format-specific options (e.g. num_conn for fixed-num connections, nse for compressed-sparse formats).

Returns:

A new instance of cls encoding dense.

Return type:

DataRepresentation

Raises:
register_buffer(name, value=None)[source]#

Register a named buffer with a default value.

set_buffer(name, value)[source]#

Update the value of a previously registered buffer.

tocoo()[source]#

Convert to coordinate (COO) format.

Returns:

The same logical matrix in COO format, shape unchanged.

Return type:

brainunit.sparse.COO

Raises:

NotImplementedError – On the abstract base; concrete subclasses must override.

See also

tocsr

Convert to compressed sparse row format.

tocsc

Convert to compressed sparse column format.

tocsc()[source]#

Convert to Compressed Sparse Column (CSC) format.

Returns:

The same logical matrix in CSC format, shape unchanged.

Return type:

CSC

Raises:

NotImplementedError – On the abstract base; concrete subclasses must override.

See also

tocsr

Convert to compressed sparse row format.

tocoo

Convert to coordinate format.

tocsr()[source]#

Convert to Compressed Sparse Row (CSR) format.

Returns:

The same logical matrix in CSR format, shape unchanged.

Return type:

CSR

Raises:

NotImplementedError – On the abstract base; concrete subclasses must override.

See also

tocsc

Convert to compressed sparse column format.

tocoo

Convert to coordinate format.

update_on_post(pre_trace, post_spike, w_min=None, w_max=None)[source]#

Apply a post-spike-triggered STDP update, returning a new matrix.

Parameters:
  • pre_trace (jax.Array or brainunit.Quantity) – Pre-synaptic trace, shape (shape[0],).

  • post_spike (jax.Array) – Post-synaptic spikes, shape (shape[1],).

  • w_min (jax.Array, brainunit.Quantity, number, or None, optional) – Clip bounds; None disables the corresponding bound.

  • w_max (jax.Array, brainunit.Quantity, number, or None, optional) – Clip bounds; None disables the corresponding bound.

Returns:

A new matrix with updated values and identical structure.

Return type:

DataRepresentation

Raises:

See also

update_on_pre

Pre-spike-triggered counterpart.

update_on_pre(pre_spike, post_trace, w_min=None, w_max=None)[source]#

Apply a pre-spike-triggered STDP update, returning a new matrix.

Parameters:
  • pre_spike (jax.Array) – Pre-synaptic spikes, shape (shape[0],).

  • post_trace (jax.Array or brainunit.Quantity) – Post-synaptic trace, shape (shape[1],).

  • w_min (jax.Array, brainunit.Quantity, number, or None, optional) – Clip bounds; None disables the corresponding bound.

  • w_max (jax.Array, brainunit.Quantity, number, or None, optional) – Clip bounds; None disables the corresponding bound.

Returns:

A new matrix with updated values and identical structure.

Return type:

DataRepresentation

Raises:

See also

update_on_post

Post-spike-triggered counterpart.

yw_to_w(y_dim_arr, w_dim_arr)[source]#

Deprecated alias for dt2t().

Deprecated since version Use: dt2t() instead. Will be removed in a future release.

Parameters:
  • y_dim_arr (Array | ndarray | Quantity) – Pre-synaptic (row) vector, sized shape[0].

  • w_dim_arr (Array | ndarray | Quantity) – Per-synapse weights.

Returns:

Per-synapse result; see dt2t().

Return type:

Array | Quantity

See also

dt2t

Replacement for this method.

yw_to_w_transposed(y_dim_arr, w_dim_arr)[source]#

Deprecated alias for dt2t_transposed().

Deprecated since version Use: dt2t_transposed() instead. Will be removed in a future release.

Parameters:
  • y_dim_arr (Array | ndarray | Quantity) – Post-synaptic (column) vector, sized shape[1].

  • w_dim_arr (Array | ndarray | Quantity) – Per-synapse weights.

Returns:

Per-synapse result; see dt2t_transposed().

Return type:

Array | Quantity

See also

dt2t_transposed

Replacement for this method.