class_docstr: 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_docstr_tok: ["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","."]
docstr: Args:
      dataset: The dataset to sample from.
      support_set_size: The size of the support set.
      num_queries: The number of queries.
      context_length: The length of the context.
      support_length: The length of the support time series.
      prediction_length: The length of the prediction.
      catch22_nn: Contains for each index its 100 nearest neighbors w.r.t. catch22 distance.
          If not None, slices from the closest `support_set_size` time series are chosen as support set.
      cheat: If true, the query (time series to be predicted) shifted by the prediction length
          is contained in the support set, i.e. the ground truth is in the support set.
docstr_tok: ["Args",":","dataset",":","The","dataset","to","sample","from",".","support_set_size",":","The","size","of","the","support","set",".","num_queries",":","The","number","of","queries",".","context_length",":","The","length","of","the","context",".","support_length",":","The","length","of","the","support","time","series",".","prediction_length",":","The","length","of","the","prediction",".","catch22_nn",":","Contains","for","each","index","its","100","nearest","neighbors","w.r.t",".","catch22","distance",".","If","not","None",",","slices","from","the","closest","`","support_set_size","`","time","series","are","chosen","as","support","set",".","cheat",":","If","true",",","the","query","(","time","series","to","be","predicted",")","shifted","by","the","prediction","length","is","contained","in","the","support","set",",","i.e",".","the","ground","truth","is","in","the","support","set","."]
code: def __init__(
      self,
      dataset: TimeSeriesDataset,
      support_set_size: int,
      num_queries: int,
      context_length: int,
      support_length: int,
      prediction_length: int,
      catch22_nn: Optional[np.ndarray] = None,
      cheat: float = 0.0,
  ):
      """
      Args:
          dataset: The dataset to sample from.
          support_set_size: The size of the support set.
          num_queries: The number of queries.
          context_length: The length of the context.
          support_length: The length of the support time series.
          prediction_length: The length of the prediction.
          catch22_nn: Contains for each index its 100 nearest neighbors w.r.t. catch22 distance.
              If not None, slices from the closest `support_set_size` time series are chosen as support set.
          cheat: If true, the query (time series to be predicted) shifted by the prediction length
              is contained in the support set, i.e. the ground truth is in the support set.
      """
  
      # Initialize
      super().__init__()
      self.dataset = dataset
      self.support_set_size = support_set_size
      self.num_queries = num_queries
      self.context_length = context_length
      self.support_length = support_length
      self.prediction_length = prediction_length
      self.cheat = cheat
      assert (
          not cheat or self.num_queries == 1
      ), "Cheat sampling only allows num_queries = 1"
  
      time_series_lengths = np.array([len(s) for s in dataset])
      time_series_weights = (
          time_series_lengths / time_series_lengths.sum()
      )
      self.index_iterator = iter(
          WeightedIndexIterator(time_series_weights)
      )
  
      self.catch22_nn = catch22_nn
      assert not (
          self.catch22_nn is not None and num_queries > 1
      ), "catch22 support set selection only works with num_queries equal to one"
  
imports: from __future__ import annotations
  import numpy
  import pandas
  from dataclasses import dataclass, fields
  from typing import Iterator, List, Optional
  import torch
  from torch.utils.data import IterableDataset, Dataset
  from .dataset import TimeSeries, TimeSeriesDataset
label_desc: Use image node_id 1 to create a new SamplingTripletDataset object from inherited base classes: IterableDataset with example: obj = SamplingTripletDataset(dataset, support_set_size, num_queries, context_length, support_length, prediction_length, catch22_nn, cheat)