Input Encodings
Encodings are a fixed transformation applied to the input before being fed into a neural network
Usage
When defining a neural model, simply use a nn.Sequential object to add your encoding before your neural network. Note that the encoding size and the input dimension of the network should match.
model = torch.nn.Sequential(
RandomFourierEncoding(geometry,1000),
MultiLayerPerceptron(1000, 128, 4)
)
Available encodings
GaussianEncoding(geometry, n_points, sample_on_surface=True, stdv=1.0)
Bases: PointDistanceEncoding
Variant of the PointDistanceEncoding where distance are then fed into a Gaussian kernel:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geometry
|
Mesh
|
the input geometry. |
required |
n_points
|
int
|
number of considered points. |
required |
sample_on_surface
|
bool
|
whether to sample the points on the geometry's surface, or at random in space. Defaults to True. |
True
|
HalfPlaneEncoding(geometry, n_points)
Bases: Module
Encoding that considers points with normals sampled on the geometry and applies the signed distance to each corresponding hyperplanes:
where \((p,n)\) are points and normals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geometry
|
Mesh
|
the input geometry. |
required |
n_points
|
int
|
number of considered (point,normal) pairs. |
required |
PointDistanceEncoding(geometry, n_points, sample_on_surface=True)
Bases: Module
Encodes the input point x with its l2 distance to sampled points \(p\) in space:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geometry
|
Mesh
|
the input geometry. |
required |
n_points
|
int
|
number of considered points. |
required |
sample_on_surface
|
bool
|
whether to sample the points on the geometry's surface, or at random in space. Defaults to True. |
True
|
RandomFourierEncoding(input_dim, encoded_dim, stdv=1.0)
Bases: Module
Encodes a given position into different frequencies of trigonometric functions :
where \(b\) is sampled from a normal distribution of zero mean (and provided standard deviation)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_dim
|
int
|
dimension of the input points (usually 2 or 3). |
required |
encoded_dim
|
int
|
size of the final encoded vector. Should be an even number (as both sin and cos of every frequency is computed). the tensor |
required |
stdv
|
float
|
Standard variation of the normal distribution used to compute |
1.0
|
Raises:
| Type | Description |
|---|---|
ValueError
|
Fails if the encoding size is not an even number. |
References
- Fourier Features Let Networks Learn High Frequency Functions in Low Dimensional Domains, Tancik et al. (2020) : https://arxiv.org/abs/2006.10739
- https://github.com/jmclong/random-fourier-features-pytorch/tree/main