chainer.functions.normalize¶
-
chainer.functions.
normalize
(x, eps=1e-05, axis=1)[source]¶ Normalize input by L2 norm.
This function implements L2 normalization on a sample along the given axis/axes. No reduction is done along the normalization axis.
In the case when
axis=1
and \(\mathbf{x}\) is a matrix of dimension \((N, K)\), where \(N\) and \(K\) denote mini-batch size and the dimension of the input vectors, this function computes an output matrix \(\mathbf{y}\) of dimension \((N, K)\) by the following equation:\[\mathbf{y}_i = {\mathbf{x}_i \over \| \mathbf{x}_i \|_2 + \epsilon}\]eps
is used to avoid division by zero when norm of \(\mathbf{x}\) along the given axis is zero.The default value of
axis
is determined for backward compatibility.- Parameters
x (
Variable
or N-dimensional array) – multi-dimensional output variable. The first dimension is assumed to be the mini-batch dimension.eps (float) – Epsilon value for numerical stability.
axis (int or tuple of ints) – Axis along which to normalize.
- Returns
The output variable which has the same shape as \(x\).
- Return type