class

LPPool1d

extendsModule
LPPool1d(norm_type: float, kernel_size: int, stride: int | None = None, ceil_mode: bool = False)
source

Applies 1-D power-average (Lp-norm) pooling over a sequence.

For each window of length kernel_size the module computes the p\ell^p norm of the absolute values of the elements:

y[n,c,i]=(k=0ks1x[n,c,is+k]p)1/py[n, c, i] = \left( \sum_{k=0}^{k_s - 1} \left|x[n,\, c,\, i \cdot s + k]\right|^p \right)^{1/p}

where pp = norm_type, ksk_s = kernel_size, and ss = stride.

Special cases:

  • p=1p = 1 — sum pooling (L1 norm over the window).
  • p=2p = 2 — square-root of sum of squares (L2 norm).
  • pp \to \infty — approaches max pooling.

Parameters

norm_typefloat
The exponent pp. Must be positive and finite.
kernel_sizeint
Size of the sliding window.
strideint or None= None
Step between windows. Defaults to kernel_size.
ceil_modebool= False
Use ceiling for output length. Default: False.

Attributes

norm_typefloat
kernel_sizeint
strideint
ceil_modebool

Notes

  • Input: (N, C, L_in)
  • Output: (N, C, L_out) where Lout=(Links)/s+1L_{out} = \lfloor (L_{in} - k_s) / s \rfloor + 1
  • Lp pooling is a power-mean generalisation: it smoothly interpolates between sum pooling (p=1p=1), energy pooling (p=2p=2), and max pooling (pp \to \infty).
  • Because the operation is differentiable for finite pp, 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, and sum — 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)
source

Initialise the LPPool1d module. See the class docstring for parameter semantics.

fn

forward

Tensor
forward(x: Tensor)
source

Apply the pooling operation to the input tensor.

Parameters

inputTensor
Input tensor of shape (N,C,)(N, C, *) where * are the spatial dimensions appropriate for this pooling layer.

Returns

Tensor

Pooled output tensor.

fn

extra_repr

str
extra_repr()
source

Return a string representation of the layer's configuration.