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 likeplot_coeffsandcreate_movieto see the quality of this interpolationThe 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 arraylinspace(-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
xmust 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_samplinginstead.pix_sampling – If int, how far apart (in pixels) each sampled function should be. If None, we use
val_samplinginstead.func – The function to check interpolation for. Must take
xas its first input, all additional kwargs can be specified infunc_kwargs.x – The 1d tensor/array to evaluate
funcon. Ifxis not set, default istorch.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
sampledtofull. This has been transposed from the array returned bynumpy.linalg.lstsqand thus will have the same shape assampled(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
xis not setValueError – If neither
val_samplingnorpix_samplingare set toNone