neuralop.losses.H1Loss

class neuralop.losses.H1Loss(d=1, measure=1.0, reduction='sum', fix_x_bnd=False, fix_y_bnd=False, fix_z_bnd=False)[source]

H1Loss provides the H1 Sobolev norm between two d-dimensional discretized functions.

Note

In function space, the Sobolev norm is an integral over the entire domain. To ensure the norm converges to the integral, we scale the matrix norm by quadrature weights along each spatial dimension.

If no quadrature is passed at a call to H1Loss, we assume a regular discretization and take 1 / measure as the quadrature weights.

Parameters:
dint, optional

dimension of input functions, by default 1

measurefloat or list, optional

measure of the domain, by default 1.0 either single scalar for each dim, or one per dim

To perform quadrature, H1Loss scales measure by the size of each spatial dimension of x, and multiplies them with ||x-y||, such that the final norm is a scaled average over the spatial dimensions of x.

reductionstr, optional

whether to reduce across the batch and channel dimension by summing (‘sum’) or averaging (‘mean’)

fix_x_bndbool, optional

whether to fix finite difference derivative computation on the x boundary, by default False

fix_y_bndbool, optional

whether to fix finite difference derivative computation on the y boundary, by default False

fix_z_bndbool, optional

whether to fix finite difference derivative computation on the z boundary, by default False

Attributes:
name

Methods

__call__(y_pred, y[, quadrature])

abs(x, y[, quadrature])

absolute H1 norm

compute_terms(x, y, quadrature)

compute_terms computes the necessary finite-difference derivative terms for computing the H1 norm

reduce_all(x)

reduce x across the batch according to self.reduction

rel(x, y[, quadrature])

relative H1-norm

uniform_quadrature(x)

uniform_quadrature creates quadrature weights scaled by the spatial size of x to ensure that LpLoss computes the average over spatial dims.

compute_terms(x, y, quadrature)[source]

compute_terms computes the necessary finite-difference derivative terms for computing the H1 norm

Parameters:
xtorch.Tensor

inputs

ytorch.Tensor

targets

quadratureint or list

quadrature weights

uniform_quadrature(x)[source]

uniform_quadrature creates quadrature weights scaled by the spatial size of x to ensure that LpLoss computes the average over spatial dims.

Parameters:
xtorch.Tensor

input data

Returns:
quadraturelist

list of quadrature weights per-dim

reduce_all(x)[source]

reduce x across the batch according to self.reduction

abs(x, y, quadrature=None)[source]

absolute H1 norm

Parameters:
xtorch.Tensor

inputs

ytorch.Tensor

targets

quadraturefloat or list, optional

quadrature constant for reduction along each dim, by default None

rel(x, y, quadrature=None)[source]

relative H1-norm

Parameters:
xtorch.Tensor

inputs

ytorch.Tensor

targets

quadraturefloat or list, optional

quadrature constant for reduction along each dim, by default None