class_docstr: Class for converting a gym environment, a controller style, and others into a black-box optimization benchmark.
class_docstr_tok: ["Class","for","converting","a","gym","environment",",","a","controller","style",",","and","others","into","a","black-box","optimization","benchmark","."]
docstr: Averages multiple evaluations if necessary.
docstr_tok: ["Averages","multiple","evaluations","if","necessary","."]
code: def evaluation_function(self, *recommendations) -> float:
      """Averages multiple evaluations if necessary."""
      if (
          self.sparse_limit is None
      ):  # Life is simple here, we directly have the weights.
          x = recommendations[0].value
      else:  # Here 0 in the enablers means that the weight is forced to 0.
          # assert np.prod(recommendations[0].value["weights"].shape) == np.prod(recommendations[0].value["enablers"].shape)
          weights = recommendations[0].kwargs["weights"]
          enablers = np.asarray(recommendations[0].kwargs["enablers"])
          assert all(
              x_ in [0, 1] for x_ in enablers
          ), f"non-binary enablers: {enablers}."
          enablers = enablers.reshape(weights.shape)
          x = weights * enablers
      if not self.randomized:
          return self.gym_multi_function(x, limited_fidelity=False)
      # We want to reduce noise by averaging without
      # spending more than 20% of the whole experiment,
      # hence the line below:
      num = max(self.num_calls // 5, 23)
      # Pb_index >= 0 refers to the test set.
      return (
          np.sum(
              [
                  self.gym_multi_function(x, limited_fidelity=False)
                  for _ in range(num)
              ]
          )
          / num
      )
  
imports: import os
  import copy
  import scipy.stats
  import typing
  import numpy
  import gym
  import nevergrad
  from nevergrad.parametrization import parameter
  from ..base import ExperimentFunction
label_desc: Use image node_id 5 for calling the GymMulti obj's underlying member method code with example usage: obj.evaluation_function() and returns: unknown, self