|View source on GitHub
Generates a random sample in a norm ball, conforming the given structure.
tensor_structure, radius, norm_type
This function expects
tensor_structure to represent a batch of examples,
where the tensors in the structure are features. The norms are calculated in
the whole feature space (including all tensors).
For L-inf norm, each feature dimension can be sampled independently from a
uniform distribution. For L2 and L1 norms, we use the result (Corollary 4 in
Barthe et al., 2005) that the first
n coordinates of a uniformly random
point on the
p-norm unit sphere in
R^(n+p) are uniformly distributed in
p-norm unit ball in
R^n. For L2 norm, we draw random points on the
unit sphere from the standard normal distribution which density is
exp(-x^2)(Corollary 1 in Harman and Lacko, 2010). For L1
norm, we draw random points on the 1-norm unit sphere from the standard
Laplace distribution which density is proportional to
details on the papers: https://arxiv.org/abs/math/0503650 and
|A (nested) collection of batched, floating-point tensors. Only the structure (number of tensors, shape, and dtype) is used, not the values. The first dimension of each tensor is the batch size and must all be equal.
|The radius of the norm ball to sample from.
nsl.configs.NormType which specifies the norm of the
A (nested) collection of tensors in the same structure as
but has its values drawn randomly. The norm of each example in the batch
is less than or equal to the given radius.