Loading...
Searching...
No Matches
gpr::quantum::PositiveArcAction Class Reference

#include <gpr/quantum/PositiveArcAction.h>

Inheritance diagram for gpr::quantum::PositiveArcAction:

Public Member Functions

 PositiveArcAction (M well, double period, double hbar, std::vector< double > weights, bool positive=true)
bool positiveQuadrature () const
ArcTailEvaluation evaluate (const std::vector< V > &q, const std::vector< PotentialEvaluation > &native, double duration, const std::vector< M > &hessians={}) const
V nodalWeights (double duration) const
std::vector< M > referenceModalGreen (double duration) const
Public Member Functions inherited from gpr::quantum::ArcTailAction
 ArcTailAction (M positiveWell, double period, double hbar, std::vector< double > arcWeights)
double period () const
const M & wellCurvature () const
const std::vector< double > & arcWeights () const
ArcTailEvaluation evaluate (const std::vector< V > &q, const std::vector< gpr::quantum::PotentialEvaluation > &native, double arcDuration, const std::vector< M > &nativeHessians={}) const

Detailed Description

Definition at line 14 of file PositiveArcAction.h.

Constructor & Destructor Documentation

◆ PositiveArcAction()

gpr::quantum::PositiveArcAction::PositiveArcAction ( M well,
double period,
double hbar,
std::vector< double > weights,
bool positive = true )
inline

Definition at line 20 of file PositiveArcAction.h.

22 : ArcTailAction(std::move(well), period, hbar, std::move(weights)),
23 positive_(positive),
24 hbar_(hbar)
25 {
26 }
ArcTailAction(M positiveWell, double period, double hbar, std::vector< double > arcWeights)

Member Function Documentation

◆ evaluate()

ArcTailEvaluation gpr::quantum::PositiveArcAction::evaluate ( const std::vector< V > & q,
const std::vector< PotentialEvaluation > & native,
double duration,
const std::vector< M > & hessians = {} ) const
inline

Definition at line 31 of file PositiveArcAction.h.

34 {}) const
35 {
36 if (!positive_)
37 return ArcTailAction::evaluate(q, native, duration, hessians);
38 const auto n = arcWeights().size() + 1;
39 const auto d = wellCurvature().rows();
40 if (q.size() != n || native.size() != n ||
41 (!hessians.empty() && hessians.size() != n) ||
42 !(duration > 0 && duration < period()) || !std::isfinite(duration))
43 throw std::invalid_argument(
44 "Matching positive arc nodes and duration required");
45 for (std::size_t j = 0; j < n; ++j)
46 if (q[j].size() != d || !q[j].allFinite() ||
47 native[j].gradient.size() != d ||
48 !native[j].gradient.allFinite() ||
49 !std::isfinite(native[j].energy))
50 throw std::invalid_argument(
51 "Finite matching positive arc values required");
52 const V weights = nodalWeights(duration);
53 const M identity = M::Identity(d, d);
54 ArcTailEvaluation out;
55 out.gradient.assign(n, V::Zero(d));
56 out.durationCrossGradient.assign(n, V::Zero(d));
57 out.fluctuationHessianPhysical = !hessians.empty();
58 const double logScale = std::log(2 * std::acos(-1.) * hbar_);
59 for (std::size_t j = 0; j + 1 < n; ++j) {
60 const double h = duration * arcWeights()[j];
61 const V delta = q[j + 1] - q[j];
62 const double kinetic = .5 * delta.squaredNorm() / h;
63 out.action += kinetic;
64 out.gradient[j] -= delta / h;
65 out.gradient[j + 1] += delta / h;
66 out.durationGradient -= kinetic / duration;
67 out.durationHessian += 2 * kinetic / (duration * duration);
68 out.durationCrossGradient[j] += delta / (h * duration);
69 out.durationCrossGradient[j + 1] -= delta / (h * duration);
70 out.logKernelNormalization += .5 * d * (-std::log(h) - logScale);
71 if (!hessians.empty()) {
72 if (hessians[j].rows() != d || hessians[j].cols() != d ||
73 !hessians[j].allFinite())
74 throw std::invalid_argument(
75 "Matching finite positive arc search curvature "
76 "required");
77 gaussian::Segment link;
78 link.A = identity / h + weights[j] * hessians[j];
79 link.L = identity / h;
80 link.rightA = identity / h;
81 link.duration = h;
82 link.logDetL = -d * std::log(h);
83 out.fluctuationSegments.push_back(std::move(link));
84 }
85 }
86 for (std::size_t j = 0; j < n; ++j) {
87 out.action += weights[j] * native[j].energy;
88 out.gradient[j] += weights[j] * native[j].gradient;
89 out.durationGradient += weights[j] * native[j].energy / duration;
90 out.durationCrossGradient[j] +=
91 weights[j] * native[j].gradient / duration;
92 }
93 const double tail = period() - duration;
94 const HarmonicReference reference(wellCurvature(), tail);
95 const auto& kernel = reference.kernel();
96 const Eigen::SelfAdjointEigenSolver<M> spectrum(wellCurvature());
97 if (spectrum.info() != Eigen::Success)
98 throw std::runtime_error(
99 "Positive arc well spectrum is unresolved");
100 const M& modes = spectrum.eigenvectors();
101 const V omega = spectrum.eigenvalues().array().sqrt();
102 const V difference = modes.transpose() * (q.back() - q.front()),
103 sum = modes.transpose() * (q.back() + q.front());
104 V left(d), right(d), leftTime(d), rightTime(d);
105 for (Eigen::Index k = 0; k < d; ++k) {
106 const double w = omega[k], x = w * tail, e = std::exp(-x),
107 one = -std::expm1(-x);
108 const double th = one / (1 + e), ct = (1 + e) / one,
109 sech2 = 4 * e / ((1 + e) * (1 + e)),
110 csch2 = 4 * e / (one * one);
111 const double a = difference[k], b = sum[k];
112 out.action += .25 * w * (ct * a * a + th * b * b);
113 left[k] = .5 * w * (ct * a + th * b);
114 right[k] = .5 * w * (-ct * a + th * b);
115 out.durationGradient -=
116 w * w / 8 * (-csch2 * a * a + sech2 * b * b);
117 out.durationHessian +=
118 w * w * w / 8 * (csch2 * ct * a * a - sech2 * th * b * b);
119 leftTime[k] = -.25 * w * w * (-csch2 * a + sech2 * b);
120 rightTime[k] = -.25 * w * w * (csch2 * a + sech2 * b);
121 }
122 out.gradient.back() += modes * left;
123 out.gradient.front() += modes * right;
124 out.durationCrossGradient.back() += modes * leftTime;
125 out.durationCrossGradient.front() += modes * rightTime;
126 out.logKernelNormalization += .5 * (kernel.logDetL - d * logScale);
127 if (!hessians.empty()) {
128 if (hessians.back().rows() != d || hessians.back().cols() != d ||
129 !hessians.back().allFinite())
130 throw std::invalid_argument(
131 "Matching finite positive arc endpoint curvature required");
132 auto link = kernel;
133 link.rightA = kernel.A;
134 link.A += weights[n - 1] * hessians.back();
135 out.fluctuationSegments.push_back(std::move(link));
136 }
137 if (!std::isfinite(out.action) ||
138 !std::isfinite(out.durationGradient) ||
139 !std::isfinite(out.durationHessian))
140 throw std::overflow_error(
141 "Positive arc action exceeds arithmetic range");
142 return out;
143 }
@ x
Definition Enums.h:28
const M & wellCurvature() const
ArcTailEvaluation evaluate(const std::vector< V > &q, const std::vector< gpr::quantum::PotentialEvaluation > &native, double arcDuration, const std::vector< M > &nativeHessians={}) const
const std::vector< double > & arcWeights() const
V nodalWeights(double duration) const
eon_relax_band_t eon_relax_surface_fn void eon_relax_outcome_t * out

