code: def expected_metrics(
      dataset_regex: Optional[str],
      max_triples: Optional[int],
      min_triples: Optional[int],
      log_level: str,
      samples: int,
      force: bool,
      output_directory: pathlib.Path,
  ):
      """Compute expected metrics for all datasets (matching the given pattern)."""
      logging.getLogger("pykeen").setLevel(level=log_level)
      df_data: List[Tuple[str, str, str, str, float]] = []
      for dataset_name, dataset_instance in iter_dataset_instances(
          regex_name_filter=dataset_regex,
          max_triples=max_triples,
          min_triples=min_triples,
      ):
          adjustments_directory = output_directory.joinpath(
              dataset_name, "adjustments"
          )
          adjustments_directory.mkdir(parents=True, exist_ok=True)
          expected_metrics_path = adjustments_directory.joinpath(
              "expected_metrics.json"
          )
          if expected_metrics_path.is_file() and not force:
              expected_metrics_dict = json.loads(
                  expected_metrics_path.read_text()
              )
          else:
              expected_metrics_dict = dict()
              for key, factory in dataset_instance.factory_dict.items():
                  if key == "training":
                      additional_filter_triples = None
                  elif key == "validation":
                      additional_filter_triples = (
                          dataset_instance.training.mapped_triples
                      )
                  elif key == "testing":
                      additional_filter_triples = [
                          dataset_instance.training.mapped_triples,
                      ]
                      if dataset_instance.validation is None:
                          click.echo(
                              f"WARNING: {dataset_name} does not have validation triples!"
                          )
                      else:
                          additional_filter_triples.append(
                              dataset_instance.validation.mapped_triples
                          )
                  else:
                      raise AssertionError(key)
                  df = get_candidate_set_size(
                      mapped_triples=factory.mapped_triples,
                      additional_filter_triples=additional_filter_triples,
                  )
                  output_path = adjustments_directory.joinpath(
                      f"{key}_candidates.tsv.gz"
                  )
                  df.to_csv(output_path, sep="\t", index=False)
                  tqdm.write(f"wrote {output_path}")
  
                  # expected metrics
                  ks = (1, 3, 5, 10) + tuple(
                      10**i
                      for i in range(
                          2,
                          int(
                              math.ceil(
                                  math.log(
                                      dataset_instance.num_entities
                                  )
                              )
                          ),
                      )
                  )
                  metrics = [
                      ArithmeticMeanRank(),
                      *(HitsAtK(k) for k in ks),
                      InverseHarmonicMeanRank(),
                      # Needs simulation
                      InverseArithmeticMeanRank(),
                      HarmonicMeanRank(),
                      GeometricMeanRank(),
                      InverseGeometricMeanRank(),
                      MedianRank(),
                      InverseMedianRank(),
                  ]
                  this_metrics: MutableMapping[
                      ExtendedTarget, Mapping[str, float]
                  ] = dict()
                  for label, sides in SIDE_MAPPING.items():
                      num_candidates = df[
                          [f"{side}_candidates" for side in sides]
                      ].values.ravel()
                      this_metrics[label] = {
                          metric.key: metric.expected_value(
                              num_candidates=num_candidates,
                              num_samples=samples,
                          )
                          for metric in metrics
                      }
                  expected_metrics_dict[key] = this_metrics
              with expected_metrics_path.open("w") as file:
                  json.dump(
                      expected_metrics_dict,
                      file,
                      sort_keys=True,
                      indent=4,
                  )
              tqdm.write(f"wrote {expected_metrics_path}")
  
          df_data.extend(
              (dataset_name, metric, side, part, value)
              for part, level1 in expected_metrics_dict.items()
              for side, level2 in level1.items()
              for metric, value in level2.items()
          )
      df = (
          pd.DataFrame(
              df_data,
              columns=["dataset", "metric", "side", "split", "value"],
          )
          .sort_values(
              by=["dataset", "metric", "side", "split"],
          )
          .reset_index(drop=True)
      )
      results_path = output_directory.joinpath(
          "metric_adjustments.tsv.gz"
      )
      df.to_csv(results_path, sep="\t", index=False)
      click.secho(f"wrote to {results_path}", fg="green")
  
      if (
          max_triples is None
          and min_triples is None
          and dataset_regex is None
      ):
          try:
              from zenodo_client import update_zenodo
          except ImportError:
              click.secho(
                  "Unable to import `zenodo_client`. Not uploading results",
                  fg="red",
              )
          else:
              zenodo_record = "6331629"
              # See https://zenodo.org/record/6331629
              rv = update_zenodo(zenodo_record, results_path)
              click.secho(
                  f"Updated Zenodo record {zenodo_record}: {rv}",
                  fg="green",
              )
  
imports: import itertools
  import json
  import logging
  import math
  import pathlib
  from textwrap import dedent
  from typing import Iterable, List, Mapping, MutableMapping, Optional, Tuple, Union
  import click
  import docdata
  import pandas
  import scipy.stats
  from more_click import force_option, log_level_option, verbose_option
  from tqdm import tqdm
  from tqdm.contrib.logging import logging_redirect_tqdm
  from .base import Dataset
  from .utils import dataset_regex_option, iter_dataset_instances, max_triples_option, min_triples_option
  from ..constants import COLUMN_LABELS, PYKEEN_DATASETS
  from ..evaluation.evaluator import get_candidate_set_size
  from ..metrics.ranking import ArithmeticMeanRank, GeometricMeanRank, HarmonicMeanRank, HitsAtK, InverseArithmeticMeanRank, InverseGeometricMeanRank, InverseHarmonicMeanRank, InverseMedianRank, MedianRank
  from ..triples import CoreTriplesFactory
  from ..typing import LABEL_HEAD, LABEL_RELATION, LABEL_TAIL, SIDE_MAPPING, ExtendedTarget
label_desc: Use image node_id 7 for calling a global function with example usage: expected_metrics(dataset_regex, max_triples, min_triples, log_level, samples, force, output_directory) without return types