61 const Eigen::Index d = roots.size();
62 Matrix width = Matrix::Zero(d / 3, 3);
63 for (Eigen::Index j = 0; j < N; ++j)
64 for (Eigen::Index k = 0; k < d; ++k) {
65 const double variance = covariance(j * d + k, j * d + k);
67 -1e-12 * std::max(1., covariance.cwiseAbs().maxCoeff()))
68 throw std::runtime_error(
"Negative bead variance");
69 width(k / 3, k % 3) +=
70 std::max(0., variance) / (roots(k) * roots(k));
72 return (width /
static_cast<double>(N)).cwiseSqrt();
78 const auto N =
static_cast<double>(q.size());
79 const Eigen::Index d = roots.size();
80 Vector mean = Vector::Zero(d);
81 for (
const auto&
x: q)
84 Vector second = Vector::Zero(d);
85 for (
const auto&
x: q)
86 second += (
x - mean).array().square().matrix();
89 s.
orbit.resize(d / 3, 3);
90 for (Eigen::Index k = 0; k < d; ++k) {
91 s.
centroid(k / 3, k % 3) = mean(k) / roots(k);
92 s.
orbit(k / 3, k % 3) = std::sqrt(second(k) / N) / roots(k);
100 double betaN,
const Matrix& excludedModes = {})
102 const auto N =
static_cast<Eigen::Index
>(q.size());
103 const Eigen::Index d = q.front().size();
104 if (H.rows() != N * d || H.cols() != N * d || !H.allFinite() ||
106 throw std::invalid_argument(
107 "A finite ring Hessian and positive beta_N required");
108 Matrix Q = Matrix::Identity(N * d, N * d);
109 if (excludedModes.size() != 0) {
110 Eigen::HouseholderQR<Matrix> qr(excludedModes);
111 const Matrix full = qr.householderQ();
112 Q = full.rightCols(N * d - excludedModes.cols());
114 Eigen::SelfAdjointEigenSolver<Matrix> s(Q.transpose() *
115 (.5 * (H + H.transpose())) * Q);
116 if (s.info() != Eigen::Success)
117 throw std::runtime_error(
"Ring spectrum failed");
118 const Matrix U = Q * s.eigenvectors();
120 for (Eigen::Index j = 0; j < N; ++j)
121 tangent.segment(j * d, d) = q[(j + 1) % N] - q[(j + N - 1) % N];
122 Eigen::Index phase = -1;
123 if (tangent.norm() > 0) {
126 for (Eigen::Index k = 0; k < U.cols(); ++k)
127 if (s.eigenvalues()(k) > 0 &&
128 std::abs(U.col(k).dot(tangent)) > best)
129 best = std::abs(U.col(k).dot(tangent)), phase = k;
131 const double scale = s.eigenvalues().cwiseAbs().maxCoeff();
132 Matrix covariance = Matrix::Zero(N * d, N * d);
133 for (Eigen::Index k = 0; k < U.cols(); ++k) {
134 if (k == phase || !(s.eigenvalues()(k) > 0))
continue;
135 if (!(s.eigenvalues()(k) > 1e-10 * scale))
136 throw std::domain_error(
137 "An unresolved zero mode must be supplied as an excluded mode");
138 covariance.noalias() +=
139 U.col(k) * U.col(k).transpose() / (betaN * s.eigenvalues()(k));
157 const Matrix& gradientCovariance,
160 const Eigen::Index n = pseudoInverse.rows();
161 if (pseudoInverse.cols() != n || gradientCovariance.rows() != n ||
162 gradientCovariance.cols() != n || n % roots.size() != 0)
163 throw std::invalid_argument(
164 "Matching pseudoinverse and gradient covariance required");
166 pseudoInverse * gradientCovariance * pseudoInverse.transpose(),
167 n / roots.size(), roots);