diff options
author | koray kavukcuoglu <koray@kavukcuoglu.org> | 2011-10-02 17:22:18 +0400 |
---|---|---|
committer | koray kavukcuoglu <koray@kavukcuoglu.org> | 2011-10-02 17:22:18 +0400 |
commit | b3fb44439ab431bb66ab258c91644888ce992844 (patch) | |
tree | bfffe88aafbcb34ff62a4a6edac0daca4ded7fd8 | |
parent | b97099b3253362dc2c14994e4783a731e2eb1afb (diff) |
corrected tests for lbfgs and cg. lbfgs.c uses global gradParameters, we shouldn't override them at each function call
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | test/l2.lua | 21 | ||||
-rw-r--r-- | test/rosenbrock.lua | 5 | ||||
-rw-r--r-- | test/test-all.lua | 28 | ||||
-rw-r--r-- | test/test_cg.lua | 9 | ||||
-rw-r--r-- | test/test_lbfgs.lua | 7 |
6 files changed, 37 insertions, 35 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 52e3acd..01eb717 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -90,7 +90,7 @@ install_files(${INSTALL_PREFIX} Sqrt.lua) install_files(${INSTALL_PREFIX} Threshold.lua) install_files(${INSTALL_PREFIX} OmpModule.lua) install_files(${INSTALL_PREFIX} SpatialClassifier.lua) -install_files(${INSTALL_PREFIX} SpatialMaxPooling.lua) +install_files(${INSTALL_PREFIX} SpatialMaxSampling.lua) install_files(${INSTALL_PREFIX} SpatialLinear.lua) install_files(${INSTALL_PREFIX} SpatialPadding.lua) install_files(${INSTALL_PREFIX} SpatialNormalization.lua) diff --git a/test/l2.lua b/test/l2.lua new file mode 100644 index 0000000..671ab51 --- /dev/null +++ b/test/l2.lua @@ -0,0 +1,21 @@ +require 'torch' +-- rosenbrock.m This function returns the function value, partial derivatives +-- and Hessian of the (general dimension) rosenbrock function, given by: +-- +-- f(x) = sum_{i=1:D-1} 100*(x(i+1) - x(i)^2)^2 + (1-x(i))^2 +-- +-- where D is the dimension of x. The true minimum is 0 at x = (1 1 ... 1). +-- +-- Carl Edward Rasmussen, 2001-07-21. + +function l2(x,dx) + + local xx = x:clone() + xx:cmul(xx) + local fout = xx:sum() + + dx:copy(x) + dx:mul(2) + return fout,dx + +end
\ No newline at end of file diff --git a/test/rosenbrock.lua b/test/rosenbrock.lua index 572e8a5..20d1f2f 100644 --- a/test/rosenbrock.lua +++ b/test/rosenbrock.lua @@ -8,7 +8,7 @@ require 'torch' -- -- Carl Edward Rasmussen, 2001-07-21. -function rosenbrock(x) +function rosenbrock(x,dx) -- (1) compute f(x) local d = x:size(1) @@ -45,6 +45,7 @@ function rosenbrock(x) x0:cmul(x0):mul(-1):add(x:narrow(1,2,d-1)):mul(200) dxout:narrow(1,2,d-1):add(x0) - return fout,dxout + dx:copy(dxout) + return fout,dx end
\ No newline at end of file diff --git a/test/test-all.lua b/test/test-all.lua index d0b071d..00da016 100644 --- a/test/test-all.lua +++ b/test/test-all.lua @@ -92,23 +92,6 @@ function nnxtest.SpatialUpSampling() mytester:asserteq(berr, 0, torch.typename(module) .. ' - i/o backward err ') end -function nnxtest.SpatialMaxSampling() - local fanin = math.random(1,4) - local sizex = math.random(1,16) - local sizey = math.random(1,16) - local osizex = math.random(2,8) - local osizey = math.random(2,8) - local module = nn.SpatialMaxSampling(osizex,osizey) - local input = lab.rand(fanin,sizey,sizex) - - local err = nn.Jacobian.testJacobian(module, input) - mytester:assertlt(err, precision, 'error on state ') - - local ferr, berr = nn.Jacobian.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 nnxtest.SpatialReSampling_1() local fanin = math.random(1,4) local sizex = math.random(4,8) @@ -383,19 +366,10 @@ function nnxtest.SpatialGraph_3() template_SpatialGraph(256, 2, 2, 'euclid', fal function nnxtest.SpatialGraph_4() template_SpatialGraph(2, 16, 16, 'cosine', false) end function nnxtest.SpatialGraph_5() template_SpatialGraph(64, 3, 3, 'cosine', false) end -if not nnx then - require 'nnx' +function nnx.test() xlua.require('image',true) mytester = torch.Tester() mytester:add(nnxtest) math.randomseed(os.time()) mytester:run() -else - function nnx.test() - xlua.require('image',true) - mytester = torch.Tester() - mytester:add(nnxtest) - math.randomseed(os.time()) - mytester:run() - end end diff --git a/test/test_cg.lua b/test/test_cg.lua index 5dc5b37..3803628 100644 --- a/test/test_cg.lua +++ b/test/test_cg.lua @@ -1,17 +1,20 @@ dofile('rosenbrock.lua') +dofile('l2.lua') require 'liblbfgs' neval = 0 maxIterations = 100 maxLineSearch = 40 -linesearch = 2 +linesearch = 0 momentum = 0 verbose = 2 nparam = 2 +local testfunc = rosenbrock local parameters = torch.Tensor(nparam):fill(0.1) +local gradParameters = torch.Tensor(nparam):zero() -output, gradParameters = rosenbrock(parameters) +output, gradParameters = testfunc(parameters,gradParameters) function printstats () print('nEval: '..neval) @@ -32,7 +35,7 @@ print('Starting:') printstats() lbfgs.evaluate = function() - output, gradParameters = rosenbrock(parameters) + output, gradParameters = testfunc(parameters,gradParameters) neval = neval + 1 printstats() return output diff --git a/test/test_lbfgs.lua b/test/test_lbfgs.lua index 88e5b9a..f882361 100644 --- a/test/test_lbfgs.lua +++ b/test/test_lbfgs.lua @@ -1,4 +1,5 @@ dofile('rosenbrock.lua') +dofile('l2.lua') require 'liblbfgs' neval = 0 @@ -8,10 +9,12 @@ linesearch = 2 sparsity = 0 verbose = 2 nparam = 8 +local testfunc = rosenbrock local parameters = torch.Tensor(nparam):fill(0.1) +local gradParameters = torch.Tensor(nparam):zero() -output, gradParameters = rosenbrock(parameters) +output, gradParameters = testfunc(parameters,gradParameters) function printstats () print('nEval: '..neval) @@ -32,7 +35,7 @@ print('Starting:') printstats() lbfgs.evaluate = function() - output, gradParameters = rosenbrock(parameters) + output, gradParameters = testfunc(parameters,gradParameters) neval = neval + 1 printstats() return output |