class_docstr: Class defining mutations, and holding a random state used for random generation.
class_docstr_tok: ["Class","defining","mutations",",","and","holding","a","random","state","used","for","random","generation","."]
docstr: Mutation discussed in
  https://arxiv.org/pdf/1606.05551v1.pdf
  We mutate a randomly drawn number of variables on average.
  The mutation is the same for all variables - coordinatewise mutation will be different from this point of view and will make it possible
  to do anisotropic mutations.
docstr_tok: ["Mutation","discussed","in","https",":","\/\/arxiv.org\/pdf\/1606.05551v1.pdf","We","mutate","a","randomly","drawn","number","of","variables","on","average",".","The","mutation","is","the","same","for","all","variables","-","coordinatewise","mutation","will","be","different","from","this","point","of","view","and","will","make","it","possible","to","do","anisotropic","mutations","."]
code: def portfolio_discrete_mutation(
      self,
      parent: tp.ArrayLike,
      intensity: tp.Optional[int] = None,
      arity: int = 2,
  ) -> tp.ArrayLike:
      """Mutation discussed in
      https://arxiv.org/pdf/1606.05551v1.pdf
      We mutate a randomly drawn number of variables on average.
      The mutation is the same for all variables - coordinatewise mutation will be different from this point of view and will make it possible
      to do anisotropic mutations.
      """
      dimension = len(parent)
      if intensity is None:
          intensity = (
              1
              if dimension == 1
              else int(self.random_state.randint(1, dimension))
          )
      if dimension == 1:  # corner case.
          return self.random_state.normal(0.0, 1.0, size=1)  # type: ignore
      boolean_vector = np.ones(dimension, dtype=bool)
      while all(boolean_vector) and dimension != 1:
          boolean_vector = (
              self.random_state.rand(dimension)
              > float(intensity) / dimension
          )
      result = [
          s if b else self.significantly_mutate(s, arity)
          for (b, s) in zip(boolean_vector, parent)
      ]
      return result
  
file_path: nevergrad/nevergrad/optimization/mutations.py
imports: import numpy
  import nevergrad.common.typing
  from nevergrad.parametrization import discretization
  from .None import utils
label_desc: Use image node_id 6 for calling the Mutator obj's underlying member method code with example usage: obj.portfolio_discrete_mutation(parent, intensity, arity) and returns: result, self