Python jax.numpy.minimum() Examples
The following are 5
code examples of jax.numpy.minimum().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
jax.numpy
, or try the search function
.
![](https://www.programcreek.com/common/static/images/search.png)
Example #1
Source File: space_serializer.py From trax with Apache License 2.0 | 6 votes |
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)
Example #2
Source File: utils.py From cleverhans with MIT License | 6 votes |
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
Example #3
Source File: ppo.py From BERT with Apache License 2.0 | 5 votes |
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
Example #4
Source File: ops.py From funsor with Apache License 2.0 | 5 votes |
def _min(x, y): return np.minimum(x, y) # TODO: replace (int, float) by object
Example #5
Source File: tke_jax.py From pyhpc-benchmarks with The Unlicense | 5 votes |
def limiter(cr): return np.maximum(0., np.maximum(np.minimum(1., 2 * cr), np.minimum(2., cr)))