Overdamped Kramers-Langer rate from reactant to product along path, sampled from the joint posterior of F and its Hessians at the reactant path point and at the saddle of the posterior mean.
The saddle search starts at the interior path point with the highest posterior mean and takes Newton steps on the mean, uphill along the lowest Hessian mode and downhill along the others, each at most half a length scale, for at most 100 steps. It succeeds at a point whose gradient meets config.saddle_tolerance, whose mean Hessian has exactly one negative eigenvalue, and whose nearest point on the path between reactant and product lies within one length scale and is not an end of that stretch; otherwise it throws FreeEnergySaddleNotFoundError. A saddle whose mean F is not above the reactant throws FreeEnergyRateUnsupportedError.
Each draw's rate is abs(kappa) / (2 pi) sqrt(det H_reactant / abs(det H_saddle)) exp(-beta barrier), with kappa the negative eigenvalue of beta D H_saddle and D = diag(config.diffusion).
1167{
1168 if (!trained_)
1169 throw std::logic_error("free-energy surrogate is not trained");
1170 const int count = static_cast<int>(path.rows());
1171 if (count < 3) {
1172 throw std::invalid_argument("a rate path needs at least three points");
1173 }
1174 if (reactant < 0 || reactant >= count || product < 0 || product >= count ||
1175 std::abs(reactant - product) < 2) {
1176 throw std::invalid_argument(
1177 "reactant and product must be path indices with an interior "
1178 "point between them");
1179 }
1180 if (path.cols() != dimension_) {
1181 throw std::invalid_argument("path dimension differs");
1182 }
1183 requireFinite(path, "free-energy path");
1184 if (
config.posterior_samples < 2) {
1185 throw std::invalid_argument(
1186 "a rate needs at least two posterior samples");
1187 }
1188 if (!(
config.beta > 0.0) || !std::isfinite(
config.beta)) {
1189 throw std::invalid_argument("beta must be positive and finite");
1190 }
1191 if (
config.diffusion.size() != dimension_ ||
1192 !(
config.diffusion.array() > 0.0).all() ||
1193 !
config.diffusion.allFinite()) {
1194 throw std::invalid_argument(
1195 "the diffusion diagonal needs one positive finite entry per "
1196 "coordinate");
1197 }
1198 if (!(
config.credible_mass > 0.0) || !(
config.credible_mass < 1.0)) {
1199 throw std::invalid_argument("credible mass must lie in (0, 1)");
1200 }
1201 if (!(
config.saddle_tolerance > 0.0) ||
1202 !std::isfinite(
config.saddle_tolerance)) {
1203 throw std::invalid_argument(
1204 "the saddle tolerance must be positive and finite");
1205 }
1206 double gradient_norm = 0.0;
1207 const Eigen::VectorXd saddle = locateSaddle(
1208 path, reactant, product,
config.saddle_tolerance, gradient_norm);
1209 Eigen::MatrixXd points(2, dimension_);
1210 points.row(0) = path.row(reactant);
1211 points.row(1) = saddle.transpose();
1212 const FreeEnergyPathPosterior posterior =
pathPosterior(points);
1213 const Eigen::Index stride = 1 + dimension_ * (dimension_ + 1) / 2;
1214 if (!(posterior.mean[stride] - posterior.mean[0] > 0.0)) {
1215 throw FreeEnergyRateUnsupportedError(
1216 "the saddle of the posterior mean is not above the reactant: "
1217 "the barrier is not positive");
1218 }
1219 const Eigen::SelfAdjointEigenSolver<Eigen::MatrixXd> eigen(
1220 posterior.covariance);
1221 if (eigen.info() != Eigen::Success) {
1222 throw std::runtime_error(
1223 "free-energy path covariance has no eigendecomposition");
1224 }
1225 const Eigen::MatrixXd root =
1226 eigen.eigenvectors() *
1227 eigen.eigenvalues().cwiseMax(0.0).cwiseSqrt().asDiagonal();
1228 const double two_pi = 2.0 * std::acos(-1.0);
1229 const Eigen::VectorXd diffusion_root =
config.diffusion.cwiseSqrt();
1230
1231 SplitMix64 generator(
config.seed);
1232 Eigen::VectorXd normal(posterior.mean.size());
1233 std::vector<double> barriers, prefactors,
rates;
1234 for (
int draw = 0; draw <
config.posterior_samples; ++draw) {
1236 const Eigen::VectorXd sample = posterior.mean + root * normal;
1237 const double barrier = sample[stride] - sample[0];
1238 if (!(barrier > 0.0)) continue;
1239 const Eigen::MatrixXd reactant_hessian =
1240 unpackHessian(sample, 1, dimension_);
1241 const Eigen::VectorXd reactant_modes =
1242 Eigen::SelfAdjointEigenSolver<Eigen::MatrixXd>(
1243 reactant_hessian, Eigen::EigenvaluesOnly)
1244 .eigenvalues();
1245 const Eigen::MatrixXd saddle_hessian =
1246 unpackHessian(sample, stride + 1, dimension_);
1247 const Eigen::VectorXd saddle_modes =
1248 Eigen::SelfAdjointEigenSolver<Eigen::MatrixXd>(
1249 saddle_hessian, Eigen::EigenvaluesOnly)
1250 .eigenvalues();
1251 if (!(reactant_modes.minCoeff() > 0.0)) continue;
1252 if (!(saddle_modes[0] < 0.0) ||
1253 (dimension_ > 1 && !(saddle_modes[1] > 0.0))) {
1254 continue;
1255 }
1256
1257
1258 const double unstable =
1259 -Eigen::SelfAdjointEigenSolver<Eigen::MatrixXd>(
1260 diffusion_root.asDiagonal() * saddle_hessian *
1261 diffusion_root.asDiagonal(),
1262 Eigen::EigenvaluesOnly)
1263 .eigenvalues()[0];
1264 const SignedLogDet reactant_det = choleskyLogDet(reactant_hessian);
1265 const SignedLogDet saddle_det = luLogDet(saddle_hessian);
1266 if (reactant_det.sign != 1 || saddle_det.sign != -1) {
1267 throw std::runtime_error(
1268 "free-energy Hessian determinant sign disagrees with its "
1269 "inertia");
1270 }
1271 const double determinant_ratio =
1272 std::exp(reactant_det.log_abs - saddle_det.log_abs);
1273 const double prefactor =
1274 config.beta * unstable / two_pi * std::sqrt(determinant_ratio);
1275 const double rate = prefactor * std::exp(-
config.beta * barrier);
1276 if (!std::isfinite(prefactor) || !std::isfinite(rate)) continue;
1277 barriers.push_back(barrier);
1278 prefactors.push_back(prefactor);
1279 rates.push_back(rate);
1280 }
1281 const int accepted =
static_cast<int>(
rates.size());
1282 if (accepted < 2 || 10LL * accepted < 9LL * static_cast<long long>(
1283 config.posterior_samples)) {
1284 throw FreeEnergyRateUnsupportedError(
1285 "fewer than 90% of posterior draws have a minimum at the reactant, "
1286 "an index-one saddle and a positive barrier");
1287 }
1288 const double tail = 0.5 * (1.0 -
config.credible_mass);
1289 KramersRateSummary summary;
1290 summary.saddle = saddle;
1291 summary.saddle_gradient_norm = gradient_norm;
1292 meanAndStd(barriers, summary.barrier_mean, summary.barrier_std);
1293 summary.barrier_lower = quantile(barriers, tail);
1294 summary.barrier_upper = quantile(barriers, 1.0 - tail);
1295 meanAndStd(prefactors, summary.prefactor_mean, summary.prefactor_std);
1296 meanAndStd(rates, summary.rate_mean, summary.rate_std);
1297 summary.rate_lower = quantile(rates, tail);
1298 summary.rate_upper = quantile(rates, 1.0 - tail);
1299 summary.samples_requested =
config.posterior_samples;
1300 summary.samples_accepted = accepted;
1301 return summary;
1302}
FreeEnergyPathPosterior pathPosterior(const Eigen::MatrixXd &path) const
void fillStandardNormal(SplitMix64 &generator, Eigen::VectorXd &normal)
Independent standard normals, two per pair of uniforms (Box-Muller).
Rates rates(const Key &key, const Eigen::VectorXd &frequencies)