Loading...
Searching...
No Matches
IndexTargetedArc.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
6#pragma once
7#include <limits>
8
9#include "ArcTailAction.h"
11
12namespace gpr::quantum {
14 std::vector<gaussian::Segment> segments;
15 double shift{};
16 std::size_t factorizations{};
17};
18
19// Adding tau to one left diagonal block per link gives H + tau I on
20// the whole band. Its inertia on a fixed phase section is monotone in
21// tau. Gaussian block factorizations locate an index-one interval without
22// forming the dense band Hessian or changing the physical action.
24 const std::vector<gaussian::Segment>& segments,
25 const Eigen::MatrixXd& normal)
26{
27 using M = Eigen::MatrixXd;
28 if (segments.empty())
29 throw std::invalid_argument("Nonempty arc search kernel required");
30 const auto d = segments.front().A.rows();
31 if (d < 1 || normal.rows() != Eigen::Index(segments.size()) * d ||
32 normal.cols() < 1 || !normal.allFinite())
33 throw std::invalid_argument(
34 "Matching finite arc phase normals required");
36 double scale = 1.;
37 for (const auto& link: segments)
38 scale = std::max(scale, link.A.cwiseAbs().maxCoeff() +
39 link.rightEndpoint().cwiseAbs().maxCoeff() +
40 2 * link.L.cwiseAbs().maxCoeff());
41 auto assess = [&](double shift) {
42 result.segments = segments;
43 for (auto& link: result.segments) {
44 const M right = link.rightEndpoint();
45 link.rightA = right;
46 link.A.diagonal().array() += shift;
47 }
48 ++result.factorizations;
49 const auto spectrum = gaussian::restrictedTraceDeterminant(
50 result.segments, M::Identity(d, d), normal);
51 if (spectrum.inertia.zero || spectrum.unresolvedBorderEigenvalues)
52 throw std::runtime_error(
53 "Arc shift lies on an unresolved eigenvalue");
54 result.shift = shift;
55 return spectrum.inertia.negative;
56 };
57 const auto original = assess(0.);
58 if (original == 1) return result;
59 double low = 0., high = 0.;
60 bool bracketed = false;
61 for (unsigned k = 0; k < 48; ++k) {
62 const double trial = original > 1 ? scale : -scale;
63 const auto negative = assess(trial);
64 if (negative == 1) return result;
65 if ((original > 1 && negative == 0) ||
66 (original == 0 && negative > 1)) {
67 low = original > 1 ? 0. : trial;
68 high = original > 1 ? trial : 0.;
69 bracketed = true;
70 break;
71 }
72 scale *= 2;
73 }
74 if (!bracketed)
75 throw std::runtime_error("Cannot bracket an index-one arc kernel");
76 for (unsigned k = 0; k < 80; ++k) {
77 const double middle = low + .5 * (high - low);
78 if (middle == low || middle == high) break;
79 std::size_t negative;
80 try {
81 negative = assess(middle);
82 } catch (const std::runtime_error&) {
83 const double offset = 256 * std::numeric_limits<double>::epsilon() *
84 std::max({1., scale, std::abs(middle)});
85 const double adjacent = std::min(high, middle + offset);
86 if (adjacent == high) throw;
87 negative = assess(adjacent);
88 }
89 if (negative == 1) return result;
90 if (negative > 1)
91 low = result.shift;
92 else
93 high = result.shift;
94 }
95 throw std::runtime_error("No resolved index-one arc shift interval exists");
96}
97
99 const ArcTailEvaluation& state,
100 const std::vector<Eigen::VectorXd>& displacement)
101{
102 if (displacement.size() != state.gradient.size() ||
103 displacement.size() != state.fluctuationSegments.size())
104 throw std::invalid_argument(
105 "Matching arc quadratic displacement required");
106 double result = 0;
107 for (std::size_t j = 0; j < displacement.size(); ++j) {
108 const auto next = (j + 1) % displacement.size();
109 const auto& link = state.fluctuationSegments[j];
110 result += state.gradient[j].dot(displacement[j]) +
111 .5 * displacement[j].dot(link.A * displacement[j]) +
112 .5 * displacement[next].dot(link.rightEndpoint() *
113 displacement[next]) -
114 displacement[j].dot(link.L * displacement[next]);
115 }
116 return result;
117}
118
119// Saddle steps can raise or lower the physical action. Agreement of the
120// measured change with its local model controls either sign; it does not
121// replace the full native gradient requirement at convergence.
122inline bool arcActionChangeAgrees(double actual, double predicted, double scale)
123{
124 return std::isfinite(actual) && std::isfinite(predicted) &&
125 std::abs(predicted) > 128 * std::numeric_limits<double>::epsilon() *
126 std::max(1., std::abs(scale)) &&
127 std::abs(actual - predicted) <= .5 * std::abs(predicted);
128}
129} // namespace gpr::quantum
TwistedRestrictedResult restrictedTraceDeterminant(const std::vector< Segment > &segments, const Matrix &twist, const Vector &unitNormal)
Models for quantum-path (instanton) searches: arc and tail actions, amplitude continuation.
IndexTargetedArcKernel indexOneArcKernel(const std::vector< gaussian::Segment > &segments, const Eigen::MatrixXd &normal)
bool arcActionChangeAgrees(double actual, double predicted, double scale)
double quadraticArcActionChange(const ArcTailEvaluation &state, const std::vector< Eigen::VectorXd > &displacement)
std::vector< Eigen::VectorXd > gradient
std::vector< gpr::quantum::gaussian::Segment > fluctuationSegments
std::vector< gaussian::Segment > segments