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

LBFGSOptimization.lua - github.com/clementfarabet/lua---nnx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ad9813902ac9fc03ba851f7f8750243a6e991ab9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
local LBFGS,parent = torch.class('nn.LBFGSOptimization', 'nn.BatchOptimization')

function LBFGS:__init(...)
   require 'liblbfgs'
   parent.__init(self, ...)
   xlua.unpack_class(self, {...},
      'LBFGSOptimization', nil,
      {arg='maxEvaluation', type='number', 
       help='maximum nb of function evaluations per pass (0 = no max)', default=0},
      {arg='maxIterations', type='number', 
       help='maximum nb of iterations per pass (0 = no max)', default=0},
      {arg='maxLineSearch', type='number', 
       help='maximum nb of steps in line search', default=20},
      {arg='sparsity', type='number', 
       help='sparsity coef (Orthantwise C)', default=0},
      {arg='parallelize', type='number', 
       help='parallelize onto N cores (experimental!)', default=1}
   )
   self.parameters = nnx.flattenParameters(nnx.getParameters(self.module))
   self.gradParameters = nnx.flattenParameters(nnx.getGradParameters(self.module))
end

function LBFGS:optimize()
   lbfgs.evaluate = self.evaluate
   -- the magic function: will update the parameter vector
   -- according to the l-BFGS method
   self.output = lbfgs.run(self.parameters, self.gradParameters,
                           self.maxEvaluation, self.maxIterations, self.maxLineSearch,
                           self.sparsity, self.verbose)
end