Specifies a one-dimensional local connection between one or two population of neurons supporting multi-channel inputs with shape (C, H); The logic is different from the original LocalConnection implementation (where masks were used with normal dense connections).
| 1485 | |
| 1486 | |
| 1487 | class LocalConnection1D(AbstractConnection): |
| 1488 | """ |
| 1489 | Specifies a one-dimensional local connection between one or two population of neurons supporting multi-channel inputs with shape (C, H); |
| 1490 | The logic is different from the original LocalConnection implementation (where masks were used with normal dense connections). |
| 1491 | """ |
| 1492 | |
| 1493 | def __init__( |
| 1494 | self, |
| 1495 | source: Nodes, |
| 1496 | target: Nodes, |
| 1497 | kernel_size: int, |
| 1498 | stride: int, |
| 1499 | n_filters: int, |
| 1500 | nu: Optional[Union[float, Sequence[float], Sequence[torch.Tensor]]] = None, |
| 1501 | reduction: Optional[callable] = None, |
| 1502 | weight_decay: float = 0.0, |
| 1503 | w_dtype: torch.dtype = torch.float32, |
| 1504 | **kwargs, |
| 1505 | ) -> None: |
| 1506 | """ |
| 1507 | Instantiates a 'LocalConnection1D` object. Source population can be multi-channel. |
| 1508 | Neurons in the post-synaptic population are ordered by receptive field, i.e., |
| 1509 | if there are `n_conv` neurons in each post-synaptic patch, then the first |
| 1510 | `n_conv` neurons in the post-synaptic population correspond to the first |
| 1511 | receptive field, the second ``n_conv`` to the second receptive field, and so on. |
| 1512 | :param source: A layer of nodes from which the connection originates. |
| 1513 | :param target: A layer of nodes to which the connection connects. |
| 1514 | :param kernel_size: size of convolutional kernels. |
| 1515 | :param stride: stride for convolution. |
| 1516 | :param n_filters: Number of locally connected filters per pre-synaptic region. |
| 1517 | :param nu: Learning rate for both pre- and post-synaptic events. It also |
| 1518 | accepts a pair of tensors to individualize learning rates of each neuron. |
| 1519 | In this case, their shape should be the same size as the connection weights. |
| 1520 | :param reduction: Method for reducing parameter updates along the minibatch dimension. |
| 1521 | :param weight_decay: Constant multiple to decay weights by on each iteration. |
| 1522 | :param w_dtype: Data type for :code:`w` tensor |
| 1523 | Keyword arguments: |
| 1524 | :param LearningRule update_rule: Modifies connection parameters according to some rule. |
| 1525 | :param torch.Tensor w: Strengths of synapses. |
| 1526 | :param torch.Tensor b: Target population bias. |
| 1527 | :param float wmin: Minimum allowed value on the connection weights. |
| 1528 | :param float wmax: Maximum allowed value on the connection weights. |
| 1529 | :param float norm: Total weight per target neuron normalization constant. |
| 1530 | """ |
| 1531 | |
| 1532 | super().__init__(source, target, nu, reduction, weight_decay, **kwargs) |
| 1533 | |
| 1534 | self.kernel_size = kernel_size |
| 1535 | self.stride = stride |
| 1536 | self.n_filters = n_filters |
| 1537 | |
| 1538 | self.in_channels, input_height = (source.shape[0], source.shape[1]) |
| 1539 | |
| 1540 | height = int((input_height - self.kernel_size) / self.stride) + 1 |
| 1541 | |
| 1542 | self.conv_size = height |
| 1543 | |
| 1544 | w = kwargs.get("w", None) |