Skip to content
class

LPPool1d

extendsModule
LPPool1d(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 power average of the elements:

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

where pp = norm_type, ksk_s = kernel_size, and ss = stride. The power keeps the sign of xx; see lucid.nn.functional.lp_pool1d.

Special cases:

  • p=1p = 1 — sum pooling.
  • p=2p = 2 — square-root of sum of squares (L2 norm).
  • p=∞p = \infty — max pooling of ∣x∣|x|.

Parameters

norm_typefloat
The exponent pp. Must be positive; inf is allowed.
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=⌊(Lin−ks)/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 (p→∞p \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.

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)

Used by 1

Constructors

1
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.

Instance methods

2
fn

extra_repr

→str
extra_repr()

Return a string representation of the layer's configuration.

fn

forward

→Tensor
forward(input: Tensor)

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.