class_docstr: Wrapper class for computing different metrics on different tasks in the context of multitask learning.
  
  In multitask learning the different tasks requires different metrics to be evaluated. This wrapper allows
  for easy evaluation in such cases by supporting multiple predictions and targets through a dictionary.
  Note that only metrics where the signature of `update` follows the standard `preds, target` is supported.
  
  Args:
      task_metrics:
          Dictionary associating each task to a Metric or a MetricCollection. The keys of the dictionary represent the
          names of the tasks, and the values represent the metrics to use for each task.
  
  Raises:
      TypeError:
          If argument `task_metrics` is not an dictionary
      TypeError:
          If not all values in the `task_metrics` dictionary is instances of `Metric` or `MetricCollection`
  
  Example (with a single metric per class):
       >>> import torch
       >>> from torchmetrics.wrappers import MultitaskWrapper
       >>> from torchmetrics.regression import MeanSquaredError
       >>> from torchmetrics.classification import BinaryAccuracy
       >>>
       >>> classification_target = torch.tensor([0, 1, 0])
       >>> regression_target = torch.tensor([2.5, 5.0, 4.0])
       >>> targets = {"Classification": classification_target, "Regression": regression_target}
       >>>
       >>> classification_preds = torch.tensor([0, 0, 1])
       >>> regression_preds = torch.tensor([3.0, 5.0, 2.5])
       >>> preds = {"Classification": classification_preds, "Regression": regression_preds}
       >>>
       >>> metrics = MultitaskWrapper({
       ...     "Classification": BinaryAccuracy(),
       ...     "Regression": MeanSquaredError()
       ... })
       >>> metrics.update(preds, targets)
       >>> metrics.compute()
       {'Classification': tensor(0.3333), 'Regression': tensor(0.8333)}
  
  Example (with several metrics per task):
       >>> import torch
       >>> from torchmetrics import MetricCollection
       >>> from torchmetrics.wrappers import MultitaskWrapper
       >>> from torchmetrics.regression import MeanSquaredError, MeanAbsoluteError
       >>> from torchmetrics.classification import BinaryAccuracy, BinaryF1Score
       >>>
       >>> classification_target = torch.tensor([0, 1, 0])
       >>> regression_target = torch.tensor([2.5, 5.0, 4.0])
       >>> targets = {"Classification": classification_target, "Regression": regression_target}
       >>>
       >>> classification_preds = torch.tensor([0, 0, 1])
       >>> regression_preds = torch.tensor([3.0, 5.0, 2.5])
       >>> preds = {"Classification": classification_preds, "Regression": regression_preds}
       >>>
       >>> metrics = MultitaskWrapper({
       ...     "Classification": MetricCollection(BinaryAccuracy(), BinaryF1Score()),
       ...     "Regression": MetricCollection(MeanSquaredError(), MeanAbsoluteError())
       ... })
       >>> metrics.update(preds, targets)
       >>> metrics.compute()
       {'Classification': {'BinaryAccuracy': tensor(0.3333), 'BinaryF1Score': tensor(0.)},
        'Regression': {'MeanSquaredError': tensor(0.8333), 'MeanAbsoluteError': tensor(0.6667)}}
