DataRepresentation#

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

Dict of all registered buffer names to their current values.

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:
  • NotImplementedError – On the abstract base; concrete subclasses must override.

  • UnsupportedOperationError – If the format cannot be reconstructed from a dense matrix (e.g. just-in-time connectivity).

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:
  • NotImplementedError – On the abstract base; concrete subclasses must override.

  • UnsupportedOperationError – If the format has no per-synapse plastic weight (e.g. just-in-time connectivity).

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:
  • NotImplementedError – On the abstract base; concrete subclasses must override.

  • UnsupportedOperationError – If the format has no per-synapse plastic weight (e.g. just-in-time connectivity).

See also

update_on_post

Post-spike-triggered counterpart.

yw_to_w_transposed(y_dim_arr, w_dim_arr)[source]#

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

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

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

  • w_dim_arr (jax.Array or brainunit.Quantity) – Per-synapse weights. Some formats (e.g. fixed-num connections) accept None here, defaulting to the representation’s own values.

Returns:

Per-synapse result.

Return type:

jax.Array or brainunit.Quantity

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

  • UnsupportedOperationError – If the format has no per-synapse weight (e.g. just-in-time connectivity).

See also

yw_to_w

y indexed by the row (pre) of W.