class_docstr: Class for computing metrics based on one StructuredDataset.
docstr: Args:
      dataset (StructuredDataset): A StructuredDataset.
      privileged_groups (list(dict)): Privileged groups. Format is a list
          of `dicts` where the keys are `protected_attribute_names` and
          the values are values in `protected_attributes`. Each `dict`
          element describes a single group. See examples for more details.
      unprivileged_groups (list(dict)): Unprivileged groups in the same
          format as `privileged_groups`.
  
  Raises:
      TypeError: `dataset` must be a
          :obj:`~aif360.datasets.StructuredDataset` type.
      ValueError: `privileged_groups` and `unprivileged_groups` must be
          disjoint.
  
  Examples:
      >>> from aif360.datasets import GermanDataset
      >>> german = GermanDataset()
      >>> u = [{'sex': 1, 'age': 1}, {'sex': 0}]
      >>> p = [{'sex': 1, 'age': 0}]
      >>> dm = DatasetMetric(german, unprivileged_groups=u, privileged_groups=p)
code: def __init__(
      self, dataset, unprivileged_groups=None, privileged_groups=None
  ):
      """
      Args:
          dataset (StructuredDataset): A StructuredDataset.
          privileged_groups (list(dict)): Privileged groups. Format is a list
              of `dicts` where the keys are `protected_attribute_names` and
              the values are values in `protected_attributes`. Each `dict`
              element describes a single group. See examples for more details.
          unprivileged_groups (list(dict)): Unprivileged groups in the same
              format as `privileged_groups`.
  
      Raises:
          TypeError: `dataset` must be a
              :obj:`~aif360.datasets.StructuredDataset` type.
          ValueError: `privileged_groups` and `unprivileged_groups` must be
              disjoint.
  
      Examples:
          >>> from aif360.datasets import GermanDataset
          >>> german = GermanDataset()
          >>> u = [{'sex': 1, 'age': 1}, {'sex': 0}]
          >>> p = [{'sex': 1, 'age': 0}]
          >>> dm = DatasetMetric(german, unprivileged_groups=u, privileged_groups=p)
      """
      if not isinstance(dataset, StructuredDataset):
          raise TypeError("'dataset' should be a StructuredDataset")
  
      # sets self.dataset
      super(DatasetMetric, self).__init__(dataset)
  
      # TODO: should this deepcopy?
      self.privileged_groups = privileged_groups
      self.unprivileged_groups = unprivileged_groups
  
      # don't check if nothing was provided
      if not self.privileged_groups or not self.unprivileged_groups:
          return
  
      priv_mask = utils.compute_boolean_conditioning_vector(
          self.dataset.protected_attributes,
          self.dataset.protected_attribute_names,
          self.privileged_groups,
      )
      unpriv_mask = utils.compute_boolean_conditioning_vector(
          self.dataset.protected_attributes,
          self.dataset.protected_attribute_names,
          self.unprivileged_groups,
      )
      if np.any(np.logical_and(priv_mask, unpriv_mask)):
          raise ValueError(
              "'privileged_groups' and 'unprivileged_groups'"
              " must be disjoint."
          )
  
file_path: AIF360/aif360/metrics/dataset_metric.py
imports: import numpy
  from aif360.datasets import StructuredDataset
  from aif360.metrics import Metric, utils
label_desc: Use image node_id 1 to create a new DatasetMetric object from inherited base classes: Metric with example: obj = DatasetMetric(dataset, unprivileged_groups, privileged_groups)