CustomKernel#
- class braintools.conn.CustomKernel(kernel_func, kernel_size, threshold=0.0, allow_self_connections=False, weight=None, delay=None, **kwargs)#
Custom kernel connectivity using user-defined kernel function.
Allows implementing arbitrary spatial kernel functions for connectivity.
Only the first two position dimensions (x, y) are used; any extra columns (e.g. z) are ignored.
- Parameters:
kernel_func (
Callable) – Function that takes (x, y) coordinates and returns kernel value. Should accept arrays and return array of same shape.kernel_size (
Array|ndarray|bool|number|bool|int|float|complex|Quantity) – Physical size of the kernel support in position units.threshold (
float) – Connection threshold on kernel-value magnitude (default: 0.0).allow_self_connections (
bool) – Whether a neuron may connect to itself when pre and post are the same population (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.
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 byjax.jit,jax.vmaporjax.grad.Examples
>>> import brainunit as u >>> import numpy as np >>> from braintools.conn import CustomKernel >>> def my_kernel(x, y): ... # Custom kernel function ... r = np.sqrt(x**2 + y**2) ... return np.exp(-r/50) * np.cos(r/10) >>> >>> positions = np.random.RandomState(0).uniform(0, 1000, (500, 2)) * u.um >>> custom = CustomKernel( ... kernel_func=my_kernel, ... kernel_size=200 * u.um, ... threshold=0.1, ... weight=1.0 * u.nS ... ) >>> result = custom( ... pre_size=500, post_size=500, ... pre_positions=positions, post_positions=positions ... ) >>> result.n_connections 5648