Conv2dKernel#
- class braintools.conn.Conv2dKernel(kernel, kernel_size, threshold=0.0, allow_self_connections=False, weight=None, delay=None, **kwargs)#
Convolutional kernel connectivity for spatially arranged point neurons.
Applies a 2D convolution kernel to neuron positions, creating connections where the kernel weight magnitude exceeds a threshold. This allows implementing receptive field structures in spiking neural networks.
Only the first two position dimensions (x, y) are used; any extra columns (e.g. z) are ignored.
kernel_sizeis the physical support of the kernel along BOTH axes: the kernel rows are mapped onto the y extent and the kernel columns onto the x extent, each bounded independently so non-square kernels cover the correct neighbourhood.- Parameters:
kernel (
ndarray) – 2D convolution kernel array.kernel_size (
Array|ndarray|bool|number|bool|int|float|complex|Quantity) – Physical size of the kernel support (along both axes) in position units.threshold (
float) – Connection threshold - only kernel values whose magnitude exceeds this create connections. Thresholding on magnitude keeps essential negative coefficients (e.g. for edge-detection kernels). Default 0.0.allow_self_connections (
bool) – Whether a neuron may connect to itself when pre and post are the same population and coincide with the kernel centre (default: False).weight (
Initialization|float|int|ndarray|Array|Quantity|None) – Weight initialization (kernel values are multiplied by this).delay (
Initialization|float|int|ndarray|Array|Quantity|None) – Delay initialization.
Examples
>>> # Create 5x5 Gaussian-like kernel >>> kernel = np.array([ ... [0.04, 0.12, 0.18, 0.12, 0.04], ... [0.12, 0.37, 0.56, 0.37, 0.12], ... [0.18, 0.56, 1.00, 0.56, 0.18], ... [0.12, 0.37, 0.56, 0.37, 0.12], ... [0.04, 0.12, 0.18, 0.12, 0.04] ... ]) >>> positions = np.random.uniform(0, 1000, (500, 2)) * u.um >>> conn = Conv2dKernel( ... kernel=kernel, ... kernel_size=100 * u.um, ... threshold=0.1, ... weight=1.0 * u.nS ... ) >>> result = conn( ... pre_size=500, post_size=500, ... pre_positions=positions, post_positions=positions ... )