GPRidge v1.0.0
GPR-accelerated saddle point searches on potential energy surfaces
☾
Toggle main menu visibility
Loading...
Searching...
No Matches
DenseLLTInverse.cpp
Go to the documentation of this file.
1
// SPDX-License-Identifier: MIT
2
// Copyright (c) gpridge developers
3
// See LICENSE for details.
4
5
#include "
DenseLLTInverse.h
"
6
7
#include <stdexcept>
8
9
#include "
SerialEigenThreads.h
"
10
11
namespace
gpr
{
12
namespace
linalg
{
13
namespace
{
14
// LLT blocking follows Eigen::nbThreads. One thread is the product the
15
// compact posterior compares against; a larger team is a different sum.
16
using
SerialEigenFactor =
ScopedSerialEigenThreads
;
17
}
// namespace
18
19
bool
DenseLLTInverse::factorise
(
const
EigenMatrix
& K)
20
{
21
[[maybe_unused]]
const
SerialEigenFactor serial_factor;
22
llt_.compute(K);
23
factored_ = (llt_.info() == Eigen::Success);
24
return
factored_;
25
}
26
27
Eigen::VectorXd
DenseLLTInverse::solve
(
const
Eigen::VectorXd& b)
const
28
{
29
if
(!factored_) {
30
throw
std::logic_error(
31
"DenseLLTInverse: solve called before factorise"
);
32
}
33
[[maybe_unused]]
const
SerialEigenFactor serial_factor;
34
return
llt_.solve(b);
35
}
36
37
EigenMatrix
DenseLLTInverse::solve_mat
(
const
EigenMatrix
& B)
const
38
{
39
if
(!factored_) {
40
throw
std::logic_error(
41
"DenseLLTInverse: solve_mat called before factorise"
);
42
}
43
[[maybe_unused]]
const
SerialEigenFactor serial_factor;
44
return
llt_.solve(B);
45
}
46
47
double
DenseLLTInverse::log_det
()
const
48
{
49
if
(!factored_) {
50
throw
std::logic_error(
51
"DenseLLTInverse: log_det called before factorise"
);
52
}
53
// log |K| = log |L L^T| = 2 sum_i log L_ii. matrixLLT() returns the
54
// packed in-place LLT storage (lower triangle holds L); .diagonal()
55
// is a non-allocating view of L's diagonal entries. Cost is O(n)
56
// reads, no allocation. Numerically identical to reading the
57
// diagonal of the materialised lower factor.
58
return
2.0 * llt_.matrixLLT().diagonal().array().log().sum();
59
}
60
61
double
DenseLLTInverse::trace_inv_times
(
const
EigenMatrix
& A)
const
62
{
63
if
(!factored_) {
64
throw
std::logic_error(
65
"DenseLLTInverse: trace_inv_times called before factorise"
);
66
}
67
// tr(K^{-1} A) = tr(L^{-T} L^{-1} A). Solve K Z = A then sum the
68
// diagonal of Z. The two-step trsm route avoids materialising
69
// K^{-1} explicitly, so the cost is one O(n^2) solve per RHS column
70
// times n columns = O(n^3) total -- same as forming K^{-1} A but
71
// without the upper-triangle pollution of dpotri.
72
[[maybe_unused]]
const
SerialEigenFactor serial_factor;
73
const
EigenMatrix
Z = llt_.solve(A);
74
return
Z.trace();
75
}
76
77
}
// namespace linalg
78
}
// namespace gpr
DenseLLTInverse.h
Rank-local Eigen LLT implementation of KernelInverse.
SerialEigenThreads.h
gpr::linalg::DenseLLTInverse::trace_inv_times
double trace_inv_times(const EigenMatrix &A) const override
Definition
DenseLLTInverse.cpp:61
gpr::linalg::DenseLLTInverse::solve_mat
EigenMatrix solve_mat(const EigenMatrix &B) const override
Solve K X = B for a multi right-hand side.
Definition
DenseLLTInverse.cpp:37
gpr::linalg::DenseLLTInverse::solve
Eigen::VectorXd solve(const Eigen::VectorXd &b) const override
Solve K x = b for a single right-hand side.
Definition
DenseLLTInverse.cpp:27
gpr::linalg::DenseLLTInverse::factorise
bool factorise(const EigenMatrix &K)
Definition
DenseLLTInverse.cpp:19
gpr::linalg::DenseLLTInverse::log_det
double log_det() const override
Returns the log determinant of K.
Definition
DenseLLTInverse.cpp:47
gpr::linalg::ScopedSerialEigenThreads
Definition
SerialEigenThreads.h:23
gpr::linalg
Dense and structured linear algebra behind the GP: Cholesky and eigen solvers, linear operators,...
Definition
ConditionedKernel.h:14
gpr
Gaussian-process regression, kernels, priors, and the searches that run on the surrogate.
Definition
Macros.h:16
gpr::EigenMatrix
Eigen::Matrix< double, EigenDynamic, EigenDynamic, EigenMatrixStorage > EigenMatrix
Definition
Macros.h:20
gpr
linalg
DenseLLTInverse.cpp
Generated by
1.17.0
Generated by
Doxygen 1.17.0
Analytics by
Antics
provided by
TurtleTech ehf