atomicrex  0.1
An advanced atomistic model building tool
LBFGSMinimizer.h
1 //
3 // Copyright (C) 2017, Alexander Stukowski and Paul Erhart
4 //
5 // This file is part of atomicrex.
6 //
7 // Atomicrex is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // Atomicrex is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 //
21 
22 #pragma once
23 
24 #include "../Atomicrex.h"
25 #include "Minimizer.h"
26 
27 namespace atomicrex {
28 
29 class LBFGSMinimizer : public Minimizer
30 {
31 public:
32 
35 
49  virtual void prepare(
50  std::vector<double>&& x0,
51  const std::function<double(const std::vector<double>&)>& func,
52  const std::function<double(const std::vector<double>&, std::vector<double>&)>& gradient = std::function<double(const std::vector<double>&, std::vector<double>&)>()) override;
53 
56  virtual void setConstraints(
57  std::vector<BoundConstraints>&& constraintTypes,
58  std::vector<double>&& lowerBounds,
59  std::vector<double>&& upperBounds) override;
60 
62  virtual MinimizerResult iterate() override;
63 
65  virtual void parse(XML::Element minimizerElement) override;
66 
67 private:
68 
70  void evaluate();
71 
72  std::vector<BoundConstraints> _constraintTypes;
73  std::vector<double> _lowerBounds;
74  std::vector<double> _upperBounds;
75 
77  std::vector<double> x;
78 
80  std::vector<double> g;
81 
82  // Variables passed to the L-BFGS-B Fortran routine:
83  char task[60];
84  char csave[60];
85  int lsave[4];
86  double dsave[29];
87  int isave[44];
88  double factr;
89  std::vector<int> iwa;
90  int m;
91  double pgtol = 1e-5;
92  std::vector<double> wa;
93  int iprint;
94 };
95 
96 } // End of namespace
FitJob * job() const
Returns the job to which this object belongs.
Definition: Minimizer.h:68
virtual void prepare(std::vector< double > &&x0, const std::function< double(const std::vector< double > &)> &func, const std::function< double(const std::vector< double > &, std::vector< double > &)> &gradient=std::function< double(const std::vector< double > &, std::vector< double > &)>()) override
Definition: LBFGSMinimizer.cpp:39
LBFGSMinimizer(FitJob *job)
Constructor.
Definition: LBFGSMinimizer.h:34
virtual MinimizerResult iterate() override
Performs one minimization iteration.
Definition: LBFGSMinimizer.cpp:99
virtual void parse(XML::Element minimizerElement) override
Parses the minimizer&#39;s parameters from the XML file.
Definition: LBFGSMinimizer.cpp:91
This file collects the definition of classes that define various simple crystal structures.
Definition: Atomicrex.h:67
Definition: XMLUtilities.h:69
Definition: FitJob.h:37
Abstract base class for minimization algorithms.
Definition: Minimizer.h:34
Definition: LBFGSMinimizer.h:29
virtual void setConstraints(std::vector< BoundConstraints > &&constraintTypes, std::vector< double > &&lowerBounds, std::vector< double > &&upperBounds) override
Definition: LBFGSMinimizer.cpp:78