votca 2024.2-dev
Loading...
Searching...
No Matches
bfgs_trm.h
Go to the documentation of this file.
1/*
2 * Copyright 2009-2020 The VOTCA Development Team
3 * (http://www.votca.org)
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License")
6 *
7 * You may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 */
19
20#pragma once
21#ifndef VOTCA_XTP_BFGS_TRM_H
22#define VOTCA_XTP_BFGS_TRM_H
23
24// Standard includes
25#include <functional>
26#include <vector>
27
28// Local VOTCA includes
29#include "logger.h"
31
32namespace votca {
33namespace xtp {
34
35class BFGSTRM {
36 public:
37 BFGSTRM(Optimiser_costfunction& costfunction) : costfunction_(costfunction) {
38 hessian_ = Eigen::MatrixXd::Identity(costfunction.NumParameters(),
39 costfunction.NumParameters());
40 }
41
42 void setLog(Logger* pLog) { pLog_ = pLog; }
43
44 void setTrustRadius(double trust_radius) { trust_radius_ = trust_radius; }
45
46 double getTrustRadius() const { return trust_radius_; }
47
48 void setCallbacks(const std::vector<std::function<void()> >& callbacks) {
49 callbacks_ = callbacks;
50 }
51
52 void setNumofIterations(Index iterations) { max_iteration_ = iterations; }
53
54 void Optimize(const Eigen::VectorXd& initialparameters);
55
56 bool Success() const { return success_; }
57 std::string getErrorMessage() const { return errormessage_; }
58
59 double getCost() const { return cost_; }
60
61 Index getIteration() const { return iteration_; }
62
63 const Eigen::VectorXd getParameters() const { return parameters_; }
64
65 void setInitialHessian(const Eigen::MatrixXd& hessian) { hessian_ = hessian; }
66
67 private:
69
70 void UpdateHessian(const Eigen::VectorXd& delta_pos,
71 const Eigen::VectorXd& delta_gradient);
72 double QuadraticEnergy(const Eigen::VectorXd& gradient,
73 const Eigen::VectorXd& delta_pos) const;
74 bool AcceptRejectStep(const Eigen::VectorXd& delta_pos,
75 const Eigen::VectorXd& gradient, double energy_delta);
76
77 std::string errormessage_;
78 bool success_ = true;
80
81 std::vector<std::function<void()> > callbacks_;
82
83 Eigen::MatrixXd hessian_;
84 Eigen::VectorXd parameters_;
85
86 double cost_ = std::numeric_limits<double>::max();
87
88 double trust_radius_ = 0.1;
89
91
93};
94
95} // namespace xtp
96} // namespace votca
97#endif // VOTCA_XTP_BFGS_TRM_H
BFGSTRM(Optimiser_costfunction &costfunction)
Definition bfgs_trm.h:37
void Optimize(const Eigen::VectorXd &initialparameters)
Definition bfgs_trm.cc:31
const Eigen::VectorXd getParameters() const
Definition bfgs_trm.h:63
Index getIteration() const
Definition bfgs_trm.h:61
Eigen::VectorXd parameters_
Definition bfgs_trm.h:84
double QuadraticEnergy(const Eigen::VectorXd &gradient, const Eigen::VectorXd &delta_pos) const
Definition bfgs_trm.cc:149
std::string getErrorMessage() const
Definition bfgs_trm.h:57
double getCost() const
Definition bfgs_trm.h:59
bool Success() const
Definition bfgs_trm.h:56
bool AcceptRejectStep(const Eigen::VectorXd &delta_pos, const Eigen::VectorXd &gradient, double energy_delta)
Definition bfgs_trm.cc:84
void setTrustRadius(double trust_radius)
Definition bfgs_trm.h:44
std::string errormessage_
Definition bfgs_trm.h:77
Eigen::MatrixXd hessian_
Definition bfgs_trm.h:83
void setNumofIterations(Index iterations)
Definition bfgs_trm.h:52
void setLog(Logger *pLog)
Definition bfgs_trm.h:42
Optimiser_costfunction & costfunction_
Definition bfgs_trm.h:68
void setInitialHessian(const Eigen::MatrixXd &hessian)
Definition bfgs_trm.h:65
void UpdateHessian(const Eigen::VectorXd &delta_pos, const Eigen::VectorXd &delta_gradient)
Definition bfgs_trm.cc:134
double getTrustRadius() const
Definition bfgs_trm.h:46
void setCallbacks(const std::vector< std::function< void()> > &callbacks)
Definition bfgs_trm.h:48
std::vector< std::function< void()> > callbacks_
Definition bfgs_trm.h:81
Logger is used for thread-safe output of messages.
Definition logger.h:164
virtual Index NumParameters() const =0
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26