fenestration.sampling.check_sampling#

fenestration.sampling.check_sampling(val_sampling: float | None = 0.5, pix_sampling: int | None = None, func: ~collections.abc.Callable[[float | ~numpy.ndarray], ~numpy.ndarray] = <function gaussian>, x: ~torch.Tensor | ~numpy.ndarray | None = None, **func_kwargs: ~typing.Any) → tuple[ndarray, ndarray, ndarray, ndarray, ndarray]#

Check how sampling relates to interpolation quality.

Given a function, a domain, and how to sample that domain, this function will use linear algebra (numpy.linalg.lstsq) to determine how to interpolate the function so that it’s centered on each pixel. You can then use functions like plot_coeffs and create_movie to see the quality of this interpolation

The idea here is to take a function (for example, gaussian) and say that we have this function defined at, e.g., every 10 pixels on the array linspace(-5, 5, 101). We want to answer then, the question of how well we can interpolate to all the intermediate functions, that is, the functions centered on each pixel in the array.

You can either specify the spacing in pixels (pix_sampling) XOR in x values (val_sampling), but exactly one of them must be set.

Your function can either be a torch or numpy function, but x must be the appropriate type, we will not cast it for you.

Parameters:
  • val_sampling – If float, how far apart (in x-values) each sampled function should be. This doesn’t have to align perfectly with the pixels, but should be close. If None, we use pix_sampling instead.

  • pix_sampling – If int, how far apart (in pixels) each sampled function should be. If None, we use val_sampling instead.

  • func – The function to check interpolation for. Must take x as its first input, all additional kwargs can be specified in func_kwargs.

  • x – The 1d tensor/array to evaluate func on. If x is not set, default is torch.linspace(-5, 5, 101).

  • func_kwargs – Additional kwargs to pass to func

Returns:

  • sampled – the array of sampled functions. will have shape (len(x), ceil(len(x)/pix_sampling))

  • full – the array of functions centered at each pixel. will have shape (len(x), len(x))

  • interpolated – the array of functions interpolated to each pixel. will have shape (len(x), len(x))

  • coeffs – the array of coefficients to transform sampled to full. This has been transposed from the array returned by numpy.linalg.lstsq and thus will have the same shape as sampled (this is to make it easier to restrict which coeffs to look at, since they’ll be more easily indexed along first dimension)

  • residuals – the errors for each interpolation, will have shape len(x)

Raises:
  • ValueError – If x is not set

  • ValueError – If neither val_sampling nor pix_sampling are set to None