scimba_torch.geometry.regularized_sdf_projectors

A module for learning regularized signed distance functions.

Functions

learn_regularized_sdf([points_file, ...])

Learn a SDF from either a file of points or a parametric hypersurface.

Classes

RegularizedSdfAnagram([points_file, ...])

The class for Regularized SDF projectors with Anagram.

RegularizedSdfEnergyNaturalGradient([...])

The class for Regularized SDF projectors with Energy Natural Gradient.

RegularizedSdfPinnsElliptic([points_file, ...])

The class for Regularized SDF projectors without preconditioning.

RegularizedSdfProjector([points_file, ...])

The abstract class for Regularized SDF projectors.

class RegularizedSdfProjector(points_file=None, parametric_hyper_surface=None, bounding_domain=None, **kwargs)[source]

Bases: ABC

The abstract class for Regularized SDF projectors.

SDF = Signed Distance Function

Parameters:
  • points_file (str | None) – A .txt file of points on the curve, default to None.

  • parametric_hyper_surface (ParametricHyperSurface | None) – a parametric HyperSurface, default to None. One among points_file, parametric_hyper_surface must be provided.

  • bounding_domain (VolumetricDomain | list[tuple[float, float]] | Tensor | None) – a bounding domain for the surface. Mandatory if parametric_hyper_surface is given.

  • **kwargs – arbitrary keyword arguments

Keyword Arguments:
  • architecture – the architecture of the NN to be used (default: GenericMLP).

  • layer_sizes – the size of the hidden layers (default: [10] * 4).

  • activation_type – the activation function (default: “sine”).

  • ...

class RegularizedSdfPinnsElliptic(points_file=None, parametric_hyper_surface=None, bounding_domain=None, **kwargs)[source]

Bases: RegularizedSdfProjector, PinnsElliptic

The class for Regularized SDF projectors without preconditioning.

SDF = Signed Distance Function

Parameters:
  • points_file (str | None) – A .txt file of points on the curve, default to None.

  • parametric_hyper_surface (ParametricHyperSurface | None) – a parametric HyperSurface, default to None. One among points_file, parametric_hyper_surface must be provided.

  • bounding_domain (VolumetricDomain | list[tuple[float, float]] | Tensor | None) – a bounding domain for the surface. Mandatory if parametric_hyper_surface is given.

  • **kwargs – arbitrary keyword arguments

Keyword Arguments:
  • architecture – the architecture of the NN to be used (default: GenericMLP).

  • layer_sizes – the size of the hidden layers (default: [10] * 4).

  • activation_type – the activation function (default: “sine”).

  • ...

class RegularizedSdfEnergyNaturalGradient(points_file=None, parametric_hyper_surface=None, bounding_domain=None, **kwargs)[source]

Bases: RegularizedSdfProjector, NaturalGradientPinnsElliptic

The class for Regularized SDF projectors with Energy Natural Gradient.

SDF = Signed Distance Function

Parameters:
  • points_file (str | None) – A .txt file of points on the curve, default to None.

  • parametric_hyper_surface (ParametricHyperSurface | None) – a parametric HyperSurface, default to None. One among points_file, parametric_hyper_surface must be provided.

  • bounding_domain (VolumetricDomain | list[tuple[float, float]] | Tensor | None) – a bounding domain for the surface. Mandatory if parametric_hyper_surface is given.

  • **kwargs – arbitrary keyword arguments

Keyword Arguments:
  • architecture – the architecture of the NN to be used (default: GenericMLP).

  • layer_sizes – the size of the hidden layers (default: [10] * 4).

  • activation_type – the activation function (default: “sine”).

Examples: Learn a SDF from a parametric hypersurface

import matplotlib.pyplot as plt

from scimba_torch.geometry.regularized_sdf_projectors import (
    RegularizedSdfEnergyNaturalGradient,
)
from scimba_torch.geometry.utils import (
    write_points_normals_to_file,
)
from scimba_torch.plots.plot_regularized_sdf_projector import (
    plot_regularized_sdf_projector,
)

bean_2d = ParametricHyperSurface.bean_2d()
bean_2d_bb = [(-0.4, 1.2), (-1.2, 0.4)]

points, normals = bean_2d.sample(2000)
write_points_normals_to_file(points, normals, "test.xy")

torch.manual_seed(0)

pinn = RegularizedSdfEnergyNaturalGradient(
    points_file="test.xy", layer_sizes=[10] * 4
)

new_training = True
if new_training or not pinn.load(__file__, "pinnsbean"):
    pinn.solve(
        epochs=400, n_collocation=4000, n_bc_collocation=2000, verbose=True
    )
    pinn.save(__file__, "pinnsbean")

plot_regularized_sdf_projector(
    pinn,
    n_visu=512,  # number of points for the visualization
    draw_contours=True,
    n_drawn_contours=20,
)

plt.show()
class RegularizedSdfAnagram(points_file=None, parametric_hyper_surface=None, bounding_domain=None, **kwargs)[source]

Bases: RegularizedSdfProjector, AnagramPinnsElliptic

The class for Regularized SDF projectors with Anagram.

SDF = Signed Distance Function

Parameters:
  • points_file (str | None) – A .txt file of points on the curve, default to None.

  • parametric_hyper_surface (ParametricHyperSurface | None) – a parametric HyperSurface, default to None. One among points_file, parametric_hyper_surface must be provided.

  • bounding_domain (VolumetricDomain | list[tuple[float, float]] | Tensor | None) – a bounding domain for the surface. Mandatory if parametric_hyper_surface is given.

  • **kwargs – arbitrary keyword arguments

Keyword Arguments:
  • architecture – the architecture of the NN to be used (default: GenericMLP).

  • layer_sizes – the size of the hidden layers (default: [10] * 4).

  • activation_type – the activation function (default: “sine”).

  • ...

learn_regularized_sdf(points_file=None, parametric_hyper_surface=None, bounding_domain=None, mode='new', load_from=None, save_to=None, **kwargs)[source]

Learn a SDF from either a file of points or a parametric hypersurface.

SDF = Signed Distance Function

Parameters:
  • points_file (str | None) – A .txt file of points on the curve, default to None.

  • parametric_hyper_surface (ParametricHyperSurface | None) – a parametric HyperSurface, default to None. One among points_file, parametric_hyper_surface must be provided.

  • bounding_domain (VolumetricDomain | list[tuple[float, float]] | Tensor | None) – a bounding domain for the surface. Mandatory if parametric_hyper_surface is given.

  • mode (str) – either “new” for new solving, “load” for loading from a file or “resume” for loading from a file and continue solving.

  • load_from (str | None) – the file from which loading the model.

  • save_to (str | None) – the file where saving the model.

  • **kwargs – arbitrary keyword arguments

Keyword Arguments:
  • architecture – the architecture of the NN to be used (default: GenericMLP).

  • layer_sizes – the size of the hidden layers (default: [10] * 4).

  • activation_type – the activation function (default: “sine”).

  • epochs – the number of optimization steps

  • n_collocation – the number of collocation points in the domain

  • n_bc_collocation – the number of collocation points on the contour

  • ...

Return type:

PinnsElliptic

Returns:

the PINN approximating the SDF

Raises:
  • NotImplementedError – the preconditioner is not known

  • ValueError – when loading file is not provided