Sampling
Helpers to down- or upsample time series data.
- ecgan.preprocessing.sampling.transpose(input, dim0, dim1) Tensor
Returns a tensor that is a transposed version of
input
. The given dimensionsdim0
anddim1
are swapped.The resulting
out
tensor shares its underlying storage with theinput
tensor, so changing the content of one would change the content of the other.- Parameters
input (Tensor) -- the input tensor.
dim0 (int) -- the first dimension to be transposed
dim1 (int) -- the second dimension to be transposed
Example:
>>> x = torch.randn(2, 3) >>> x tensor([[ 1.0028, -0.9893, 0.5809], [-0.1669, 0.7299, 0.4942]]) >>> torch.transpose(x, 0, 1) tensor([[ 1.0028, -0.1669], [-0.9893, 0.7299], [ 0.5809, 0.4942]])
- ecgan.preprocessing.sampling.downsampling_fixed_sample_rate(data, sample_rate)[source]
Downsample dataset by returning every sample_rate-th value in every dimension.
- Parameters
data (
ndarray
) -- Tensor to be downsampled. Shape:(seq_len, channels)
.sample_rate (
int
) -- The fixed sample rate used to retain every sample_rate-th value.
- Return type
ndarray
- Returns
The downsampled series.
- ecgan.preprocessing.sampling.downsample_largest_triangle_three_buckets(data, threshold)[source]
Downsample the data according to LTTB.
- Parameters
data (
ndarray
) -- The unsampled data.threshold (
int
) -- The LTTB threshold (target size).
- Return type
ndarray
- Returns
The downsampled data.
- ecgan.preprocessing.sampling.interpolate(data, target_frequency, interpolation_strategy=None)[source]
Force an incoming multivariate series to conform to a fixed frequency using PyTorch.
Required if measuring devices use a different sampling frequency. More information on sampling rates: See here. Requires 3D input for most interpolation strategies.
- Parameters
data (
ndarray
) -- Input series which shall be upsampled. Shape: (seq_len, num_channels).target_frequency (
int
) -- Desired output frequency.interpolation_strategy (
Optional
[str
]) -- Strategy according to https://pytorch.org/docs/stable/nn.functional.html
- Return type
ndarray
- Returns
(NumPy) Tensor with the upsampled values.
- ecgan.preprocessing.sampling.resample(data, target_rate, algorithm=SamplingAlgorithm.LTTB, interpolation_strategy=None)[source]
Sample data according to the specified SamplingAlgorithm.
- Parameters
data (
ndarray
) -- The data that shall be sampled.algorithm (
SamplingAlgorithm
) -- The sampling algorithm.target_rate (
int
) -- Has to be set for a fixed sampling rate.interpolation_strategy (
Optional
[str
]) -- According to the PyTorch interpolation strategies. Only required for SamplingAlgorithm.INTERPOLATE.
- Return type
ndarray
- Returns
The resampled data.