MaxPool1d

Contents

MaxPool1d#

class brainstate.nn.MaxPool1d(kernel_size, stride=None, padding='VALID', channel_axis=-1, return_indices=False, name=None, in_size=None)#

Applies a 1D max pooling over an input signal composed of several input planes.

In the simplest case, the output value of the layer with input size \((N, L, C)\) and output \((N, L_{out}, C)\) can be precisely described as:

\[out(N_i, k, C_j) = \max_{m=0, \ldots, \text{kernel\_size} - 1} input(N_i, stride \times k + m, C_j)\]

If padding is non-zero, then the input is implicitly padded with negative infinity on both sides for padding number of points. dilation is the stride between the elements within the sliding window. This link has a nice visualization of the pooling parameters.

Shape:
  • Input: \((N, L_{in}, C)\) or \((L_{in}, C)\).

  • Output: \((N, L_{out}, C)\) or \((L_{out}, C)\), where

    \[L_{out} = \left\lfloor \frac{L_{in} + 2 \times \text{padding} - \text{dilation} \times (\text{kernel\_size} - 1) - 1}{\text{stride}} + 1\right\rfloor\]
Parameters:
  • kernel_size (int | Sequence[int] | integer | Sequence[integer]) – An integer, or a sequence of integers defining the window to reduce over.

  • stride (int | Sequence[int]) – An integer, or a sequence of integers, representing the inter-window stride. Default: kernel_size

  • padding (str | int | Tuple[int, ...] | Sequence[Tuple[int, int]]) – Either the string ‘SAME’, the string ‘VALID’, or a sequence of n (low, high) integer pairs that give the padding to apply before and after each spatial dimension. Default: ‘VALID’

  • channel_axis (int | None) – Axis of the spatial channels for which pooling is skipped. If None, there is no channel axis. Default: -1

  • return_indices (bool) – If True, will return the max indices along with the outputs. Useful for MaxUnpool1d. Default: False

  • name (str | None) – The object name.

  • in_size (int | Sequence[int] | integer | Sequence[integer] | None) – The shape of the input tensor.

Examples

>>> import brainstate
>>> # pool of size=3, stride=2
>>> m = MaxPool1d(3, stride=2, channel_axis=-1)
>>> input = brainstate.random.randn(20, 50, 16)
>>> output = m(input)
>>> output.shape
(20, 24, 16)