SQuad

class xitorch.integrate.SQuad(x: torch.Tensor, method: Optional[Union[str, Callable]] = None, **fwd_options)[source]

SQuad (Sampled QUADrature) is a class for quadrature performed with a fixed samples at given points. Mathematically, it does the integration

\[\mathbf{z}(x) = \int_{x_0}^x \mathbf{y}(x')\ \mathrm{d}x\]

where \(\mathbf{y}(x)\) is the interpolated function from a given sample.

Parameters
  • x (torch.Tensor) – The positions where the samples are given. It is a 1D tensor with shape (nx,).

  • method (str or callable or None) – The integration method. If None, it will choose "cspline".

  • **fwd_options – Method-specific options (see method section below)

method="cspline"
SQuad(..., method="cspline", *, bc_type="natural")

Perform integration of given sampled values by assuming it is interpolated with cubic spline 1. It is simply

\[S = \sum_{i=0}^{N-2} \left[\frac{1}{2}(y_i+y_{i+1}) + \frac{1}{12}(y'_i - y'_{i+1})(x_{i+1}-x_i)^2\right]\]
Keyword Arguments

bc_type (str) – Boundary condition. See xitorch.interpolate.Interp1D with "cspline" method for details.

References

1

Mark H. Holmes, “Connections Between Cubic Splines and Quadrature Rules” (eq. 8), The American Mathematical Monthly, Volume 121, Issue 8, 2014.

method="trapz"
SQuad(..., method="trapz")

Perform integration with trapezoidal rule. It is simply

\[S = \sum_{i=0}^{N-2} \frac{1}{2}(y_i+y_{i+1})\]
cumsum(y: torch.Tensor, dim: int = - 1) → torch.Tensor[source]

Perform the cumulative integration of the samples \(\mathbf{y}\) over the specified dimension.

Parameters
  • y (torch.Tensor) – The value of samples. The size of y at dim must be equal to the length of x.

  • dim (int) – The dimension where the cumulative integration is performed.

Returns

The cumulative integrated values with the same shape as y.

Return type

torch.Tensor

integrate(y: torch.Tensor, dim: int = - 1, keepdim: bool = False) → torch.Tensor[source]

Perform the full integration of the samples \(\mathbf{y}\) over the specified dimension.

Parameters
  • y (torch.Tensor) – The value of samples. The size of y at dim must be equal to the length of x, i.e. (..., nx, ...).

  • dim (int) – The dimension where the integration is performed.

  • keepdim (bool) – Option to not discard the integrated dimension. If True, the integrated dimension size will be 1.

Returns

The integrated values.

Return type

torch.Tensor