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","."]
code: def sparse_gym_multi_function(
      self,
      weights: np.ndarray,
      enablers: np.ndarray,
      limited_fidelity: bool = False,
  ) -> float:
      assert all(x_ in [0, 1] for x_ in enablers)
      x = weights * enablers
      loss = self.gym_multi_function(
          x,
          limited_fidelity=limited_fidelity,
      )
      sparse_penalty = 0
      if (
          self.sparse_limit is not None
      ):  # Then we penalize the weights above the threshold "sparse_limit".
          sparse_penalty = (1 + np.abs(loss)) * max(
              0, np.sum(enablers) - self.sparse_limit
          )
      return loss + sparse_penalty
  
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 9 for calling the GymMulti obj's underlying member method code with example usage: obj.sparse_gym_multi_function(weights, enablers, limited_fidelity) and returns: unknown