(self)
return episode_classes_rel
Returns the (relative) class IDs for an episode.

    If self.use_dag_hierarchy, it samples them according to a procedure
    informed by the dataset's ontology, otherwise randomly.
    If self.min_examples_in_class > 0, classes with too few examples will not
    be selected.
Returns the (relative) class IDs for an episode.
Returns the ( relative ) class IDs for an episode .
def sample_class_ids(self):
    """Returns the (relative) class IDs for an episode.

    If self.use_dag_hierarchy, it samples them according to a procedure
    informed by the dataset's ontology, otherwise randomly.
    If self.min_examples_in_class > 0, classes with too few examples will not
    be selected.
    """
    prob = [1.0, 0.0]
    if self.ignore_hierarchy_probability:
      prob = [
          1.0 - self.ignore_hierarchy_probability,
          self.ignore_hierarchy_probability
      ]

    if self.use_dag_hierarchy and self._rng.choice([True, False], p=prob):
      # Retrieve the list of relative class IDs for an internal node sampled
      # uniformly at random.
      episode_classes_rel = self._rng.choice(self.span_leaves_rel)

      # If the number of chosen classes is larger than desired, sub-sample them.
      if len(episode_classes_rel) > self.max_ways_upper_bound:
        episode_classes_rel = self._rng.choice(
            episode_classes_rel,
            size=[self.max_ways_upper_bound],
            replace=False)

      # Light check to make sure the chosen number of classes is valid.
      assert len(episode_classes_rel) >= self.min_ways
      assert len(episode_classes_rel) <= self.max_ways_upper_bound
    elif self.use_bilevel_hierarchy and self._rng.choice([True, False], p=prob):
      # First sample a coarse category uniformly. Then randomly sample the way
      # uniformly, but taking care not to sample more than the number of classes
      # of the chosen supercategory.
      episode_superclass = self._rng.choice(self.superclass_set, 1)[0]
      num_superclass_classes = self.dataset_spec.classes_per_superclass[
          episode_superclass]

      num_ways = sample_num_ways_uniformly(
          num_superclass_classes,
          min_ways=self.min_ways,
          max_ways=self.max_ways_upper_bound,
          rng=self._rng)

      # e.g. if these are [3, 1] then the 4'th and the 2'nd of the subclasses
      # that belong to the chosen superclass will be used. If the class id's
      # that belong to this superclass are [23, 24, 25, 26] then the returned
      # episode_classes_rel will be [26, 24] which as usual are number relative
      # to the split.
      episode_subclass_ids = sample_class_ids_uniformly(
          num_ways, num_superclass_classes, rng=self._rng)
      (episode_classes_rel,
       _) = self.dataset_spec.get_class_ids_from_superclass_subclass_inds(
           self.split, episode_superclass, episode_subclass_ids)
    elif self.use_all_classes:
      episode_classes_rel = np.arange(self.num_classes)
    else:  # No type of hierarchy is used. Classes are randomly sampled.
      if self.num_ways is not None:
        num_ways = self.num_ways
      else:
        num_ways = sample_num_ways_uniformly(
            self.num_filtered_classes,
            min_ways=self.min_ways,
            max_ways=self.max_ways_upper_bound,
            rng=self._rng)
      # Filtered class IDs relative to the selected split
      ids_rel = [
          class_id - self.class_set[0] for class_id in self._filtered_class_set
      ]
      episode_classes_rel = sample_class_ids_uniformly(
          num_ways, ids_rel, rng=self._rng)

    return episode_classes_rel
def sample_class_ids ( self ) : prob = [ 1.0 , 0.0 ] if self . ignore_hierarchy_probability : prob = [ 1.0 - self . ignore_hierarchy_probability , self . ignore_hierarchy_probability ] if self . use_dag_hierarchy and self . _rng . choice ( [ True , False ] , p = prob ) : # Retrieve the list of relative class IDs for an internal node sampled # uniformly at random. episode_classes_rel = self . _rng . choice ( self . span_leaves_rel ) # If the number of chosen classes is larger than desired, sub-sample them. if len ( episode_classes_rel ) > self . max_ways_upper_bound : episode_classes_rel = self . _rng . choice ( episode_classes_rel , size = [ self . max_ways_upper_bound ] , replace = False ) # Light check to make sure the chosen number of classes is valid. assert len ( episode_classes_rel ) >= self . min_ways assert len ( episode_classes_rel ) <= self . max_ways_upper_bound elif self . use_bilevel_hierarchy and self . _rng . choice ( [ True , False ] , p = prob ) : # First sample a coarse category uniformly. Then randomly sample the way # uniformly, but taking care not to sample more than the number of classes # of the chosen supercategory. episode_superclass = self . _rng . choice ( self . superclass_set , 1 ) [ 0 ] num_superclass_classes = self . dataset_spec . classes_per_superclass [ episode_superclass ] num_ways = sample_num_ways_uniformly ( num_superclass_classes , min_ways = self . min_ways , max_ways = self . max_ways_upper_bound , rng = self . _rng ) # e.g. if these are [3, 1] then the 4'th and the 2'nd of the subclasses # that belong to the chosen superclass will be used. If the class id's # that belong to this superclass are [23, 24, 25, 26] then the returned # episode_classes_rel will be [26, 24] which as usual are number relative # to the split. episode_subclass_ids = sample_class_ids_uniformly ( num_ways , num_superclass_classes , rng = self . _rng ) ( episode_classes_rel , _ ) = self . dataset_spec . get_class_ids_from_superclass_subclass_inds ( self . split , episode_superclass , episode_subclass_ids ) elif self . use_all_classes : episode_classes_rel = np . arange ( self . num_classes ) else : # No type of hierarchy is used. Classes are randomly sampled. if self . num_ways is not None : num_ways = self . num_ways else : num_ways = sample_num_ways_uniformly ( self . num_filtered_classes , min_ways = self . min_ways , max_ways = self . max_ways_upper_bound , rng = self . _rng ) # Filtered class IDs relative to the selected split ids_rel = [ class_id - self . class_set [ 0 ] for class_id in self . _filtered_class_set ] episode_classes_rel = sample_class_ids_uniformly ( num_ways , ids_rel , rng = self . _rng ) return episode_classes_rel