hybrid_interpolate: Linear + spectral interpolation#

hypercoil.functional.interpolate.hybrid_interpolate(data: Tensor, mask: Tensor, max_consecutive_linear: int = 3, oversampling_frequency: float = 8, maximum_frequency: float = 1.0, sampling_period: float = 1.0, frequency_thresh: float = 0.3) Tensor[source]#

Interpolate unseen time frames using a hybrid approach that combines linear and spectral methods.

Hybrid interpolation uses the linear method for unseen frames that are no more than max_consecutive_linear frames away from a seen frame, and the spectral method otherwise. Imputation proceeds as follows:

  • Unseen frames are divided into two groups according to the approach that will be used for imputation.

  • Spectral interpolation is applied using the seen time frames.

  • Linear interpolation is applied using the seen time frames, together with the frames interpolated using the spectral method.

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.

max_consecutive_linearint or None (default 3)

The maximum number of consecutive frames for which the linear method will be used; any unseen frames that cannot be imputed using this maximum are instead imputed using the spectral approach.

oversampling_frequencyfloat (default 8)

Determines the number of frequency bins to use when estimating the sine and cosine spectra. 1 indicates that the number of bins should be the same as in a Fourier transform, while larger values indicate that frequency bins should be oversampled.

maximum_frequencyfloat (default 1)

Maximum frequency bin to consider in the fit, as a fraction of Nyquist.

sampling_periodfloat (default 1)

Period separating consecutive samples in data.

frequency_threshfloat (default 0.3)

Because of the non-orthogonality of the basis functions, spurious variance will often be captured in the spectral estimates. To control this spurious variance, all frequency bins whose estimates are less than frequency_thresh, as a fraction of the maximum estimate across all bins, are set to 0.

Returns:
Tensor

Input dataset with missing frames imputed.