LaplacianKernel

LaplacianKernel#

class braintools.conn.LaplacianKernel(kernel_type='4-connected', kernel_size=1.0, allow_self_connections=False, weight=None, delay=None, **kwargs)#

Laplacian kernel for edge detection connectivity.

Implements Laplacian operators for detecting discontinuities and edges, useful for lateral inhibition and edge enhancement.

The Laplacian kernel has an essential negative centre coefficient (-4 or -8); connections are selected on coefficient magnitude so that centre weight is retained.

Parameters:
  • kernel_type (str) – Type of Laplacian (‘4-connected’, ‘8-connected’).

  • kernel_size (Array | ndarray | bool | number | bool | int | float | complex | Quantity) – Physical size of the kernel in position units.

  • allow_self_connections (bool) – Whether a neuron may connect to itself when pre and post are the same population (default: False). The Laplacian centre coefficient maps onto the self-connection, so enabling this retains the centre weight on the diagonal.

  • weight (Initialization | float | int | ndarray | Array | Quantity | None) – Weight initialization (Laplacian values are multiplied by this).

  • delay (Initialization | float | int | ndarray | Array | Quantity | None) – Delay initialization.

Notes

Candidate pairs are found with a k-d tree over the positions and handled in chunks of bounded size, so memory grows with the number of edges rather than with pre_size * post_size. The edges, their order and the weights are the same as in version 0.3 (up to rounding). Generation runs on the host with NumPy and cannot be traced by jax.jit, jax.vmap or jax.grad.

Examples

>>> import brainunit as u
>>> import numpy as np
>>> from braintools.conn import LaplacianKernel
>>> positions = np.random.RandomState(0).uniform(0, 1000, (500, 2)) * u.um
>>> laplacian = LaplacianKernel(
...     kernel_type='4-connected',
...     kernel_size=60 * u.um,
...     weight=1.0 * u.nS
... )
>>> result = laplacian(
...     pre_size=500, post_size=500,
...     pre_positions=positions, post_positions=positions
... )
>>> result.n_connections
634
generate(pre_size, post_size, pre_positions=None, post_positions=None, **kwargs)[source]#

Generate Laplacian kernel connections.

Return type:

ConnectionResult