Loading...
Searching...
No Matches
gpr::quantum::bathresponse Namespace Reference

Classes

struct  Bounds
struct  CentroidResponseFit
struct  Model

Typedefs

using Matrix = Eigen::MatrixXd
using Vector = Eigen::VectorXd

Functions

CentroidResponseFit fitCentroidResponse (const Eigen::MatrixXd &Caa, const Eigen::MatrixXd &Cyy, const Eigen::MatrixXd &Cya, double beta)
Bounds boundResponse (const Matrix &B, const Matrix &Q, const Matrix &AQ, double alpha, double shift)

Typedef Documentation

◆ Matrix

using gpr::quantum::bathresponse::Matrix = Eigen::MatrixXd

Definition at line 16 of file HarmonicBathResponse.h.

◆ Vector

using gpr::quantum::bathresponse::Vector = Eigen::VectorXd

Definition at line 17 of file HarmonicBathResponse.h.

Function Documentation

◆ boundResponse()

Bounds gpr::quantum::bathresponse::boundResponse ( const Matrix & B,
const Matrix & Q,
const Matrix & AQ,
double alpha,
double shift )
inline

Definition at line 64 of file HarmonicBathResponse.h.

66{
67 const auto n = B.rows(), r = B.cols(), m = Q.cols();
68 if (n <= 0 || r <= 0 || m <= 0 || m > n || Q.rows() != n ||
69 AQ.rows() != n || AQ.cols() != m || !B.allFinite() || !Q.allFinite() ||
70 !AQ.allFinite() || !std::isfinite(alpha) || alpha < 0 ||
71 !std::isfinite(shift) || !(shift + alpha > 0))
72 throw std::invalid_argument(
73 "Finite compatible bath data and positive spectral shift required");
74 const double epsilon = 256 * std::numeric_limits<double>::epsilon() * n;
75 if ((Q.transpose() * Q - Matrix::Identity(m, m)).norm() > epsilon)
76 throw std::invalid_argument("Orthonormal bath response basis required");
77 const Matrix G = Q.transpose() * B;
78 const Matrix missing = B - Q * G;
79 for (Eigen::Index j = 0; j < r; ++j)
80 if (missing.col(j).stableNorm() > epsilon * B.col(j).stableNorm())
81 throw std::invalid_argument(
82 "Bath coupling lies outside the supplied basis");
83 Matrix T = Q.transpose() * AQ;
84 const double operatorScale = AQ.stableNorm();
85 if ((T - T.transpose()).norm() > epsilon * operatorScale)
86 throw std::invalid_argument(
87 "Self-adjoint bath operator actions required");
88 T = (.5 * T + .5 * T.transpose()).eval();
89 Matrix positive = T;
90 positive.diagonal().array() -= alpha;
91 Eigen::SelfAdjointEigenSolver<Matrix> spectrum(positive);
92 const double tolerance = epsilon * std::max(operatorScale, std::abs(alpha));
93 if (spectrum.info() != Eigen::Success ||
94 spectrum.eigenvalues().minCoeff() < -tolerance)
95 throw std::domain_error(
96 "Bath actions violate the declared spectral lower bound");
97 Bounds result;
98 result.lowerModel = {T, G};
99 result.lower = result.lowerModel.response(shift);
100 if (m == n) {
101 result.upperModel = result.lowerModel;
102 result.upper = result.lower;
103 result.residualDirections = Matrix(n, 0);
104 result.residualSingularValues = Vector(0);
105 return result;
106 }
107 Matrix residual = AQ - Q * T;
108 for (int pass = 0; pass < 2; ++pass)
109 residual.noalias() -= Q * (Q.transpose() * residual).eval();
110 Eigen::JacobiSVD<Matrix> factor(residual,
111 Eigen::ComputeThinU | Eigen::ComputeThinV);
112 if (factor.info() != Eigen::Success)
113 throw std::runtime_error("Bath residual factorization failed");
114 result.residualDirections = factor.matrixU();
115 result.residualSingularValues = factor.singularValues();
116 const Matrix F =
117 factor.singularValues().asDiagonal() * factor.matrixV().transpose();
118 Vector inverse = Vector::Zero(m);
119 for (Eigen::Index j = 0; j < m; ++j) {
120 if (spectrum.eigenvalues()[j] > tolerance)
121 inverse[j] = 1 / spectrum.eigenvalues()[j];
122 else if ((F * spectrum.eigenvectors().col(j)).stableNorm() >
123 epsilon * operatorScale)
124 throw std::domain_error(
125 "Bath residual leaves the supported stiffness range");
126 }
127 const Matrix pseudoinverse = spectrum.eigenvectors() *
128 inverse.asDiagonal() *
129 spectrum.eigenvectors().transpose();
130 Matrix extended = Matrix::Zero(2 * m, 2 * m);
131 extended.topLeftCorner(m, m) = T;
132 extended.bottomLeftCorner(m, m) = F;
133 extended.topRightCorner(m, m) = F.transpose();
134 extended.bottomRightCorner(m, m) = F * pseudoinverse * F.transpose();
135 extended.bottomRightCorner(m, m).diagonal().array() += alpha;
136 Matrix coupling = Matrix::Zero(2 * m, r);
137 coupling.topRows(m) = G;
138 result.upperModel = {std::move(extended), std::move(coupling)};
139 result.upper = result.upperModel.response(shift);
140 return result;
141}
Matrix response(double shift) const