class_docstr_tok: ["Wrapper","class","for","computing","different","metrics","on","different","tasks","in","the","context","of","multitask","learning",".","In","multitask","learning","the","different","tasks","requires","different","metrics","to","be","evaluated",".","This","wrapper","allows","for","easy","evaluation","in","such","cases","by","supporting","multiple","predictions","and","targets","through","a","dictionary",".","Note","that","only","metrics","where","the","signature","of","`","update","`","follows","the","standard","`","preds",",","target","`","is","supported",".","Args",":","task_metrics",":","Dictionary","associating","each","task","to","a","Metric","or","a","MetricCollection",".","The","keys","of","the","dictionary","represent","the","names","of","the","tasks",",","and","the","values","represent","the","metrics","to","use","for","each","task",".","Raises",":","TypeError",":","If","argument","`","task_metrics","`","is","not","an","dictionary","TypeError",":","If","not","all","values","in","the","`","task_metrics","`","dictionary","is","instances","of","`","Metric","`","or","`","MetricCollection","`","Example","(","with","a","single","metric","per","class",")",":",">",">",">","import","torch",">",">",">","from","torchmetrics.wrappers","import","MultitaskWrapper",">",">",">","from","torchmetrics.regression","import","MeanSquaredError",">",">",">","from","torchmetrics.classification","import","BinaryAccuracy",">",">",">",">",">",">","classification_target","=","torch.tensor","(","[","0",",","1",",","0","]",")",">",">",">","regression_target","=","torch.tensor","(","[","2.5",",","5.0",",","4.0","]",")",">",">",">","targets","=","{","``","Classification","''",":","classification_target",",","``","Regression","''",":","regression_target","}",">",">",">",">",">",">","classification_preds","=","torch.tensor","(","[","0",",","0",",","1","]",")",">",">",">","regression_preds","=","torch.tensor","(","[","3.0",",","5.0",",","2.5","]",")",">",">",">","preds","=","{","``","Classification","''",":","classification_preds",",","``","Regression","''",":","regression_preds","}",">",">",">",">",">",">","metrics","=","MultitaskWrapper","(","{","...","``","Classification","''",":","BinaryAccuracy","(",")",",","...","``","Regression","''",":","MeanSquaredError","(",")","...","}",")",">",">",">","metrics.update","(","preds",",","targets",")",">",">",">","metrics.compute","(",")","{","'Classification","'",":","tensor","(","0.3333",")",",","'Regression","'",":","tensor","(","0.8333",")","}","Example","(","with","several","metrics","per","task",")",":",">",">",">","import","torch",">",">",">","from","torchmetrics","import","MetricCollection",">",">",">","from","torchmetrics.wrappers","import","MultitaskWrapper",">",">",">","from","torchmetrics.regression","import","MeanSquaredError",",","MeanAbsoluteError",">",">",">","from","torchmetrics.classification","import","BinaryAccuracy",",","BinaryF1Score",">",">",">",">",">",">","classification_target","=","torch.tensor","(","[","0",",","1",",","0","]",")",">",">",">","regression_target","=","torch.tensor","(","[","2.5",",","5.0",",","4.0","]",")",">",">",">","targets","=","{","``","Classification","''",":","classification_target",",","``","Regression","''",":","regression_target","}",">",">",">",">",">",">","classification_preds","=","torch.tensor","(","[","0",",","0",",","1","]",")",">",">",">","regression_preds","=","torch.tensor","(","[","3.0",",","5.0",",","2.5","]",")",">",">",">","preds","=","{","``","Classification","''",":","classification_preds",",","``","Regression","''",":","regression_preds","}",">",">",">",">",">",">","metrics","=","MultitaskWrapper","(","{","...","``","Classification","''",":","MetricCollection","(","BinaryAccuracy","(",")",",","BinaryF1Score","(",")",")",",","...","``","Regression","''",":","MetricCollection","(","MeanSquaredError","(",")",",","MeanAbsoluteError","(",")",")","...","}",")",">",">",">","metrics.update","(","preds",",","targets",")",">",">",">","metrics.compute","(",")","{","'Classification","'",":","{","'BinaryAccuracy","'",":","tensor","(","0.3333",")",",","'BinaryF1Score","'",":","tensor","(","0",".",")","}",",","'Regression","'",":","{","'MeanSquaredError","'",":","tensor","(","0.8333",")",",","'MeanAbsoluteError","'",":","tensor","(","0.6667",")","}","}"]
docstr: Plot a single or multiple values from the metric.
  
  All tasks' results are plotted on individual axes.
  
  Args:
      val: Either a single result from calling `metric.forward` or `metric.compute` or a list of these results.
          If no value is provided, will automatically call `metric.compute` and plot that result.
      axes: Sequence of matplotlib axis objects. If provided, will add the plots to the provided axis objects.
          If not provided, will create them.
  
  Returns:
      Sequence of tuples with Figure and Axes object for each task.
  
  .. plot::
      :scale: 75
  
      >>> # Example plotting a single value
      >>> import torch
      >>> from torchmetrics.wrappers import MultitaskWrapper
      >>> from torchmetrics.regression import MeanSquaredError
      >>> from torchmetrics.classification import BinaryAccuracy
      >>>
      >>> classification_target = torch.tensor([0, 1, 0])
      >>> regression_target = torch.tensor([2.5, 5.0, 4.0])
      >>> targets = {"Classification": classification_target, "Regression": regression_target}
      >>>
      >>> classification_preds = torch.tensor([0, 0, 1])
      >>> regression_preds = torch.tensor([3.0, 5.0, 2.5])
      >>> preds = {"Classification": classification_preds, "Regression": regression_preds}
      >>>
      >>> metrics = MultitaskWrapper({
      ...     "Classification": BinaryAccuracy(),
      ...     "Regression": MeanSquaredError()
      ... })
      >>> metrics.update(preds, targets)
      >>> value = metrics.compute()
      >>> fig_, ax_ = metrics.plot(value)
  
  .. plot::
      :scale: 75
  
      >>> # Example plotting multiple values
      >>> import torch
      >>> from torchmetrics.wrappers import MultitaskWrapper
      >>> from torchmetrics.regression import MeanSquaredError
      >>> from torchmetrics.classification import BinaryAccuracy
      >>>
      >>> classification_target = torch.tensor([0, 1, 0])
      >>> regression_target = torch.tensor([2.5, 5.0, 4.0])
      >>> targets = {"Classification": classification_target, "Regression": regression_target}
      >>>
      >>> classification_preds = torch.tensor([0, 0, 1])
      >>> regression_preds = torch.tensor([3.0, 5.0, 2.5])
      >>> preds = {"Classification": classification_preds, "Regression": regression_preds}
      >>>
      >>> metrics = MultitaskWrapper({
      ...     "Classification": BinaryAccuracy(),
      ...     "Regression": MeanSquaredError()
      ... })
      >>> values = []
      >>> for _ in range(10):
      ...     values.append(metrics(preds, targets))
      >>> fig_, ax_ = metrics.plot(values)
