code: def _get_score_from_eval_stats_history(
      eval_stats_history, agg="last", target="eval_score"
  ):
      """Get a scalar score from a list of evaluation statistics dicts."""
      final_score = None
      if agg == "last":
          for stats in reversed(eval_stats_history):
              if target in stats:
                  final_score = stats[target]
                  break
      elif agg == "mean":
          scores = []
          for stats in eval_stats_history:
              if target in stats:
                  score = stats[target]
                  if score is not None:
                      scores.append(score)
          final_score = sum(scores) / len(scores)
      elif agg == "best":
          scores = []
          for stats in eval_stats_history:
              if target in stats:
                  score = stats[target]
                  if score is not None:
                      scores.append(score)
          final_score = max(scores)  # Assuming larger is better
      else:
          raise ValueError("Unknown agg method: {}".format(agg))
  
      if final_score is None:
          final_score = float("NaN")
      return final_score
  
file_path: pfrl/examples/optuna/optuna_dqn_obs1d.py
imports: import argparse
  import logging
  import os
  import random
  import gym
  import torch.optim
  import pfrl
  from pfrl import experiments, explorers, q_functions, replay_buffers, utils
  from pfrl.agents.dqn import DQN
  from pfrl.experiments.evaluation_hooks import OptunaPrunerHook
  from pfrl.nn.mlp import MLP
label_desc: Use image node_id 2 for calling a global function with example usage: _get_score_from_eval_stats_history(eval_stats_history, agg, target) and returns: final_score