weighted_interpolate#

hypercoil.functional.interpolate.weighted_interpolate(data: Tensor, mask: Tensor, start_stage: int = 1, max_stage: int | Literal['auto'] = 'auto', stages: Sequence[int] | None = None, map_to_kernel: Callable | None = None) Tensor[source]#

Interpolate unseen time frames as a weighted average of neighbours.

Interpolation proceeds iteratively over progressively longer window sizes. It first defines a convolutional weighting/window kernel for the current window size, and then sets the values of unseen time frames to the convolution of seen time frames with this kernel, and marks those time frames as seen for the next iteration. Iteration proceeds either until the specified maximum stage or until every unseen frame is imputed.

Note

In practice, for a square window kernel, the weighted interpolation is similar to a nearest-neighbour interpolation with very inefficient implementation.

Parameters:
datatensor

Time series data.

maskboolean tensor

Boolean tensor indicating whether the value in each frame of the input time series is observed. True indicates that the original data are “good” or observed, while False indicates that they are “bad” or missing and flags them for interpolation.

start_stageint

The first stage of weighted interpolation. The meaning of this is governed by the map_to_kernel argument. If no map_to_kernel argument is otherwise specified, it sets the initial size of a boxcar window for averaging. (A value of 1 corresponds to averaging over the current frame, together with 1 frame in each of the forward and reverse directions.)

max_stageint or None (default None)

The final stage of weighted interpolation. The meaning of this is governed by the map_to_kernel argument. If no map_to_kernel argument is otherwise specified, it sets the maximum size of a boxcar window for averaging. By default, no maximum size is specified, and iteration proceeds until every unseen time point is imputed.

map_to_kernelcallable(int -> tensor)

A function that uses the integer value of the current stage to create a convolutional kernel for weighting of neighbours. By default, a boxcar window that includes the current frame, together with stage frames in each of the forward and backward directions, is returned.

Returns:
Tensor

Input dataset with missing frames imputed.