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:
authorSoumith Chintala <soumith@gmail.com>2015-02-15 15:56:30 +0300
committerSoumith Chintala <soumith@gmail.com>2015-02-15 15:56:30 +0300
commit3fc3e48f767211222dc6a7ae22b9135e1ad596ac (patch)
tree5389c02633fd97af56a45f17757f760243e43f5a /test.lua
parent71ee0baa4b2f4998be11aae1b8fbe8b68bad271c (diff)
parent95f414533c86defc499983e99c0e8391cfbd8e7f (diff)
Merge pull request #165 from szagoruyko/prelu
Parametric ReLU
Diffstat (limited to 'test.lua')
-rw-r--r--test.lua64
1 files changed, 64 insertions, 0 deletions
diff --git a/test.lua b/test.lua
index 0bd7ad2..9604aac 100644
--- a/test.lua
+++ b/test.lua
@@ -262,6 +262,70 @@ function nntest.Threshold()
mytester:asserteq(berr, 0, torch.typename(module) .. ' - i/o backward err ')
end
+function nntest.PReLU()
+ local ini = math.random(3,5)
+ local input = torch.Tensor(ini):zero()
+
+ local module = nn.PReLU(ini)
+
+ -- 1D
+ local err = jac.testJacobian(module,input)
+ mytester:assertlt(err,precision, 'error on state ')
+
+ local err = jac.testJacobianParameters(module, input, module.weight, module.gradWeight)
+ mytester:assertlt(err,precision, 'error on weight ')
+
+ local err = jac.testJacobianUpdateParameters(module, input, module.weight)
+ mytester:assertlt(err,precision, 'error on weight [direct update] ')
+
+ for t,err in pairs(jac.testAllUpdate(module, input, 'weight', 'gradWeight')) do
+ mytester:assertlt(err, precision, string.format(
+ 'error on weight [%s]', t))
+ end
+
+ -- 2D
+ local nframe = math.random(1,7)
+ local input = torch.Tensor(nframe, ini):zero()
+
+ local err = jac.testJacobian(module,input)
+ mytester:assertlt(err,precision, 'error on state ')
+
+ local err = jac.testJacobianParameters(module, input, module.weight, module.gradWeight)
+ mytester:assertlt(err,precision, 'error on weight ')
+
+ local err = jac.testJacobianUpdateParameters(module, input, module.weight)
+ mytester:assertlt(err,precision, 'error on weight [direct update] ')
+
+ for t,err in pairs(jac.testAllUpdate(module, input, 'weight', 'gradWeight')) do
+ mytester:assertlt(err, precision, string.format(
+ 'error on weight [%s]', t))
+ end
+
+ -- 4D
+ local nframe = math.random(1,7)
+ local kW, kH = math.random(1,8), math.random(1,8)
+ local input = torch.Tensor(nframe, ini, kW, kH):zero()
+
+ local err = jac.testJacobian(module,input)
+ mytester:assertlt(err,precision, 'error on state ')
+
+ local err = jac.testJacobianParameters(module, input, module.weight, module.gradWeight)
+ mytester:assertlt(err,precision, 'error on weight ')
+
+ local err = jac.testJacobianUpdateParameters(module, input, module.weight)
+ mytester:assertlt(err,precision, 'error on weight [direct update] ')
+
+ for t,err in pairs(jac.testAllUpdate(module, input, 'weight', 'gradWeight')) do
+ mytester:assertlt(err, precision, string.format(
+ 'error on weight [%s]', t))
+ end
+
+ -- IO
+ 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
+
function nntest.HardShrink()
local ini = math.random(3,5)
local inj = math.random(3,5)