Geometrical queries
estimate_local_Lipschitz_constant(model, queries, device, stdv=0.01, n_samples=100, batch_size=5000)
Estimates the lipschitz constant near a point. This function samples points around the query points and returns the max of the gradient norm over the samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
the neural model to evaluate. |
required |
queries
|
ndarray
|
points at which the lipschitz constant needs to be evaluated |
required |
device
|
str
|
device onto which computations are performed. |
required |
stdv
|
float
|
standard deviation of the gaussian noise applied for sampling around query points. Standard deviation can be given as an array of size (queries.shape[0]) to specify different values for each query points. Defaults to 1e-2. |
0.01
|
n_samples
|
int
|
number of drawn samples for each query point. Defaults to 100. |
100
|
batch_size
|
int
|
batch size for parallel computation. Defaults to 5000. |
5000
|
Returns:
| Type | Description |
|---|---|
|
np.ndarray : a numpy array containing the value of the local Lipschitz constant at each query point. |
gradient_descent(query_pts, model, device='cpu', step_size=1.0, batch_size=1000, use_dist=False, normalize_grad=False, max_steps=100)
Performs steps of gradient descent of the given neural implicit function.
Given a point \(x\) and a neural implicit \(f\), this function will iterate: $\(x \leftarrow x - \nabla f(x)\)$
until max_steps is reached.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query_pts
|
ndarray
|
starting points. |
required |
model
|
Module
|
the neural implicit function. |
required |
device
|
str
|
device onto which the computation is performed. Defaults to "cpu". |
'cpu'
|
step_size
|
float
|
multiplicative parameter of the gradient at each step ("learning rate"). Defaults to 1.. |
1.0
|
batch_size
|
int
|
batch size for forward/backward computation on the neural implicit. Defaults to 1000. |
1000
|
use_dist
|
bool
|
whether to multiply the step by the value of the function at each point. Defaults to False. |
False
|
normalize_grad
|
bool
|
whether to normalize the neural implicit gradient at each steps. Defaults to False. |
False
|
max_steps
|
int
|
maximum number of steps. Defaults to 100. |
100
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: output points |
project_onto_iso(query_pts, model, iso=0.0, device='cpu', batch_size=1000, normalize_grad=False, max_steps=100, precision=1e-06)
Project the input points onto the nearest point of a given isosurface.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query_pts
|
ndarray
|
input point |
required |
model
|
Module
|
the neural implicit function. |
required |
iso
|
float
|
which isovalue the points should be projected to. Defaults to 0.. |
0.0
|
device
|
str
|
device onto which the computation is performed. Defaults to "cpu". |
'cpu'
|
batch_size
|
int
|
batch size for forward/backward computation on the neural implicit. Defaults to 1000. |
1000
|
normalize_grad
|
bool
|
whether to normalize the neural implicit gradient at each steps. Defaults to False. |
False
|
max_steps
|
int
|
maximum number of steps. Defaults to 100. |
100
|
precision
|
float
|
. Defaults to 1e-6. |
1e-06
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: the projected points |
sample_iso_projection(init_pts, model, iso=0.0, device='cpu', n_nearest=10, stdv=0.2, step_size=0.1, batch_size=1000, normalize_grad=False, max_steps=10)
Sample a neural implicit isosurface by projecting points onto it and make them repel themselves.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
init_pts
|
ndarray
|
initial points to be projected onto the isosurface. |
required |
model
|
Module
|
the neural implicit function. |
required |
iso
|
float
|
which isovalue the points should be projected to. Defaults to 0.. |
0.0
|
device
|
str
|
device onto which the computation is performed. Defaults to "cpu". |
'cpu'
|
n_nearest
|
int
|
number of nearest neighbors to consider for the repelling phase. Defaults to 10. |
10
|
stdv
|
float
|
standard deviation of the weights of near samples. Defaults to 0.2. |
0.2
|
step_size
|
float
|
multiplicative parameter of the gradient at each step ("learning rate"). Defaults to 1.. |
0.1
|
batch_size
|
int
|
batch size for forward/backward computation on the neural implicit. Defaults to 1000. |
1000
|
normalize_grad
|
bool
|
whether to normalize the neural implicit gradient at each steps. Defaults to False. |
False
|
max_steps
|
int
|
maximum number of steps. Defaults to 100. |
10
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: points sampled on the given isosurface. |
References
Iso-Points: Optimizing Neural Implicit Surfaces with Hybrid Representations, Yifan et al. (2021)
sample_iso_raytraced(model, n_rays, iso=0.0, device='cpu', threshold=0.0001, max_iter=1000)
Sample an isosurface of a neural implicit function by tracing rays intersecting the object and returning all ray-shape intersection points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
the neural implicit function. |
required |
n_rays
|
int
|
number of rays to sample. The number of sampled points is related to the number of rays |
required |
iso
|
float
|
description. Defaults to 0.. |
0.0
|
device
|
str
|
description. Defaults to "cpu". |
'cpu'
|
threshold
|
float
|
description. Defaults to 1e-4. |
0.0001
|
max_iter
|
int
|
description. Defaults to 1000. |
1000
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: sampled points |
References
- Uniform Sampling of Surfaces by Casting Rays, Ling et al., 2025
- https://github.com/iszihan/implicit-uniform-sampler/blob/main/ImplicitUniformSampler/sampler.py
sample_skeleton(model, res, device='cpu', batch_size=1000, margin=-0.01, grad_norm_threshold=0.5, descent_steps=0)
Samples the skeleton of a neural signed distance field. The skeleton of a shape is defined as the inside discontinuities of its distance field's gradient. This function works by sampling and rejecting points depending on the norm of the gradient at each point. If the neural implicit is well behaved (for instance, a 1-Lip SDF), then the discontinuities have low gradient.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
the neural implicit function. |
required |
res
|
int
|
resolution of the sampling. |
required |
device
|
str
|
device onto which the computation is performed. Defaults to "cpu". |
'cpu'
|
batch_size
|
int
|
batch size for forward/backward computation on the neural implicit. Defaults to 1000. |
1000
|
margin
|
float
|
the maximal value of the implicit function for a point to be considered inside the shape. Defaults to -1e-2. |
-0.01
|
grad_norm_threshold
|
float
|
the threshold for rejecting non-skeleton points. Defaults to 0.5. |
0.5
|
descent_steps
|
int
|
number of gradient descent step to perform on the sampled points to project them to the skeleton. Defaults to 0. |
0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: sampled points on the skeleton of the shape |