<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/neural-structured-learning/blob/v1.4.0/neural_structured_learning/lib/utils.py#L212-L283) |

Solves the maximization problem weights\^T\*x with the constraint norm(x)=1.

    nsl.lib.maximize_within_unit_norm(
        weights, norm_type, epsilon=1e-06
    )

This op solves a batch of maximization problems at one time. The first axis of
`weights` is assumed to be the batch dimension, and each "row" is treated as
an independent maximization problem.

This op is mainly used to generate adversarial examples (e.g., FGSM proposed
by Goodfellow et al.). Specifically, the `weights` are gradients, and `x` is
the adversarial perturbation. The desired perturbation is the one causing the
largest loss increase. In this op, the loss increase is approximated by the
dot product between the gradient and the perturbation, as in the first-order
Taylor approximation of the loss function.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `weights` | A `Tensor` or a collection of `Tensor` objects representing a batch of weights to define the maximization objective. If this is a collection, the first dimension of all `Tensor` objects should be the same (i.e. batch size). |
| `norm_type` | One of [`nsl.configs.NormType`](https://www.tensorflow.org/neural_structured_learning/api_docs/python/nsl/configs/NormType), the type of the norm in the constraint. |
| `epsilon` | A lower bound value for the norm to avoid division by 0. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A `Tensor` or a collection of `Tensor` objects (with the same structure and shape as `weights`) representing a batch of adversarial perturbations as the solution to the maximization problems. ||

<br />