diff options
author | Clement Farabet <clement.farabet@gmail.com> | 2011-08-31 09:54:42 +0400 |
---|---|---|
committer | Clement Farabet <clement.farabet@gmail.com> | 2011-08-31 09:54:42 +0400 |
commit | f97f610a34d2a323b56976186aeacf1a6c7bb6cb (patch) | |
tree | f286290beae78fc21bc429df79775632c39ee383 | |
parent | e2ed5a2b94d52e7ae048e502d768512272a07a36 (diff) |
Using new optimized send/receive functions (mapreduce).
-rw-r--r-- | LBFGSOptimization.lua | 22 | ||||
-rw-r--r-- | lbfgs.c | 12 |
2 files changed, 19 insertions, 15 deletions
diff --git a/LBFGSOptimization.lua b/LBFGSOptimization.lua index f47ccbd..976226d 100644 --- a/LBFGSOptimization.lua +++ b/LBFGSOptimization.lua @@ -43,6 +43,9 @@ function LBFGS:forward_sequential(inputs, targets, options) -- + self.output contains the estimated (average) F(X) lbfgs.evaluate = function() + -- verbose + if self.verbose >= 2 then print('<LBFGSOptimization> evaluating f(X) + df/dX') end + local _t_ = sys.clock() -- reset gradients self.gradParameters:zero() -- f is the average of all criterions @@ -67,6 +70,8 @@ function LBFGS:forward_sequential(inputs, targets, options) end -- normalize gradients self.gradParameters:div(#inputs) + -- verbose + if self.verbose >= 2 then print('<LBFGSOptimization> f(X) + df/dX computed in ' .. (sys.clock() - _t_) .. ' sec') end -- return average f(X) return self.output/#inputs end @@ -91,8 +96,7 @@ function LBFGS:forward_mapreduce(inputs, targets, options) if type(self.prehook) == 'string' then parallel.children:send(self.prehook) else - print('\r<LBFGSOptimization> WARNING: when using para||el mode, hooks should be') - print('\r<LBFGSOptimization> WARNING: defined as strings. User prehook ignored.') + print('\r<LBFGSOptimization> WARNING: when using para||el mode, hooks should be defined as strings. User prehook ignored.') parallel.children:send('') end else @@ -102,8 +106,7 @@ function LBFGS:forward_mapreduce(inputs, targets, options) if type(self.posthook) == 'string' then parallel.children:send(self.posthook) else - print('\r<LBFGSOptimization> WARNING: when using para||el mode, hooks should be') - print('<\rLBFGSOptimization> WARNING: defined as strings. User posthook ignored.') + print('\r<LBFGSOptimization> WARNING: when using para||el mode, hooks should be defined as strings. User posthook ignored.') parallel.children:send('') end else @@ -153,15 +156,18 @@ function LBFGS:forward_mapreduce(inputs, targets, options) -- in separate threads lbfgs.evaluate_map = function() + -- verbose + if self.verbose >= 2 then print('<LBFGSOptimization> evaluating f(X) + df/dX') end + local _t_ = sys.clock() -- transmit new parameters to all workers parallel.children:send(self.parameters) -- then wait for all workers to return their partial gradParameters + outputs - for t = 1,P do - gradParametersPartial[t] = parallel.children[t]:receive() - outputsPartial[t] = parallel.children[t]:receive() - end + gradParametersPartial = parallel.children:receive() + outputsPartial = parallel.children:receive() -- force cleanup collectgarbage() + -- verbose + if self.verbose >= 2 then print('<LBFGSOptimization> f(X) + df/dX computed in ' .. (sys.clock() - _t_) .. ' sec') end end -- (1b) the reduce part of the evaluation: accumulate all @@ -1440,11 +1440,10 @@ static int progress(void *instance, { nIteration = k; if (verbose > 1) { - printf("\n<LBFGSOptimization> iteration %d:\n", nIteration); - printf(" + fx = %f\n", fx); + printf("<LBFGSOptimization> iteration %d:\n", nIteration); + printf(" + f(X) = %f\n", fx); printf(" + xnorm = %f, gnorm = %f, step = %f\n", xnorm, gnorm, step); printf(" + nb evaluations = %d\n", nEvaluation); - printf("\n"); } return 0; } @@ -1477,11 +1476,10 @@ int lbfgs_run(lua_State *L) { // verbose if (verbose) { - printf("\n<LBFGSOptimization> batch optimized after %d iterations\n", nIteration); - printf(" + fx = %f\n", fx); - printf(" + x = [ %f , ... %f]\n",x[0],x[nParameter-1]); + printf("<LBFGSOptimization> batch optimized after %d iterations\n", nIteration); + printf(" + f(X) = %f\n", fx); + printf(" + X = [%f , ... %f]\n",x[0],x[nParameter-1]); printf(" + nb evaluations = %d\n", nEvaluation); - printf("\n"); } // cleanup |