docstr_tok: ["Plot","a","single","or","multiple","values","from","the","metric",".","All","tasks","'","results","are","plotted","on","individual","axes",".","Args",":","val",":","Either","a","single","result","from","calling","`","metric.forward","`","or","`","metric.compute","`","or","a","list","of","these","results",".","If","no","value","is","provided",",","will","automatically","call","`","metric.compute","`","and","plot","that","result",".","axes",":","Sequence","of","matplotlib","axis","objects",".","If","provided",",","will","add","the","plots","to","the","provided","axis","objects",".","If","not","provided",",","will","create","them",".","Returns",":","Sequence","of","tuples","with","Figure","and","Axes","object","for","each","task",".","..","plot",":",":",":","scale",":","75",">",">",">","#","Example","plotting","a","single","value",">",">",">","import","torch",">",">",">","from","torchmetrics.wrappers","import","MultitaskWrapper",">",">",">","from","torchmetrics.regression","import","MeanSquaredError",">",">",">","from","torchmetrics.classification","import","BinaryAccuracy",">",">",">",">",">",">","classification_target","=","torch.tensor","(","[","0",",","1",",","0","]",")",">",">",">","regression_target","=","torch.tensor","(","[","2.5",",","5.0",",","4.0","]",")",">",">",">","targets","=","{","``","Classification","''",":","classification_target",",","``","Regression","''",":","regression_target","}",">",">",">",">",">",">","classification_preds","=","torch.tensor","(","[","0",",","0",",","1","]",")",">",">",">","regression_preds","=","torch.tensor","(","[","3.0",",","5.0",",","2.5","]",")",">",">",">","preds","=","{","``","Classification","''",":","classification_preds",",","``","Regression","''",":","regression_preds","}",">",">",">",">",">",">","metrics","=","MultitaskWrapper","(","{","...","``","Classification","''",":","BinaryAccuracy","(",")",",","...","``","Regression","''",":","MeanSquaredError","(",")","...","}",")",">",">",">","metrics.update","(","preds",",","targets",")",">",">",">","value","=","metrics.compute","(",")",">",">",">","fig_",",","ax_","=","metrics.plot","(","value",")","..","plot",":",":",":","scale",":","75",">",">",">","#","Example","plotting","multiple","values",">",">",">","import","torch",">",">",">","from","torchmetrics.wrappers","import","MultitaskWrapper",">",">",">","from","torchmetrics.regression","import","MeanSquaredError",">",">",">","from","torchmetrics.classification","import","BinaryAccuracy",">",">",">",">",">",">","classification_target","=","torch.tensor","(","[","0",",","1",",","0","]",")",">",">",">","regression_target","=","torch.tensor","(","[","2.5",",","5.0",",","4.0","]",")",">",">",">","targets","=","{","``","Classification","''",":","classification_target",",","``","Regression","''",":","regression_target","}",">",">",">",">",">",">","classification_preds","=","torch.tensor","(","[","0",",","0",",","1","]",")",">",">",">","regression_preds","=","torch.tensor","(","[","3.0",",","5.0",",","2.5","]",")",">",">",">","preds","=","{","``","Classification","''",":","classification_preds",",","``","Regression","''",":","regression_preds","}",">",">",">",">",">",">","metrics","=","MultitaskWrapper","(","{","...","``","Classification","''",":","BinaryAccuracy","(",")",",","...","``","Regression","''",":","MeanSquaredError","(",")","...","}",")",">",">",">","values","=","[","]",">",">",">","for","_","in","range","(","10",")",":","...","values.append","(","metrics","(","preds",",","targets",")",")",">",">",">","fig_",",","ax_","=","metrics.plot","(","values",")"]
code: def plot(
      self,
      val: Optional[Union[Dict, Sequence[Dict]]] = None,
      axes: Optional[Sequence[_AX_TYPE]] = None,
  ) -> Sequence[_PLOT_OUT_TYPE]:
      """Plot a single or multiple values from the metric.
  
      All tasks' results are plotted on individual axes.
  
      Args:
          val: Either a single result from calling `metric.forward` or `metric.compute` or a list of these results.
              If no value is provided, will automatically call `metric.compute` and plot that result.
          axes: Sequence of matplotlib axis objects. If provided, will add the plots to the provided axis objects.
              If not provided, will create them.
  
      Returns:
          Sequence of tuples with Figure and Axes object for each task.
  
      .. plot::
          :scale: 75
  
          >>> # Example plotting a single value
          >>> import torch
          >>> from torchmetrics.wrappers import MultitaskWrapper
          >>> from torchmetrics.regression import MeanSquaredError
          >>> from torchmetrics.classification import BinaryAccuracy
          >>>
          >>> classification_target = torch.tensor([0, 1, 0])
          >>> regression_target = torch.tensor([2.5, 5.0, 4.0])
          >>> targets = {"Classification": classification_target, "Regression": regression_target}
          >>>
          >>> classification_preds = torch.tensor([0, 0, 1])
          >>> regression_preds = torch.tensor([3.0, 5.0, 2.5])
          >>> preds = {"Classification": classification_preds, "Regression": regression_preds}
          >>>
          >>> metrics = MultitaskWrapper({
          ...     "Classification": BinaryAccuracy(),
          ...     "Regression": MeanSquaredError()
          ... })
          >>> metrics.update(preds, targets)
          >>> value = metrics.compute()
          >>> fig_, ax_ = metrics.plot(value)
  
      .. plot::
          :scale: 75
  
          >>> # Example plotting multiple values
          >>> import torch
          >>> from torchmetrics.wrappers import MultitaskWrapper
          >>> from torchmetrics.regression import MeanSquaredError
          >>> from torchmetrics.classification import BinaryAccuracy
          >>>
          >>> classification_target = torch.tensor([0, 1, 0])
          >>> regression_target = torch.tensor([2.5, 5.0, 4.0])
          >>> targets = {"Classification": classification_target, "Regression": regression_target}
          >>>
          >>> classification_preds = torch.tensor([0, 0, 1])
          >>> regression_preds = torch.tensor([3.0, 5.0, 2.5])
          >>> preds = {"Classification": classification_preds, "Regression": regression_preds}
          >>>
          >>> metrics = MultitaskWrapper({
          ...     "Classification": BinaryAccuracy(),
          ...     "Regression": MeanSquaredError()
          ... })
          >>> values = []
          >>> for _ in range(10):
          ...     values.append(metrics(preds, targets))
          >>> fig_, ax_ = metrics.plot(values)
  
      """
      if axes is not None:
          if not isinstance(axes, Sequence):
              raise TypeError(
                  f"Expected argument `axes` to be a Sequence. Found type(axes) = {type(axes)}"
              )
  
          if not all(isinstance(ax, _AX_TYPE) for ax in axes):
              raise TypeError(
                  "Expected each ax in argument `axes` to be a matplotlib axis object"
              )
  
          if len(axes) != len(self.task_metrics):
              raise ValueError(
                  "Expected argument `axes` to be a Sequence of the same length as the number of tasks."
                  f"Found len(axes) = {len(axes)} and {len(self.task_metrics)} tasks"
              )
  
      val = val if val is not None else self.compute()
      fig_axs = []
      for i, (task_name, task_metric) in enumerate(
          self.task_metrics.items()
      ):
          ax = axes[i] if axes is not None else None
          if isinstance(val, Dict):
              f, a = task_metric.plot(val[task_name], ax=ax)
          elif isinstance(val, Sequence):
              f, a = task_metric.plot(
                  [v[task_name] for v in val], ax=ax
              )
          else:
              raise TypeError(
                  "Expected argument `val` to be None or of type Dict or Sequence[Dict]. "
                  f"Found type(val)= {type(val)}"
              )
          fig_axs.append((f, a))
      return fig_axs
  
file_path: torchmetrics/src/torchmetrics/wrappers/multitask.py
imports: from typing import Any, Dict, Iterable, Optional, Sequence, Tuple, Union
  from torch import Tensor, nn
  from torchmetrics.collections import MetricCollection
  from torchmetrics.metric import Metric
  from torchmetrics.utilities.imports import _MATPLOTLIB_AVAILABLE
  from torchmetrics.utilities.plot import _AX_TYPE, _PLOT_OUT_TYPE
  from torchmetrics.wrappers.abstract import WrapperMetric
label_desc: Use image node_id 10 for calling the MultitaskWrapper obj's underlying member method code with example usage: obj.plot(val, axes) and returns: fig_axs