Loading...
Searching...
No Matches
PriorMeanHessian.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// Copyright (c) gpridge developers
3// See LICENSE for details.
4//
5// Shared Cartesian pair-Hessian blocks for residual prior means.
6// ZBLPriorMean and MorsePriorMean both emit these; the GP Hessian-vector
7// path applies them without knowing which prior produced the pairs.
8
9#ifndef GPR_PRIOR_PRIOR_MEAN_HESSIAN_H_
10#define GPR_PRIOR_PRIOR_MEAN_HESSIAN_H_
11
12#include <Eigen/Core>
13#include <vector>
14
15namespace gpr {
16namespace priors {
17
21 Eigen::Index first;
22 Eigen::Index second;
23 Eigen::Matrix3d block;
24};
25
27template <typename Derived>
28[[nodiscard]] inline Eigen::MatrixXd applyPriorHessianPairs(
29 const std::vector<PriorHessianPair>& pairs,
30 const Eigen::MatrixBase<Derived>& directions)
31{
32 Eigen::MatrixXd result =
33 Eigen::MatrixXd::Zero(directions.rows(), directions.cols());
34 for (const auto& pair: pairs) {
35 if (pair.second < 0) {
36 result.middleRows(pair.first, 3) +=
37 pair.block * directions.middleRows(pair.first, 3);
38 continue;
39 }
40 const Eigen::MatrixXd value =
41 pair.block * (directions.middleRows(pair.first, 3) -
42 directions.middleRows(pair.second, 3));
43 result.middleRows(pair.first, 3) += value;
44 result.middleRows(pair.second, 3) -= value;
45 }
46 return result;
47}
48
50inline void addPriorHessianPairs(const std::vector<PriorHessianPair>& pairs,
51 Eigen::MatrixXd& hessian)
52{
53 for (const auto& pair: pairs) {
54 hessian.block<3, 3>(pair.first, pair.first) += pair.block;
55 if (pair.second < 0) continue;
56 hessian.block<3, 3>(pair.first, pair.second) -= pair.block;
57 hessian.block<3, 3>(pair.second, pair.first) -= pair.block;
58 hessian.block<3, 3>(pair.second, pair.second) += pair.block;
59 }
60}
61
62} // namespace priors
63} // namespace gpr
64
65#endif // GPR_PRIOR_PRIOR_MEAN_HESSIAN_H_
Prior distributions and prior-mean functions for the GP.
void addPriorHessianPairs(const std::vector< PriorHessianPair > &pairs, Eigen::MatrixXd &hessian)
Add the same pair blocks to a dense Cartesian Hessian.
Eigen::MatrixXd applyPriorHessianPairs(const std::vector< PriorHessianPair > &pairs, const Eigen::MatrixBase< Derived > &directions)
Apply physical prior curvature without forming a dense Hessian.
Gaussian-process regression, kernels, priors, and the searches that run on the surrogate.
Definition Macros.h:16
Pair term of a prior Hessian: block acts on x_first - x_second. A negative second is a fixed partner,...