CustomKernel

CustomKernel#

class braintools.conn.CustomKernel(kernel_func, kernel_size, threshold=0.0, weight=None, delay=None, **kwargs)#

Custom kernel connectivity using user-defined kernel function.

Allows implementing arbitrary spatial kernel functions for connectivity.

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 (default: 0.0).

  • 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

>>> 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.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
... )
generate(**kwargs)[source]#

Generate custom kernel connections.

Return type:

ConnectionResult