code: def internal2external_grad(xi, bounds):
      
  
      ge = np.empty_like(xi)
  
      for i, (v, bound) in enumerate(zip(xi, bounds)):
  
          a = bound[0]  # minimum
          b = bound[1]  # maximum
  
          if a == None and b == None:  # No constraints
              ge[i] = 1.0
  
          elif b == None:  # only min
              ge[i] = v / np.sqrt(v ** 2 + 1)
  
          elif a == None:  # only max
              ge[i] = -v / np.sqrt(v ** 2 + 1)
  
          else:  # both min and max
              ge[i] = (b - a) * np.cos(v) / 2.
  
      return ge
docs: Calculate the internal to external gradiant
      
      Calculates the partial of external over internal