Loading...
Searching...
No Matches
ConstrainedFamilyRate.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
3
4#include <Eigen/SVD>
5#include <algorithm>
6#include <cmath>
7#include <limits>
8#include <numbers>
9#include <stdexcept>
10
11namespace gpr::quantum {
13 const Eigen::MatrixXd& normals,
14 const std::vector<Eigen::MatrixXd>& derivatives,
15 const Eigen::MatrixXd& targets, const Eigen::VectorXd& point)
16{
17 const auto k = normals.cols(), d = normals.rows();
18 if (k < 1 || d < k || point.size() != d || targets.rows() != k ||
19 targets.cols() != k ||
20 derivatives.size() != static_cast<std::size_t>(k) ||
21 !normals.allFinite() || !targets.allFinite() || !point.allFinite() ||
22 (normals.transpose() * normals - Eigen::MatrixXd::Identity(k, k))
23 .norm() > 1e-12 * k)
24 throw std::invalid_argument(
25 "Finite matching orthonormal constraint chart required");
26 Eigen::MatrixXd jacobian(k, k);
27 double logScale = 0;
28 for (Eigen::Index b = 0; b < k; ++b) {
29 const auto& derivative = derivatives[b];
30 if (derivative.rows() != d || derivative.cols() != k ||
31 !derivative.allFinite() ||
32 (normals.transpose() * derivative +
33 derivative.transpose() * normals)
34 .stableNorm() >
35 1e-12 * std::max(1., derivative.stableNorm()))
36 throw std::invalid_argument(
37 "Constraint derivatives must be tangent to the orthonormal "
38 "frame");
39 jacobian.col(b) = targets.col(b) - derivative.transpose() * point;
40 const double scale = jacobian.col(b).stableNorm();
41 if (!(scale > 0) || !std::isfinite(scale))
42 throw std::domain_error(
43 "Constraint parameters define a singular or unrepresentable "
44 "chart");
45 jacobian.col(b) /= scale;
46 logScale += std::log(scale);
47 }
48 const Eigen::JacobiSVD<Eigen::MatrixXd> svd(jacobian);
49 const auto& singular = svd.singularValues();
50 if (svd.info() != Eigen::Success || !singular.allFinite() ||
51 singular.minCoeff() <= 128 * std::numeric_limits<double>::epsilon() *
52 k * singular.maxCoeff())
53 throw std::domain_error(
54 "Constraint parameters do not resolve an independent chart");
55 const double result = logScale + singular.array().log().sum();
56 if (!std::isfinite(result))
57 throw std::overflow_error("Unrepresentable coarea logarithm");
58 return result;
59}
60
62 double referenceAction, const gaussian::TwistedTraceResult& reference,
63 const std::vector<ConstrainedFamilyPoint>& family, Eigen::Index k,
64 double hbar, double symmetryFactor)
65{
66 if (k < 1 || reference.dimension <= k || !std::isfinite(referenceAction) ||
67 !(hbar > 0) || !std::isfinite(hbar) || !(symmetryFactor > 0) ||
68 !std::isfinite(symmetryFactor) || family.empty() ||
69 !(reference.duration > 0) || !std::isfinite(reference.duration))
70 throw std::invalid_argument(
71 "Finite reference, retained coordinates and positive integration "
72 "scales required");
73 const double referenceLog = reference.logPositiveTrace();
74 std::vector<double> logarithms;
75 for (const auto& point: family) {
76 const auto& result = point.fluctuations;
77 if (!std::isfinite(point.action) || !(point.quadratureWeight > 0) ||
78 !std::isfinite(point.quadratureWeight) ||
79 !std::isfinite(point.logParameterJacobian) ||
80 result.codimension != k ||
81 result.dimension != reference.dimension - k ||
82 !std::isfinite(result.duration) ||
83 std::abs(result.duration - reference.duration) >
84 128 * std::numeric_limits<double>::epsilon() *
85 reference.duration)
86 throw std::invalid_argument(
87 "Conditional family must match reference measure and retained "
88 "dimension");
89 if (!result.logAbsNormalizedDet ||
90 !std::isfinite(*result.logAbsNormalizedDet) ||
91 result.inertia.negative != 1 || result.inertia.zero ||
92 result.unresolvedBorderEigenvalues ||
93 result.inertia.positive !=
94 static_cast<std::size_t>(result.dimension - 1))
95 throw std::domain_error(
96 "Conditional transverse Gaussian must have one resolved "
97 "negative mode");
98 const double value = std::log(point.quadratureWeight) +
99 point.logParameterJacobian +
100 (referenceAction - point.action) / hbar -
101 .5 * *result.logAbsNormalizedDet - referenceLog;
102 if (!std::isfinite(value))
103 throw std::overflow_error(
104 "Unrepresentable conditional family integrand");
105 logarithms.push_back(value);
106 }
107 const double maximum =
108 *std::max_element(logarithms.begin(), logarithms.end());
109 long double sum = 0;
110 for (const auto value: logarithms)
111 sum += std::exp(static_cast<long double>(value - maximum));
112 const double result = maximum + static_cast<double>(std::log(sum)) +
113 std::log(symmetryFactor) -
114 std::log(reference.duration) -
115 .5 * static_cast<double>(k) *
116 (std::log(2 * std::numbers::pi) + std::log(hbar));
117 if (!std::isfinite(result))
118 throw std::overflow_error("Unrepresentable conditional family rate");
119 return result;
120}
121} // namespace gpr::quantum
Models for quantum-path (instanton) searches: arc and tail actions, amplitude continuation.
double logImFConstrainedFamilyRate(double referenceAction, const gaussian::TwistedTraceResult &reference, const std::vector< ConstrainedFamilyPoint > &family, Eigen::Index k, double hbar, double symmetryFactor)
double logConstraintFamilyJacobian(const Eigen::MatrixXd &normals, const std::vector< Eigen::MatrixXd > &derivatives, const Eigen::MatrixXd &targets, const Eigen::VectorXd &point)