Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/torch/nn.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkarpathy <andrej.karpathy@gmail.com>2015-05-06 00:55:07 +0300
committerSoumith Chintala <soumith@gmail.com>2015-05-13 07:50:22 +0300
commit905ea8c1a4033af2af0f90e92e16597f442f3512 (patch)
tree206d026415810a399d9db96c75a8625a46b6f11c /test.lua
parent28b0d2a80f302e39876002a3978bb4f70c4ee171 (diff)
Adding Batch L2 Normalization Layer that makes all rows of input Tensor unit L2 norm
Diffstat (limited to 'test.lua')
-rw-r--r--test.lua23
1 files changed, 23 insertions, 0 deletions
diff --git a/test.lua b/test.lua
index 9414a66..959c369 100644
--- a/test.lua
+++ b/test.lua
@@ -3554,6 +3554,29 @@ function nntest.Padding()
mytester:assertTensorEq(gradInput, input, 0.00001, "Padding backward error")
end
+function nntest.L2Normalize()
+ local ini = math.random(6,8)
+ local inj = math.random(3,5)
+ local input = torch.randn(ini, inj)
+
+ local module = nn.L2Normalize()
+
+ -- test correctness of output
+ local output = module:forward(input)
+ local norms = torch.norm(output, 2, 2)
+ local desired_norms = torch.ones(ini)
+ mytester:assertTensorEq(norms, desired_norms, 0.000001, 'L2Normalize forward err')
+
+ -- test the Jacobian
+ local err = jac.testJacobian(module,input)
+ mytester:assertlt(err, precision, 'error on state ')
+
+ -- test IO correctness
+ local ferr, berr = jac.testIO(module,input)
+ mytester:asserteq(ferr, 0, torch.typename(module) .. ' - i/o forward err ')
+ mytester:asserteq(berr, 0, torch.typename(module) .. ' - i/o backward err ')
+end
+
mytester:add(nntest)
if not nn then