本文整理汇总了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)
示例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
示例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
示例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
示例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)))