1D Quadrature rules

This contains some utilities for defining 1D quadrules used to estimate the integral over the residual

Gauss legendre quadrature

class svise.quadrature.gauss_legendre_vecs(N: int, a: float = -1.0, b: float = 1.0, dtype: dtype | None = None)[source]

Returns the gauss-legendre quadrature weights and nodes provided by fastgl (see svise/extern for LICENSE and details)

Parameters:
  • N (int) – Number of integration nodes

  • dtype (torch.dtype, optional) – Return data type. Defaults to torch.float32.

Returns:

integration weights, integration nodes

Return type:

(dtype, dtype)

Trapezoidal quadrature

class svise.quadrature.trapezoidal_vecs(N: int, a: float = -1.0, b: float = 1.0, dtype: dtype | None = None)[source]

Returns the trapezoidal qudrature weights and nodes

Parameters:
  • N (int) – Number of integration nodes

  • a (float, optional) – Start of interval. Defaults to -1.0.

  • b (float, optional) – End of interval. Defaults to 1.0.

  • dtype (torch.dtype, optional) – Return data type. Defaults to torch.float32.

Returns:

integration weights, integration nodes

Return type:

(dtype, dtype)

QuadRule1D abstract base class

class svise.quadrature.QuadRule1D(a: float | Tensor, b: float | Tensor, N: int, *args, **kwargs)[source]

Abstract base class for 1D quad rules.

Parameters:
  • a (Union[float, Tensor]) – lower bound of integration

  • b (Union[float, Tensor]) – upper bound of integration

  • N (int) – number of quadrature nodes

abstract forward(f: Callable) Tensor[source]

Estimate for integral :param f: function to be integrated :type f: Callable

Returns:

Iq integral estimate

Return type:

Tensor

Gauss-Legendre quad rule

class svise.quadrature.GaussLegendreQuad(a: float | Tensor, b: float | Tensor, N: int)[source]

Estimates integral with Gauss Legendre quad.

Parameters:
  • a (Union[float, Tensor]) – lower bound of integration

  • b (Union[float, Tensor]) – upper bound of integration

  • N (int) – number of quadrature nodes

forward(f: Callable)[source]

Estimate for integral :param f: function to be integrated :type f: Callable

Returns:

Iq integral estimate

Return type:

Tensor

Unbiased Gauss-Legendre quad rule

class svise.quadrature.UnbiasedGaussLegendreQuad(a: float | Tensor, b: float | Tensor, N: int, quad_percent: float, gamma: float | Tensor = 1.0)[source]

Estimates integral using the unbiased quadrature scheme based on Gauss Legendre quadrature from L.-f. Lee, Interpolation, quadrature, and stochastic integration, Econometric Theory 17, (2001).

Parameters:
  • a (Union[float, Tensor]) – lower bound of integration

  • b (Union[float, Tensor]) – upper bound of integration

  • N (int) – number of quadrature nodes

  • quad_percent (float) – percentage of quad nodes to use for Legendre

forward(f: Callable)[source]

Estimate for integral :param f: function to be integrated :type f: Callable

Returns:

Iq integral estimate

Return type:

Tensor