dsf.utils.integrators module

Numerical integration scripts for Delta Sigma calculations.

dsf.utils.integrators.normalize_distribution(x, y)[source]

Normalize a one-dimensional distribution.

Parameters:
  • x (ndarray[tuple[Any, ...], dtype[float64]]) – Coordinate array.

  • y (ndarray[tuple[Any, ...], dtype[float64]]) – Distribution values evaluated on x.

Returns:

Distribution values normalized so that their trapezoid integral over x is one.

Raises:

ValueError – If the distribution integral is not positive.

Return type:

ndarray[tuple[Any, …], dtype[float64]]

dsf.utils.integrators.trapezoid_integral(y, x, *, axis=-1)[source]

Integrate values using the trapezoid rule.

Parameters:
  • y (ndarray[tuple[Any, ...], dtype[float64]]) – Values to integrate.

  • x (ndarray[tuple[Any, ...], dtype[float64]]) – Coordinates along the integration axis.

  • axis (int) – Axis over which to integrate. If y is one-dimensional, the result is a scalar. If y has extra dimensions, the integration removes the selected axis and returns an array.

Returns:

Integral of y with respect to x. Returns a scalar for a one-dimensional integral and an array for batched integrals.

Return type:

float | ndarray[tuple[Any, …], dtype[float64]]

dsf.utils.integrators.weighted_trapezoid_average(x, values, weights, *, axis=0, normalize_weights=True)[source]

Compute a weighted trapezoid average along one axis.

Parameters:
  • x (ndarray[tuple[Any, ...], dtype[float64]]) – Coordinate array for the integration axis.

  • values (ndarray[tuple[Any, ...], dtype[float64]]) – Values to average.

  • weights (ndarray[tuple[Any, ...], dtype[float64]]) – One-dimensional weights defined on x.

  • axis (int) – Axis of values corresponding to x.

  • normalize_weights (bool) – Whether to normalize weights before averaging. If True, the returned value is a true weighted average. If False, the returned value is the weighted integral.

Returns:

Weighted average over axis. Returns a scalar if all dimensions are integrated away, otherwise returns an array.

Return type:

float | ndarray[tuple[Any, …], dtype[float64]]