当前位置: 首页>>代码示例>>Python>>正文


Python numpy.minimum方法代码示例

本文整理汇总了Python中jax.numpy.minimum方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.minimum方法的具体用法?Python numpy.minimum怎么用?Python numpy.minimum使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在jax.numpy的用法示例。


在下文中一共展示了numpy.minimum方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from jax import numpy [as 别名]
# 或者: from jax.numpy import minimum [as 别名]
def __init__(self, space, vocab_size, precision=2, max_range=(-100.0, 100.0)):
    self._precision = precision

    # Some gym envs (e.g. CartPole) have unreasonably high bounds for
    # observations. We clip so we can represent them.
    bounded_space = copy.copy(space)
    (min_low, max_high) = max_range
    bounded_space.low = np.maximum(space.low, min_low)
    bounded_space.high = np.minimum(space.high, max_high)
    if (not np.allclose(bounded_space.low, space.low) or
        not np.allclose(bounded_space.high, space.high)):
      logging.warning(
          'Space limits %s, %s out of bounds %s. Clipping to %s, %s.',
          str(space.low), str(space.high), str(max_range),
          str(bounded_space.low), str(bounded_space.high)
      )

    super(BoxSpaceSerializer, self).__init__(bounded_space, vocab_size) 
开发者ID:google,项目名称:trax,代码行数:20,代码来源:space_serializer.py

示例2: clip_eta

# 需要导入模块: from jax import numpy [as 别名]
# 或者: from jax.numpy import minimum [as 别名]
def clip_eta(eta, norm, eps):
  """
  Helper function to clip the perturbation to epsilon norm ball.
  :param eta: A tensor with the current perturbation.
  :param norm: Order of the norm (mimics Numpy).
              Possible values: np.inf or 2.
  :param eps: Epsilon, bound of the perturbation.
  """

  # Clipping perturbation eta to self.norm norm ball
  if norm not in [np.inf, 2]:
    raise ValueError('norm must be np.inf or 2.')

  axis = list(range(1, len(eta.shape)))
  avoid_zero_div = 1e-12
  if norm == np.inf:
    eta = np.clip(eta, a_min=-eps, a_max=eps)
  elif norm == 2:
    # avoid_zero_div must go inside sqrt to avoid a divide by zero in the gradient through this operation
    norm = np.sqrt(np.maximum(avoid_zero_div, np.sum(np.square(eta), axis=axis, keepdims=True)))
    # We must *clip* to within the norm ball, not *normalize* onto the surface of the ball
    factor = np.minimum(1., np.divide(eps, norm))
    eta = eta * factor
  return eta 
开发者ID:tensorflow,项目名称:cleverhans,代码行数:26,代码来源:utils.py

示例3: clipped_objective

# 需要导入模块: from jax import numpy [as 别名]
# 或者: from jax.numpy import minimum [as 别名]
def clipped_objective(probab_ratios, advantages, reward_mask, epsilon=0.2):
  return np.minimum(
      probab_ratios * advantages,
      clipped_probab_ratios(probab_ratios, epsilon=epsilon) *
      advantages) * reward_mask 
开发者ID:yyht,项目名称:BERT,代码行数:7,代码来源:ppo.py

示例4: _min

# 需要导入模块: from jax import numpy [as 别名]
# 或者: from jax.numpy import minimum [as 别名]
def _min(x, y):
    return np.minimum(x, y)


# TODO: replace (int, float) by object 
开发者ID:pyro-ppl,项目名称:funsor,代码行数:7,代码来源:ops.py

示例5: limiter

# 需要导入模块: from jax import numpy [as 别名]
# 或者: from jax.numpy import minimum [as 别名]
def limiter(cr):
    return np.maximum(0., np.maximum(np.minimum(1., 2 * cr), np.minimum(2., cr))) 
开发者ID:dionhaefner,项目名称:pyhpc-benchmarks,代码行数:4,代码来源:tke_jax.py


注:本文中的jax.numpy.minimum方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。