code: def calculate_losses(
      solution: np.ndarray,
      prediction: np.ndarray,
      task_type: int,
      metrics: Sequence[Scorer],
      *,
      X_data: Optional[SUPPORTED_XDATA_TYPES] = None,
      scoring_functions: Optional[List[Scorer]] = None,
  ) -> Dict[str, float]:
      """
      Returns the losses (a magnitude that allows casting the
      optimization problem as a minimization one) for the
      given Auto-Sklearn Scorer objects.
  
      Parameters
      ----------
      solution: np.ndarray
          The ground truth of the targets
      prediction: np.ndarray
          The best estimate from the model, of the given targets
      task_type: int
          To understand if the problem task is classification
          or regression
      metrics: Sequence[Scorer]
          A list of objects that hosts a function to calculate how good the
          prediction is according to the solution.
      X_data: Optional[SUPPORTED_XDATA_TYPES]
          X data used to obtain the predictions
      scoring_functions: List[Scorer]
          A list of metrics to calculate multiple losses
  
      Returns
      -------
      Dict[str, float]
          A loss function for each of the provided scorer objects
      """
      score = calculate_scores(
          solution=solution,
          prediction=prediction,
          X_data=X_data,
          task_type=task_type,
          metrics=metrics,
          scoring_functions=scoring_functions,
      )
      scoring_functions = scoring_functions if scoring_functions else []
  
      # we expect a dict() object for which we should calculate the loss
      loss_dict = dict()
      for metric_ in scoring_functions + list(metrics):
          # maybe metric argument is not in scoring_functions
          # TODO: When metrics are annotated with type_of_target support
          # we can remove this check
          if metric_.name not in score:
              continue
          loss_dict[metric_.name] = (
              metric_._optimum - score[metric_.name]
          )
      return loss_dict
  
imports: from abc import ABCMeta, abstractmethod
  from typing import Any, Callable, Dict, List, Optional, Sequence, Union
  import collections
  from functools import partial
  from itertools import product
  import numpy
  import sklearn.metrics
  from sklearn.utils.multiclass import type_of_target
  from smac.utils.constants import MAXINT
  from autosklearn.constants import BINARY_CLASSIFICATION, MULTICLASS_CLASSIFICATION, MULTILABEL_CLASSIFICATION, MULTIOUTPUT_REGRESSION, REGRESSION, REGRESSION_TASKS, TASK_TYPES
  from autosklearn.data.target_validator import SUPPORTED_XDATA_TYPES
  from .util import sanitize_array
label_desc: Use image node_id 5 for calling a global function with example usage: calculate_losses(solution, prediction, task_type, metrics) and returns: loss_dict