18{
19 if (!(hbar > 0.) || !std::isfinite(hbar) || G.rows() == 0 ||
20 G.rows() != G.cols() || C.rows() != G.rows() || C.cols() != G.cols() ||
21 f.size() != G.rows() || !G.allFinite() || !C.allFinite() ||
22 !f.allFinite())
23 throw std::invalid_argument("Finite matching influence data required");
24 if (!G.isApprox(G.transpose(), 1e-12) || !C.isApprox(C.transpose(), 1e-12))
25 throw std::invalid_argument("Symmetric influence operators required");
26 Eigen::LLT<Eigen::MatrixXd> base(G);
27 if (base.info() != Eigen::Success)
28 throw std::domain_error("Nonpositive reference");
29 const Eigen::MatrixXd L = base.matrixL();
30 const Eigen::MatrixXd A =
31 Eigen::MatrixXd::Identity(G.rows(), G.cols()) + L.transpose() * C * L;
32 Eigen::LLT<Eigen::MatrixXd> update(A);
33 if (update.info() != Eigen::Success)
34 throw std::domain_error("Nonpositive influence");
35 const Eigen::MatrixXd Q = L * update.solve(L.transpose());
36 const Eigen::VectorXd diagonal =
37 Eigen::MatrixXd(update.matrixL()).diagonal();
38 return {-.5 * f.dot(Q * f) + hbar * diagonal.array().log().sum(), -Q * f,
39 Q};
40}