Layers
- class rff.layers.BasicEncoding
Layer for mapping coordinates using the basic encoding
Initializes internal Module state, shared by both nn.Module and ScriptModule.
- forward(v: Tensor) Tensor
Computes \(\gamma(\mathbf{v}) = (\cos{2 \pi \mathbf{v}} , \sin{2 \pi \mathbf{v}})\)
- Parameters
v (Tensor) – input tensor of shape \((N, *, \text{input_size})\)
- Returns
mapped tensor of shape \((N, *, 2 \cdot \text{input_size})\)
- Return type
Tensor
- class rff.layers.GaussianEncoding(sigma: Optional[float] = None, input_size: Optional[float] = None, encoded_size: Optional[float] = None, b: Optional[Tensor] = None)
Layer for mapping coordinates using random Fourier features
- Parameters
sigma (Optional[float]) – standard deviation
input_size (Optional[float]) – the number of input dimensions
encoded_size (Optional[float]) – the number of dimensions the b matrix maps to
b (Optional[Tensor], optional) – Optionally specify a
bmatrix already sampled
- Raises
ValueError – If
bis provided and one ofsigma,input_size, orencoded_sizeis provided. Ifbis not provided and one ofsigma,input_size, orencoded_sizeis not provided.
- forward(v: Tensor) Tensor
Computes \(\gamma(\mathbf{v}) = (\cos{2 \pi \mathbf{B} \mathbf{v}} , \sin{2 \pi \mathbf{B} \mathbf{v}})\)
- Parameters
v (Tensor) – input tensor of shape \((N, *, \text{input_size})\)
- Returns
Tensor mapping using random fourier features of shape \((N, *, 2 \cdot \text{encoded_size})\)
- Return type
Tensor
- class rff.layers.PositionalEncoding(sigma: float, m: int)
Layer for mapping coordinates using the positional encoding
- Parameters
sigma (float) – frequency constant
m (int) – number of frequencies to map to
- forward(v: Tensor) Tensor
Computes \(\gamma(\mathbf{v}) = (\dots, \cos{2 \pi \sigma^{(j/m)} \mathbf{v}} , \sin{2 \pi \sigma^{(j/m)} \mathbf{v}}, \dots)\)
- Parameters
v (Tensor) – input tensor of shape \((N, *, \text{input_size})\)
- Returns
mapped tensor of shape \((N, *, 2 \cdot m \cdot \text{input_size})\)
- Return type
Tensor