Module: Chainer::Functions::Normalization::Calculation
- Included in:
- BatchNormalization, BatchNormalizationGrad, FixedBatchNormalization, FixedBatchNormalizationGrad
- Defined in:
- lib/chainer/functions/normalization/batch_normalization.rb
Instance Method Summary collapse
- #apply_bn_fwd(xp, x, mean, inv_std, gamma, beta) ⇒ Object
- #x_hat(x, mean, inv_std) ⇒ Object
- #zero_if_none(xp, x, shape, dtype) ⇒ Object
Instance Method Details
#apply_bn_fwd(xp, x, mean, inv_std, gamma, beta) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/chainer/functions/normalization/batch_normalization.rb', line 5 def apply_bn_fwd(xp, x, mean, inv_std, gamma, beta) # NOTE: all arguments should be broadcasted to x.shape # (mean, inv_std, gamma, and beta have to already be expanded) x_hat = x_hat(x, mean, inv_std) y = gamma * x_hat y += beta y end |
#x_hat(x, mean, inv_std) ⇒ Object
14 15 16 17 18 |
# File 'lib/chainer/functions/normalization/batch_normalization.rb', line 14 def x_hat(x, mean, inv_std) x_mu = x - mean x_mu *= inv_std x_mu end |
#zero_if_none(xp, x, shape, dtype) ⇒ Object
20 21 22 23 |
# File 'lib/chainer/functions/normalization/batch_normalization.rb', line 20 def zero_if_none(xp, x, shape, dtype) # TODO: Return broadcasted 0 instead of a zeroed array. x.nil? ? dtype.zeros(*shape) : x end |