class
LPPool1d
extends
ModuleLPPool1d(norm_type: float, kernel_size: int, stride: int | None = None, ceil_mode: bool = False)Applies 1-D power-average (Lp-norm) pooling over a sequence.
For each window of length kernel_size the module computes the
norm of the absolute values of the elements:
where = norm_type, = kernel_size, and
= stride.
Special cases:
- — sum pooling (L1 norm over the window).
- — square-root of sum of squares (L2 norm).
- — approaches max pooling.
Parameters
norm_typefloatThe exponent . Must be positive and finite.
kernel_sizeintSize of the sliding window.
strideint or None= NoneStep between windows. Defaults to
kernel_size.ceil_modebool= FalseUse ceiling for output length. Default:
False.Attributes
norm_typefloatkernel_sizeintstrideintceil_modeboolNotes
- Input:
(N, C, L_in) - Output:
(N, C, L_out)where
- Lp pooling is a power-mean generalisation: it smoothly interpolates between sum pooling (), energy pooling (), and max pooling ().
- Because the operation is differentiable for finite , it can be used as a drop-in replacement for max or average pooling in gradient-based training.
- Implemented via engine primitives
unfold_dim,abs,pow_scalar, andsum— fully GPU-compatible.
Examples
L2 power pooling (energy pooling):
>>> import lucid
>>> import lucid.nn as nn
>>> pool = nn.LPPool1d(norm_type=2, kernel_size=4)
>>> x = lucid.ones((1, 8, 16))
>>> y = pool(x)
>>> y.shape
(1, 8, 4)
Sum pooling (p=1) with overlapping windows:
>>> pool = nn.LPPool1d(norm_type=1, kernel_size=3, stride=1)
>>> x = lucid.ones((2, 4, 12))
>>> y = pool(x)
>>> y.shape
(2, 4, 10)Methods (3)
dunder
__init__
→None__init__(norm_type: float, kernel_size: int, stride: int | None = None, ceil_mode: bool = False)Initialise the LPPool1d module. See the class docstring for parameter semantics.
fn
forward
→Tensorforward(x: Tensor)Apply the pooling operation to the input tensor.
Parameters
inputTensorInput tensor of shape where are the
spatial dimensions appropriate for this pooling layer.
Returns
TensorPooled output tensor.
fn
extra_repr
→strextra_repr()Return a string representation of the layer's configuration.