gluonts.nursery.few_shot_prediction.src.meta.data.sampling module#

class gluonts.nursery.few_shot_prediction.src.meta.data.sampling.SamplingTripletDataset(dataset: gluonts.nursery.few_shot_prediction.src.meta.data.dataset.TimeSeriesDataset, support_set_size: int, num_queries: int, context_length: int, support_length: int, prediction_length: int, catch22_nn: Optional[numpy.ndarray] = None, cheat: float = 0.0)[source]#

Bases: torch.utils.data.dataset.IterableDataset[gluonts.nursery.few_shot_prediction.src.meta.data.sampling.Triplet]

The sampling triplet dataset randomly samples support sets and past queries along with their future prediction horizon. All three sets consist of time series windows sliced from the original time series. The support set time series end before the prediction horizon begins to avoid time leakage. The dataset yields infinitely many items. Support set time series length is for now context_length.

class gluonts.nursery.few_shot_prediction.src.meta.data.sampling.SequentialTripletDataset(dataset: gluonts.nursery.few_shot_prediction.src.meta.data.dataset.TimeSeriesDataset, support_set_size: int, num_queries: int, context_length: int, support_length: int, prediction_length: int, support_dataset: Optional[gluonts.nursery.few_shot_prediction.src.meta.data.dataset.TimeSeriesDataset] = None, seed: Optional[int] = None, catch22_nn: Optional[numpy.ndarray] = None, cheat: bool = False)[source]#

Bases: torch.utils.data.dataset.Dataset[gluonts.nursery.few_shot_prediction.src.meta.data.sampling.Triplet]

The sequential triplet dataset traverses the dataset and uses the last prediction length slice as future query. The support set is sampled randomly. The length of dataset is the number of times series divided by the number of queries.

class gluonts.nursery.few_shot_prediction.src.meta.data.sampling.SuperSamplingTripletDataset(datasets: List[gluonts.nursery.few_shot_prediction.src.meta.data.sampling.SamplingTripletDataset], dataset_sampling: str)[source]#

Bases: torch.utils.data.dataset.IterableDataset[gluonts.nursery.few_shot_prediction.src.meta.data.sampling.Triplet]

The super sampling triplet dataset randomly samples support sets and past queries along with their future prediction horizon from a list of sampling datasets. First a sampling dataset is randomly chosen. Then the chosen triplet dataset samples support, query past and query future set. The dataset yields infinitely many items.

class gluonts.nursery.few_shot_prediction.src.meta.data.sampling.Triplet(support_set: List[gluonts.nursery.few_shot_prediction.src.meta.data.dataset.TimeSeries], query_past: List[gluonts.nursery.few_shot_prediction.src.meta.data.dataset.TimeSeries], query_future: List[gluonts.nursery.few_shot_prediction.src.meta.data.dataset.TimeSeries])[source]#

Bases: object

A triplet is composed of a support set, observed queries, and corresponding (unobserved) future queries.

query_future: List[gluonts.nursery.few_shot_prediction.src.meta.data.dataset.TimeSeries]#
query_past: List[gluonts.nursery.few_shot_prediction.src.meta.data.dataset.TimeSeries]#
support_set: List[gluonts.nursery.few_shot_prediction.src.meta.data.dataset.TimeSeries]#
class gluonts.nursery.few_shot_prediction.src.meta.data.sampling.TripletDataset(queries: gluonts.nursery.few_shot_prediction.src.meta.data.dataset.TimeSeriesDataset, support_sets: List[List[gluonts.nursery.few_shot_prediction.src.meta.data.dataset.TimeSeries]])[source]#

Bases: torch.utils.data.dataset.Dataset[gluonts.nursery.few_shot_prediction.src.meta.data.sampling.Triplet]

The triplet dataset gets a list of queries and corresponding support set and returns them as triplets.

class gluonts.nursery.few_shot_prediction.src.meta.data.sampling.WeightedIndexIterator(weights: numpy.ndarray, num_cache: int = 1024)[source]#

Bases: object

Iterator that caches a number of indices sampled according to given weights.

This gives a great performance speedup since np.random.choice is the bottleneck of the data loading. This class samples and caches a certain number of indices and return them until new ones need to be sampled.

gluonts.nursery.few_shot_prediction.src.meta.data.sampling.sample_supps(supps_size: int, length: int, dataset: gluonts.nursery.few_shot_prediction.src.meta.data.dataset.TimeSeriesDataset, index_iterator: Iterator, q_split: Optional[pandas._libs.tslibs.timestamps.Timestamp] = None, cheat_query: Optional[gluonts.nursery.few_shot_prediction.src.meta.data.dataset.TimeSeries] = None)[source]#
Parameters
  • supps_size – The number of support time series

  • length – The length of the support time series slice

  • dataset – The dataset to choose support time series slices from

  • index_iterator – An iterator that returns indices of the dataset sampled w.r.t. some weights.

  • q_split – The latest possible end time of all support time series

  • cheat_query – If not None, the cheat query is contained in the support set at a random position.