class_docstr: Computes the mean average precision (mAP) over different tasks.
class_docstr_tok: ["Computes","the","mean","average","precision","(","mAP",")","over","different","tasks","."]
code: def compute(self):
      # Matches the official OGB evaluation scheme for mean average precision.
      values = super().compute()
      labels = values["labels"]
      logits = values["logits"]
      mask = values["mask"]
  
      assert logits.shape == labels.shape == mask.shape
      assert len(logits.shape) == 2
  
      probs = jax.nn.sigmoid(logits)
      num_tasks = labels.shape[1]
      average_precisions = np.full(num_tasks, np.nan)
  
      for task in range(num_tasks):
          # AP is only defined when there is at least one negative data
          # and at least one positive data.
          is_labeled = mask[:, task]
          if len(np.unique(labels[is_labeled, task])) >= 2:
              average_precisions[
                  task
              ] = sklearn.metrics.average_precision_score(
                  labels[is_labeled, task], probs[is_labeled, task]
              )
  
      # When all APs are NaNs, return NaN. This avoids raising a RuntimeWarning.
      if np.isnan(average_precisions).all():
          return np.nan
      return np.nanmean(average_precisions)
  
imports: import os
  from typing import Any, Dict, Iterable, Tuple, Optional
  from absl import logging
  from clu import checkpoint
  from clu import metric_writers
  from clu import metrics
  from clu import parameter_overview
  from clu import periodic_actions
  import flax
  import flax.core
  import flax.linen
  from flax.training import train_state
  import jax
  import jax.numpy
  import jraph
  import ml_collections
  import numpy
  import optax
  import sklearn.metrics
  import tensorflow
  import input_pipeline
  import models
label_desc: Use image node_id 1 for calling the MeanAveragePrecision obj's underlying member method code with example usage: obj.compute() and returns: np, np