votca 2024.1-dev
Loading...
Searching...
No Matches
trustregion.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_TRUSTREGION_H
22#define VOTCA_XTP_TRUSTREGION_H
23
24// Standard includes
25#include <iostream>
26
27// Local VOTCA includes
28#include "eigen.h"
29
30// Solves the trustregion subproblem g^T*s+0.5*s^T H s = min with ||s||<=delta
31
32namespace votca {
33namespace xtp {
34
36 public:
37 Eigen::VectorXd CalculateStep(const Eigen::VectorXd& gradient,
38 const Eigen::MatrixXd& Hessian,
39 double delta) const;
40
41 private:
43 public:
45 const Eigen::VectorXd& factor,
46 const Eigen::SelfAdjointEigenSolver<Eigen::MatrixXd>& hessian,
47 double trust_radius, Index startindex)
48 : factor_(factor),
49 hessian_(hessian),
50 trust_radius_(trust_radius),
51 startindex_(startindex) {
52 ;
53 }
54
55 // Calculates \phi and \phi/\phi'
56 std::pair<double, double> Evaluate(double lambda) {
57 Index size = factor_.size() - startindex_;
58 Eigen::ArrayXd quotient =
59 (hessian_.eigenvalues().array() + lambda).tail(size);
60 const double p2 = (factor_.array().tail(size) / (quotient.pow(2))).sum();
61 const double p = std::sqrt(p2);
62 const double q2 = (factor_.array().tail(size) / (quotient.pow(3))).sum();
63 std::pair<double, double> result;
64 result.first = 1 / trust_radius_ - 1 / p;
65 result.second = p2 / q2 * (p - trust_radius_) / trust_radius_;
66 return result;
67 }
68
69 private:
70 const Eigen::VectorXd& factor_;
71 const Eigen::SelfAdjointEigenSolver<Eigen::MatrixXd>& hessian_;
74 };
75};
76
77} // namespace xtp
78} // namespace votca
79#endif // VOTCA_XTP_TRUSTREGION_H
std::pair< double, double > Evaluate(double lambda)
Definition trustregion.h:56
const Eigen::SelfAdjointEigenSolver< Eigen::MatrixXd > & hessian_
Definition trustregion.h:71
TrustRegionFunction(const Eigen::VectorXd &factor, const Eigen::SelfAdjointEigenSolver< Eigen::MatrixXd > &hessian, double trust_radius, Index startindex)
Definition trustregion.h:44
Eigen::VectorXd CalculateStep(const Eigen::VectorXd &gradient, const Eigen::MatrixXd &Hessian, double delta) const
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26