Utils¶
- TS_PCA.utils.batch_dataset(dataset, batch_size, masks=None, dtype=<class 'jax.numpy.float32'>)¶
Change the shape to apply a batch function
- Parameters:
dataset (array of shape (n_ts,n_s,n_d)) – dataset of time series graph
batch_size ((int)) – we should have n_ts // batch_size=int
masks (array (n_ts,n_s,1)) – Mask related to the dataset
- Raises:
ValueError – dataset size is not a multiple of batch_size:
- Returns:
reshaped dataset : array of shape (n_batches,batch_size,n_s,n_d)
reshaped mask : array of shape (n_batches,batch_size,n_s,1)
- Return type:
pair
- TS_PCA.utils.from_timeseries_to_dataset(X, sampfreq=1, dtype=<class 'jax.numpy.float32'>)¶
Convert a list of time series arrays into a fixed-shape dataset suitable for TS-PCA.
Each time series is transformed into a time-augmented array of shape \((n\_samples, d+1)\) where the first column contains time points (with sampling frequency sampfreq) and the remaining columns contain the original time series values. The function also returns a mask indicating valid samples for each time series.
- Parameters:
X (list of arrays) – List of time series arrays. Each element should have shape (n_samples, d) or (n_samples,) for univariate series.
sampfreq (float, optional) – Sampling frequency used to generate the time points. Default is 1.
dtype (jnp.dtype, optional) – Data type of the returned arrays. Default is jnp.float32.
- Returns:
- datasetjnp.array of shape (n_time_series, n_samples_max, d+1)
Padded dataset of time series, where n_samples_max is the length of the longest time series. The first column contains time points, and the remaining columns contain time series values.
- maskjnp.array of shape (n_time_series, n_samples_max, 1)
Boolean mask indicating valid samples for each time series. True indicates a valid entry, False indicates padding.
Notes
The function pads shorter time series to the length of the longest series in X.
Internally, it calls time_shape_embedding to embed each time series with time
information and generate the corresponding mask. - Suitable for use as input to TS-PCA methods that require a fixed-size dataset and mask.
- TS_PCA.utils.time_shape_embedding(x, sampfreq=1, max_length=None, dtype=<class 'jax.numpy.float32'>)¶
time series to time series’graph
- Parameters:
x ((array)) – signal (T,d) or ()
sampfreq ((int, optional)) – sampling frequency. Defaults to 1. Important to set when it’s not 1 for hyperparameter tuning
max_length ((int, optional):) – maximum lenght desired. Defaults to None.
dtype ((_type_, optional):) – float32 or 64 depending on the memory. Defaults to jnp.float32.
- Returns:
The graph of the signal x : array of shape (T,d+1) Its mask : array of shape (T,1)
- Return type:
pair
- TS_PCA.utils.unbatch_dataset(batched_dataset, batched_masks=None, dtype=<class 'jax.numpy.float32'>)¶
Change the shape to remove batch dim
- Parameters:
batched_dataset (array of shape (n_batches,batch_size,n_s,n_d)) – batch dataset of time series graph
batched_masks (array (n_batches,batch_size,n_s,1)) – Mask related to the dataset
- Returns:
dataset : array of shape (n,n_s,n_d)
mask : array of shape (n,n_s,1)
- Return type:
pair