214{
215 const auto N =
static_cast<Eigen::Index
>(ring.
beads.size());
218 const Eigen::Index d = kernel.
lower.front().rows();
219 if (N < 4 || ring.
beads.front().size() != d ||
221 throw std::invalid_argument(
222 "Kernel, ring and weights dimensions must match");
225 throw std::invalid_argument(
226 "A frozen environment kernel needs the reactant as reference");
227 const Vector reference = hasReactant ? ring.
reactant : Vector::Zero(d);
229 const Eigen::Index sites = hasReactant ? N + 1 : N;
230 if (w.
channels.size() != sites * (d + 1))
231 throw std::invalid_argument("Weights do not match the ring");
232 for (Eigen::Index j = 0; j < N; ++j) {
233 x.segment(j * d, d) = ring.
beads[j] - reference;
234 for (Eigen::Index c = 0; c < d; ++c)
236 }
237 Sensitivity result;
239 .5 * (wg *
x.transpose() +
x * wg.transpose()) -
241 if (hasReactant) {
243 if (reactant.info() != Eigen::Success)
244 throw std::domain_error("A positive reactant ring is required");
245 W += .5 * reactant.solve(Matrix::Identity(N * d, N * d));
246 }
247 result.ringWeight = .5 * (W + W.transpose());
248 result.modeWeights =
projectRing(result.ringWeight, N, d);
249 for (std::size_t k = 0; k < kernel.
lower.size(); ++k) {
251 result.halfWidth +=
252 .5 *
nuclearNorm(root * result.modeWeights[k] * root);
253 }
256 return result;
257}
Eigen::Index siteChannel(Eigen::Index sites, Eigen::Index site, Eigen::Index component)
std::vector< Matrix > projectRing(const Matrix &W, Eigen::Index beads, Eigen::Index d)
double nuclearNorm(const Matrix &M)
Matrix positiveRoot(const Matrix &D)
void requireBlocks(const std::vector< Matrix > &blocks, Eigen::Index beads)
Matrix ringMatrix(const std::vector< Matrix > &blocks, Eigen::Index beads)
std::vector< Vector > beads