votca 2026-dev
Loading...
Searching...
No Matches
trah.h
Go to the documentation of this file.
1/*
2 * Copyright 2009-2026 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_TRAH_H
22#define VOTCA_XTP_TRAH_H
23
24// Standard includes
25#include <functional>
26
27// Local VOTCA includes
28#include "eigen.h"
29
30namespace votca {
31namespace xtp {
32
55namespace trah {
56
58 // The micro-iterations stop when |(H - mu) x + g| <= eta |g| with the
59 // forcing term eta = min(max_forcing, |g|), so the macro-iterations
60 // converge quadratically close to the minimum.
61 double max_forcing = 0.1;
62 double residual_floor = 1e-10;
65 double alpha_max = 1e4;
66 double lower_fraction = 0.8;
67};
68
69struct StepResult {
70 Eigen::VectorXd x;
71 // g.x + 1/2 x.H.x of the step taken, and g.x alone
72 double predicted = 0.0;
73 double linear = 0.0;
74 double alpha = 1.0;
75 double mu = 0.0;
78 // the step started from the subspace passed in
79 bool reused = false;
80 double residual = 0.0;
81 bool converged = false;
82};
83
85using HessianProduct = std::function<Eigen::MatrixXd(const Eigen::MatrixXd&)>;
86
92struct Subspace {
93 Eigen::MatrixXd B;
94 Eigen::MatrixXd HB;
95 Eigen::VectorXd g;
96 void Clear() {
97 B.resize(0, 0);
98 HB.resize(0, 0);
99 g.resize(0);
100 }
101};
102
103StepResult Step(const Eigen::VectorXd& g, const Eigen::VectorXd& diag,
104 const HessianProduct& hessian, double trust_radius,
105 const StepOptions& opt = StepOptions(),
106 Subspace* subspace = nullptr);
107
114 public:
115 explicit TrustRadius(double radius = 0.5, double max_radius = 1.0)
116 : radius_(radius), max_radius_(max_radius) {}
117 double Radius() const { return radius_; }
118 double LastRatio() const { return ratio_; }
119 bool Update(double predicted, double actual);
125 bool Update(double predicted, double actual, double linear, double step_norm);
126
127 static constexpr double noise_floor = 1e-10;
128
129 private:
130 double radius_;
132 double ratio_ = 0.0;
133};
134
141Eigen::MatrixXd RotateOrbitals(const Eigen::MatrixXd& C,
142 const Eigen::VectorXd& x, Index nocc);
143
146Eigen::VectorXd OccVirt(const Eigen::MatrixXd& M, Index nocc);
147
148} // namespace trah
149} // namespace xtp
150} // namespace votca
151
152#endif // VOTCA_XTP_TRAH_H
double Radius() const
Definition trah.h:117
static constexpr double noise_floor
Definition trah.h:127
bool Update(double predicted, double actual)
Definition trah.cc:257
TrustRadius(double radius=0.5, double max_radius=1.0)
Definition trah.h:115
double LastRatio() const
Definition trah.h:118
Trust-region augmented-Hessian (TRAH) step for orbital rotations, after Helmich-Paris,...
Definition trah.h:55
std::function< Eigen::MatrixXd(const Eigen::MatrixXd &)> HessianProduct
Hessian applied to the columns of V (n x k), returning n x k.
Definition trah.h:85
StepResult Step(const Eigen::VectorXd &g, const Eigen::VectorXd &diag, const HessianProduct &hessian, double trust_radius, const StepOptions &opt=StepOptions(), Subspace *subspace=nullptr)
Definition trah.cc:116
Eigen::MatrixXd RotateOrbitals(const Eigen::MatrixXd &C, const Eigen::VectorXd &x, Index nocc)
Definition trah.cc:275
Eigen::VectorXd OccVirt(const Eigen::MatrixXd &M, Index nocc)
Definition trah.cc:318
Provides a means for comparing floating point numbers.
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26
Eigen::VectorXd x
Definition trah.h:70
Eigen::VectorXd g
Definition trah.h:95
Eigen::MatrixXd B
Definition trah.h:93
Eigen::MatrixXd HB
Definition trah.h:94