◆ fitCentroidResponse()

CentroidResponseFit gpr::quantum::bathresponse::fitCentroidResponse ( const Eigen::MatrixXd & Caa,
const Eigen::MatrixXd & Cyy,
const Eigen::MatrixXd & Cya,
double beta )
inline

Fit R = B^T A^-1 B from uncentered second moments of forcing a and projected bath centroid y. The conditional model is y|a ~ N(-R a,R/beta). The score gives R Caa R + R/beta = Cyy. Mean consistency is an independent diagnostic; solving the score cannot establish that the physical bath is harmonic. For nonlinear forcing, a is its imaginary-time average.

Definition at line 71 of file CentroidResponseFit.h.

75{
76 using namespace centroid_detail;
77 const auto n = Cyy.rows();
78 if (n <= 0 || Cyy.cols() != n || Caa.rows() != n || Caa.cols() != n ||
79 Cya.rows() != n || Cya.cols() != n || !Caa.allFinite() ||
80 !Cyy.allFinite() || !Cya.allFinite() || !std::isfinite(beta) ||
81 !(beta > 0.) || !std::isfinite(1. / beta) || !(1. / beta > 0.))
82 throw std::invalid_argument(
83 "Finite compatible centroid moments and positive beta required");
84 Vector scale(n);
85 for (Eigen::Index i = 0; i < n; ++i) {
86 if (Cyy(i, i) < 0.)
87 throw std::domain_error("Nonnegative centroid variance required");
88 if (Cyy(i, i) == 0. && ((Cyy.row(i).array() != 0.).any() ||
89 (Cyy.col(i).array() != 0.).any()))
90 throw std::domain_error(
91 "Zero centroid variance requires a zero covariance row");
92 scale[i] = Cyy(i, i) == 0. ? 1. : std::sqrt(Cyy(i, i));
93 }
94 Matrix aa(n, n), yy(n, n), ya(n, n);
95 for (Eigen::Index i = 0; i < n; ++i)
96 for (Eigen::Index j = 0; j < n; ++j) {
97 const long double si = scale[i], sj = scale[j];
98 aa(i, j) = checked(static_cast<long double>(Caa(i, j)) * si * sj);
99 yy(i, j) = checked(static_cast<long double>(Cyy(i, j)) / si / sj);
100 ya(i, j) = checked(static_cast<long double>(Cya(i, j)) * sj / si);
101 }
102 spectrum(aa);
103 const Matrix S = root(yy);
104 auto eig = spectrum(S * aa * S);
105 const double b = 1. / beta;
106 Vector weights(n);
107 for (Eigen::Index i = 0; i < n; ++i) {
108 const double lambda = std::max(0., eig.eigenvalues()[i]);
109 weights[i] = 1. / (.5 * b + .5 * std::hypot(b, 2 * std::sqrt(lambda)));
110 }
111 Matrix response = S * eig.eigenvectors() * weights.asDiagonal() *
112 eig.eigenvectors().transpose() * S;
113 response = (.5 * response + .5 * response.transpose()).eval();
114 const Matrix meanResidual = ya + response * aa;
115 const Matrix quadratic = response * aa * response;
116 const Matrix scoreResidual = quadratic + b * response - yy;
117 CentroidResponseFit result;
118 result.scaledMeanResidual =
119 ratio(meanResidual.stableNorm(),
120 std::max(ya.stableNorm(), (response * aa).stableNorm()));
121 result.relativeScoreResidual =
122 ratio(scoreResidual.stableNorm(),
123 std::max({yy.stableNorm(), quadratic.stableNorm(),
124 (b * response).stableNorm()}));
125 result.response.resize(n, n);
126 result.conditionalCovariance.resize(n, n);
127 result.meanMomentResidual.resize(n, n);
128 result.scoreMomentResidual.resize(n, n);
129 for (Eigen::Index i = 0; i < n; ++i)
130 for (Eigen::Index j = 0; j < n; ++j) {
131 const long double si = scale[i], sj = scale[j];
132 const long double entry =
133 static_cast<long double>(response(i, j)) * si * sj;
134 result.response(i, j) = checked(entry);
135 result.conditionalCovariance(i, j) = checked(entry / beta);
136 result.meanMomentResidual(i, j) =
137 checked(static_cast<long double>(meanResidual(i, j)) * si / sj);
138 result.scoreMomentResidual(i, j) = checked(
139 static_cast<long double>(scoreResidual(i, j)) * si * sj);
140 }
141 return result;
142}
Eigen::MatrixXd Matrix