◆ nodalWeights()

V gpr::quantum::PositiveArcAction::nodalWeights ( double duration) const
inline

Definition at line 144 of file PositiveArcAction.h.

145 {
146 const auto n = arcWeights().size() + 1;
147 V out = V::Zero(n);
148 for (std::size_t j = 0; j + 1 < n; ++j) {
149 const double h = .5 * duration * arcWeights()[j];
150 out[j] += h;
151 out[j + 1] += h;
152 }
153 return out;
154 }

◆ positiveQuadrature()

bool gpr::quantum::PositiveArcAction::positiveQuadrature ( ) const
inline

Definition at line 27 of file PositiveArcAction.h.

28 {
29 return positive_;
30 }

◆ referenceModalGreen()

std::vector< M > gpr::quantum::PositiveArcAction::referenceModalGreen ( double duration) const
inline

Definition at line 157 of file PositiveArcAction.h.

158 {
159 if (!positive_) return {};
160 const auto n = arcWeights().size() + 1;
161 const auto d = wellCurvature().rows();
162 const Eigen::SelfAdjointEigenSolver<M> spectrum(wellCurvature());
163 if (spectrum.info() != Eigen::Success)
164 throw std::runtime_error("Positive reference modes are unresolved");
165 const V weights = nodalWeights(duration);
166 std::vector<M> result;
167 for (Eigen::Index k = 0; k < d; ++k) {
168 const double w = std::sqrt(spectrum.eigenvalues()[k]);
169 M precision = M::Zero(n, n);
170 for (std::size_t j = 0; j < n; ++j)
171 precision(j, j) += weights[j] * w * w;
172 for (std::size_t j = 0; j + 1 < n; ++j) {
173 const double a = 1 / (duration * arcWeights()[j]);
174 precision(j, j) += a;
175 precision(j + 1, j + 1) += a;
176 precision(j, j + 1) -= a;
177 precision(j + 1, j) -= a;
178 }
179 const auto link = gaussian::exactSegment(M::Constant(1, 1, w * w),
180 period() - duration);
181 precision(0, 0) += link.A(0, 0);
182 precision(n - 1, n - 1) += link.A(0, 0);
183 precision(0, n - 1) -= link.L(0, 0);
184 precision(n - 1, 0) -= link.L(0, 0);
185 const Eigen::LDLT<M> factor(precision);
186 if (factor.info() != Eigen::Success ||
187 (factor.vectorD().array() <= 0).any())
188 throw std::runtime_error(
189 "Positive arc harmonic reference precision is unresolved");
190 result.push_back(factor.solve(M::Identity(n, n)));
191 }
192 return result;
193 }
Segment exactSegment(const Matrix &hessian, double duration)

The documentation for this class was generated from the following file: