Losses

class spherical_inr.loss.CartesianGradientLaplacianMSELoss(alpha_reg: float = 1.0)[source]

Bases: Module

Cartesian Gradient-Laplacian MSE Loss.

Computes a composite loss that combines the MSE between the Cartesian gradient of the network output and a target gradient with a regularization term based on the squared Cartesian Laplacian. For a function \(f\) defined on \(\mathbb{R}^n\), let

\[\nabla f = \left( \frac{\partial f}{\partial x_1},\, \dots,\, \frac{\partial f}{\partial x_n} \right) \quad \text{and} \quad \Delta f = \sum_{i=1}^{n} \frac{\partial^2 f}{\partial x_i^2}.\]

The loss is defined as

\[\mathcal{L} = \operatorname{mean}\Bigl( \sum_{i=1}^{n}\Bigl( \frac{\partial f}{\partial x_i} - t_i \Bigr)^2 \Bigr) \;+\; \alpha\,\operatorname{mean}\Bigl( (\Delta f)^2 \Bigr),\]

where \(t\) is the target gradient and \(\alpha\) is a regularization parameter.

forward(target: Tensor, output: Tensor, input: Tensor) Tensor[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class spherical_inr.loss.CartesianGradientMSELoss(*args, **kwargs)[source]

Bases: Module

Cartesian Gradient MSE Loss.

Computes the mean squared error (MSE) loss between the Cartesian gradient of the network output and a target gradient. For a function \(f\) defined on \(\mathbb{R}^n\), the Cartesian gradient is

\[\nabla f = \left( \frac{\partial f}{\partial x_1},\, \frac{\partial f}{\partial x_2},\, \dots,\, \frac{\partial f}{\partial x_n} \right).\]

The loss is defined as

\[\mathcal{L} = \operatorname{mean}\Bigl( \sum_{i=1}^{n}\Bigl( \frac{\partial f}{\partial x_i} - t_i \Bigr)^2 \Bigr),\]

where \(t\) denotes the target gradient.

forward(target: Tensor, output: Tensor, input: Tensor) Tensor[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class spherical_inr.loss.CartesianLaplacianLoss(*args, **kwargs)[source]

Bases: Module

Cartesian Laplacian Loss.

Computes the loss based on the Cartesian Laplacian of the network output. For a scalar function \(f\) defined on \(\mathbb{R}^n\), the Cartesian Laplacian is

\[\Delta f = \sum_{i=1}^{n} \frac{\partial^2 f}{\partial x_i^2}.\]

The loss is defined as the mean squared value of the Laplacian:

\[\mathcal{L} = \operatorname{mean}\Bigl( (\Delta f)^2 \Bigr).\]
forward(output: Tensor, input: Tensor) Tensor[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class spherical_inr.loss.S2GradientLaplacianMSELoss(alpha_reg: float = 1.0)[source]

Bases: Module

S2 Gradient-Laplacian MSE Loss.

Computes a composite loss for functions defined on the 2-sphere that combines the MSE between the gradient on the 2-sphere and a target gradient with a regularization term based on the squared Laplacian on the 2-sphere. For a function \(f\) defined on the 2-sphere with coordinates \((\theta,\phi)\), let

\[\nabla_{S^2} f = \left( \frac{\partial f}{\partial \theta},\, \frac{1}{\sin\theta}\frac{\partial f}{\partial \phi} \right)\]

and

\[\Delta_{S^2} f = \frac{1}{\sin\theta}\frac{\partial}{\partial \theta}\left( \sin\theta\,\frac{\partial f}{\partial \theta} \right) + \frac{1}{\sin^2\theta}\frac{\partial^2 f}{\partial \phi^2}.\]

The loss is defined as

\[\mathcal{L} = \operatorname{mean}\Bigl( \sum_{i=1}^{2}\Bigl( (\nabla_{S^2} f)_i - t_i \Bigr)^2 \Bigr) \;+\; \alpha\,\operatorname{mean}\Bigl( (\Delta_{S^2} f)^2 \Bigr),\]

where \(t\) denotes the target gradient and \(\alpha\) is a regularization parameter.

forward(target: Tensor, output: Tensor, input: Tensor) Tensor[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class spherical_inr.loss.S2GradientMSELoss(*args, **kwargs)[source]

Bases: Module

S2 Gradient MSE Loss.

Computes the mean squared error (MSE) loss between the gradient on the 2-sphere and a target gradient. For a function \(f\) defined on the 2-sphere with coordinates \((\theta,\phi)\), the gradient is

\[\nabla_{S^2} f = \left( \frac{\partial f}{\partial \theta},\, \frac{1}{\sin\theta}\frac{\partial f}{\partial \phi} \right).\]

The loss is defined as

\[\mathcal{L} = \operatorname{mean}\Bigl( \sum_{i=1}^{2}\Bigl( (\nabla_{S^2} f)_i - t_i \Bigr)^2 \Bigr),\]

where \(t\) denotes the target gradient.

forward(target: Tensor, output: Tensor, input: Tensor) Tensor[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class spherical_inr.loss.S2LaplacianLoss(*args, **kwargs)[source]

Bases: Module

S2 Laplacian Loss.

Computes the loss based on the Laplacian of the network output on the 2-sphere. For a function \(f\) defined on the 2-sphere with coordinates \((\theta,\phi)\), the Laplacian is

\[\Delta_{S^2} f = \frac{1}{\sin\theta}\frac{\partial}{\partial \theta}\left( \sin\theta\,\frac{\partial f}{\partial \theta} \right) + \frac{1}{\sin^2\theta}\frac{\partial^2 f}{\partial \phi^2}.\]

The loss is defined as the mean squared value of the Laplacian:

\[\mathcal{L} = \operatorname{mean}\Bigl( (\Delta_{S^2} f)^2 \Bigr).\]
forward(output: Tensor, input: Tensor) Tensor[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class spherical_inr.loss.SphericalGradientLaplacianMSELoss(alpha_reg: float = 1.0)[source]

Bases: Module

Spherical Gradient-Laplacian MSE Loss.

Computes a composite loss that combines the MSE between the spherical gradient of the network output and a target gradient with a regularization term based on the squared spherical Laplacian. For a function \(f\) defined in spherical coordinates \((r,\theta,\phi)\), let

\[\nabla_{sph} f = \left( \frac{\partial f}{\partial r},\, \frac{1}{r}\frac{\partial f}{\partial \theta},\, \frac{1}{r\,\sin\theta}\frac{\partial f}{\partial \phi} \right)\]

and the spherical Laplacian is

\[\Delta_{sph} f = \frac{1}{r^2}\frac{\partial}{\partial r}\left( r^2\,\frac{\partial f}{\partial r} \right) + \frac{1}{r^2 \sin\theta}\frac{\partial}{\partial \theta}\left( \sin\theta\,\frac{\partial f}{\partial \theta} \right) + \frac{1}{r^2 \sin^2\theta}\frac{\partial^2 f}{\partial \phi^2}.\]

The loss is defined as

\[\mathcal{L} = \operatorname{mean}\Bigl( \sum_{i}\Bigl( (\nabla_{sph} f)_i - t_i \Bigr)^2 \Bigr) \;+\; \alpha\,\operatorname{mean}\Bigl( (\Delta_{sph} f)^2 \Bigr),\]

where \(t\) is the target gradient and \(\alpha\) is a regularization coefficient.

forward(target: Tensor, output: Tensor, input: Tensor) Tensor[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class spherical_inr.loss.SphericalGradientMSELoss(*args, **kwargs)[source]

Bases: Module

Spherical Gradient MSE Loss.

Computes the mean squared error (MSE) loss between the spherical gradient of the network output and a target gradient. For a function \(f\) defined in spherical coordinates \((r,\theta,\phi)\), the spherical gradient is given by

\[\nabla_{sph} f = \left( \frac{\partial f}{\partial r},\, \frac{1}{r}\frac{\partial f}{\partial \theta},\, \frac{1}{r\,\sin\theta}\frac{\partial f}{\partial \phi} \right).\]

The loss is defined as

\[\mathcal{L} = \operatorname{mean}\Bigl( \sum_{i}\Bigl( (\nabla_{sph} f)_i - t_i \Bigr)^2 \Bigr),\]

where \(t\) represents the target gradient.

forward(target: Tensor, output: Tensor, input: Tensor) Tensor[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class spherical_inr.loss.SphericalLaplacianLoss(*args, **kwargs)[source]

Bases: Module

Spherical Laplacian Loss.

Computes the loss based on the spherical Laplacian of the network output. For a scalar function \(f\) defined in spherical coordinates \((r,\theta,\phi)\), the spherical Laplacian is given by

\[\Delta_{sph} f = \frac{1}{r^2}\frac{\partial}{\partial r}\left( r^2\,\frac{\partial f}{\partial r} \right) + \frac{1}{r^2 \sin\theta}\frac{\partial}{\partial \theta}\left( \sin\theta\,\frac{\partial f}{\partial \theta} \right) + \frac{1}{r^2 \sin^2\theta}\frac{\partial^2 f}{\partial \phi^2}.\]

The loss is defined as the mean squared value of the Laplacian:

\[\mathcal{L} = \operatorname{mean}\Bigl( (\Delta_{sph} f)^2 \Bigr).\]
forward(output: Tensor, input: Tensor) Tensor[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.