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: Transforms a logit into an int obtained through softmax.
docstr_tok: ["Transforms","a","logit","into","an","int","obtained","through","softmax","."]
code: def discretize(self, a, env):
      """Transforms a logit into an int obtained through softmax."""
      if len(self.arities) > 0:
          if self.control == "conformant":
              index = 0
              output = []
              for arities in self.arities:
                  local_output = []
                  for arity in arities:
                      local_output += [
                          min(
                              int(
                                  scipy.stats.norm.cdf(a[index]) * arity
                              ),
                              arity - 1,
                          )
                      ]
                      index += 1
                  output += [local_output]
              assert index == len(a)
              return np.array(output)
          else:
              index = 0
              output = []
              for arities in self.arities:
                  local_output = []
                  for arity in arities:
                      local_output += [
                          int(
                              list(
                                  np.random.multinomial(
                                      1,
                                      self.softmax(
                                          a[index : index + arity]
                                      ),
                                  )
                              ).index(1)
                          )
                      ]
                      index += arity
                  output += [local_output]
              assert index == len(a)
              return np.array(output)
  
      if self.greedy_bias:
          a = np.asarray(a, dtype=np.float32)
          for i, action in enumerate(range(len(a))):
              tmp_env = copy.deepcopy(env)
              _, r, _, _ = tmp_env.step(action)
              a[i] += self.greedy_coefficient * r
      probabilities = self.softmax(a)
      assert (
          sum(probabilities) <= 1.0 + 1e-7
      ), f"{probabilities} with greediness {self.greedy_coefficient}."
      return int(list(np.random.multinomial(1, probabilities)).index(1))
  
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 7 for calling the GymMulti obj's underlying member method code with example usage: obj.discretize(a, env) and returns: int, np, np