neuralop.losses.differentiation.non_uniform_fd

neuralop.losses.differentiation.non_uniform_fd(points, values, num_neighbors=5, derivative_indices=[0], radius=None, regularize_lstsq=False)[source]

Finite difference approximation of first order derivatives on unstructured point clouds.

Parameters:
pointstorch tensor of shape (N, d) containing the d coordinates of the N points
valuestorch tensor of shape (N) containing the values of the function at the N points
radiusfloat, the cutoff distance to use a neighbor as radius

Neighbors with distances beyond this value are not used (their weights are set to zero) Always keep at least 3 neighbors (including the point itself)

num_neighbors: int for the number of nearest neighbors to include in the stencil (including the point itself)
derivative_indicesindices of the derivatives to compute, e.g. in 2D, [0] for x, [1] for y, [0, 1] for x and y
regularize_lstsqbool, whether to regularize the least squares system

Sometimes torch.linalg.lstsq(A, b).solution creates artifacts so can add regularizer But regularizer can deteriorate performance when system is well-conditioned

Returns:
derivatives: tensor of shape (len(derivative_indices), N) of derivatives

e.g. in 2D with derivative_indices=[0, 1], derivatives[0] is df(x,y)/dx and derivatives[1] is df(x,y)/dy