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

github.com/torch/optim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClement Farabet <clement.farabet@gmail.com>2012-01-22 04:12:48 +0400
committerClement Farabet <clement.farabet@gmail.com>2012-01-22 04:12:48 +0400
commitfc1f65f02a81ed471932b28e741f6158aa75fa6c (patch)
treecdd478c9077ed09de09db6275002251e5b472eea /lbfgs.lua
parentce54b935208e27ee9ded6f7d55a3bd3caf7df12a (diff)
L-BFGS now works in stochastic mode.
Diffstat (limited to 'lbfgs.lua')
-rw-r--r--lbfgs.lua31
1 files changed, 21 insertions, 10 deletions
diff --git a/lbfgs.lua b/lbfgs.lua
index cb53cd0..1efb118 100644
--- a/lbfgs.lua
+++ b/lbfgs.lua
@@ -195,11 +195,16 @@ function optim.lbfgs(opfunc, x, state)
f,g,x,t,lsFuncEval = lineSearch(opfunc,x,t,d,f,g,gtd,c1,c2,tolX)
append(f_hist, f)
else
- -- no line search, simply move with fixed-step and re-evaluate f(x)
+ -- no line search, simply move with fixed-step
x:add(t,d)
- f,g = opfunc(x)
- lsFuncEval = 1
- append(f_hist, f)
+ if nIter ~= maxIter then
+ -- re-evaluate function only if not in last iteration
+ -- the reason we do this: in a stochastic setting,
+ -- no use to re-evaluate that function here
+ f,g = opfunc(x)
+ lsFuncEval = 1
+ append(f_hist, f)
+ end
end
-- update func eval
@@ -209,6 +214,18 @@ function optim.lbfgs(opfunc, x, state)
------------------------------------------------------------
-- check conditions
------------------------------------------------------------
+ if nIter == maxIter then
+ -- no use to run tests
+ verbose('reached max number of iterations')
+ break
+ end
+
+ if currentFuncEval >= maxEval then
+ -- max nb of function evals
+ verbose('max nb of function evals')
+ break
+ end
+
tmp1:copy(g):abs()
if tmp1:sum() <= tolFun then
-- check optimality
@@ -228,12 +245,6 @@ function optim.lbfgs(opfunc, x, state)
verbose('function value changing less than tolX')
break
end
-
- if currentFuncEval >= maxEval then
- -- max nb of function evals
- verbose('max nb of function evals')
- break
- end
end
-- save state