Skip to content

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:

\[x \mapsto e^{ - \frac{||x-p||^2}{\sigma}}\]

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:

\[x \mapsto \langle n, x-p \rangle\]

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:

\[x \mapsto ||x-p||_2\]

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 :

\[x \mapsto [\cos(2\pi b x), \sin(2 \pi b x)]\]

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 b will have shape (geometry.dim, dim_encoded//2)

required
stdv float

Standard variation of the normal distribution used to compute b. Defaults to 1..

1.0

Raises:

Type Description
ValueError

Fails if the encoding size is not an even number.

References