GPRidge v1.0.0
GPR-accelerated saddle point searches on potential energy surfaces
☾
Toggle main menu visibility
Loading...
Searching...
No Matches
RFFModel.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
#ifndef GPR_ML_RFFMODEL_H_
6
#define GPR_ML_RFFMODEL_H_
7
8
#include <Eigen/Dense>
9
#include <memory>
10
11
#include "
../../backend/Macros.h
"
12
#include "
../../structures/Structures.h
"
13
#include "
../covariance_functions/SexpatCF.h
"
14
#include "
../linalg/KernelInverse.h
"
15
16
namespace
gpr
{
17
18
namespace
linalg
{
19
class
MpiCommunicator
;
20
class
DistributedState
;
21
}
// namespace linalg
22
51
class
RFFModel
{
52
public
:
53
RFFModel
() =
default
;
54
explicit
RFFModel
(
55
std::shared_ptr<const linalg::MpiCommunicator> communication);
56
57
enum class
NormalEquationBackend
{
58
Eigen
,
59
Cutlass
,
60
};
61
76
void
build
(
SexpatCF
& kernel,
const
AtomsConfiguration
& conf_info,
77
const
Observation
& training_data,
int
D_rff,
78
double
noise_var = 1e-6,
double
grad_noise_var = 1e-4);
79
87
void
calculatePotential
(
Observation
& image)
const
;
88
97
void
calculateVariance
(
Observation
& image)
const
;
98
107
[[nodiscard]]
bool
meanHessianVector
(
const
Eigen::VectorXd&
x
,
108
const
Eigen::VectorXd& v,
109
Eigen::VectorXd& action)
const
;
110
111
bool
isBuilt
()
const
112
{
113
return
built_;
114
}
115
[[nodiscard]]
NormalEquationBackend
normalEquationBackend
() const noexcept
116
{
117
return
normal_equation_backend_;
118
}
119
[[nodiscard]]
const
char
*
normalEquationBackendName
() const noexcept
120
{
121
switch
(normal_equation_backend_) {
122
case
NormalEquationBackend::Eigen
:
123
return
"eigen"
;
124
case
NormalEquationBackend::Cutlass
:
125
return
"cutlass"
;
126
}
127
return
"unknown"
;
128
}
129
130
private
:
131
std::shared_ptr<const linalg::MpiCommunicator> communication_;
132
std::shared_ptr<linalg::DistributedState> distributed_state_;
133
bool
built_ =
false
;
134
int
D_rff_ = 0;
135
NormalEquationBackend
normal_equation_backend_ =
136
NormalEquationBackend::Eigen
;
137
138
EigenMatrix
W_;
// (D_rff x d_feat) frequency matrix
139
Eigen::VectorXd b_;
// (D_rff,) random phases
140
double
c_ = 0.0;
// sigma * sqrt(2/D_rff)
141
142
Eigen::VectorXd alpha_;
// (D_rff + 1,) BLR weights (last entry = const)
143
144
// KernelInverse over the BLR system A = sum_r Z_r^T diag(prec_r) Z_r + I.
145
// Held by unique_ptr so the concrete impl is selected at build()-time:
146
// * scalapack build, np > 1 -> ScalapackPDPotrfInverse: A is scattered
147
// through the BLACS grid, factorised via pdpotrf, and consumed by
148
// pdtrsm-distributed solves. Per-instance L_dist_ keeps the RFF
149
// factorisation off the DistributedState singleton L cache that the
150
// GP-side cholesky_distributed owns (the cache pollution that
151
// SEGV'd calculateVarianceLaplaceDelta in PR-pre-A6).
152
// * eigen build OR np == 1 -> DenseLLTInverse: rank-local Eigen LLT;
153
// threaded BLAS via EIGEN_USE_BLAS gives single-rank parallelism.
154
// Both impls satisfy the same interface (solve / solve_mat / log_det /
155
// trace_inv_times); calculatePotential / calculateVariance consume them
156
// through the abstract base, no #ifdef leakage into the predict path.
157
std::unique_ptr<linalg::KernelInverse> inverse_;
158
159
double
e_ref_ = 0.0;
// training_data.E(0, 0); subtracted before
160
// BLR fit, added back to predict mean for
161
// numerical stability (matches ChemGP's
162
// RFF integration in chemgp-core/src/predict.rs).
163
164
AtomsConfiguration
conf_info_;
165
double
far_field_radius_ = 0.0;
166
};
167
168
}
// namespace gpr
169
170
#endif
// GPR_ML_RFFMODEL_H_
x
@ x
Definition
Enums.h:28
KernelInverse.h
Abstract operator interface for K^{-1} actions used by Laplace Hessian probe loops and Williams-Rasmu...
Macros.h
SexpatCF.h
Structures.h
gpr::RFFModel::normalEquationBackendName
const char * normalEquationBackendName() const noexcept
Definition
RFFModel.h:119
gpr::RFFModel::build
void build(SexpatCF &kernel, const AtomsConfiguration &conf_info, const Observation &training_data, int D_rff, double noise_var=1e-6, double grad_noise_var=1e-4)
Build the RFF model from trained hyperparameters and data.
Definition
RFFModel.cpp:42
gpr::RFFModel::normalEquationBackend
NormalEquationBackend normalEquationBackend() const noexcept
Definition
RFFModel.h:115
gpr::RFFModel::isBuilt
bool isBuilt() const
Definition
RFFModel.h:111
gpr::RFFModel::calculateVariance
void calculateVariance(Observation &image) const
Predict energy/gradient variance at test configurations.
Definition
RFFModel.cpp:464
gpr::RFFModel::calculatePotential
void calculatePotential(Observation &image) const
Predict energy and gradient at test configurations.
Definition
RFFModel.cpp:382
gpr::RFFModel::RFFModel
RFFModel()=default
gpr::RFFModel::NormalEquationBackend
NormalEquationBackend
Definition
RFFModel.h:57
gpr::RFFModel::NormalEquationBackend::Cutlass
@ Cutlass
Definition
RFFModel.h:59
gpr::RFFModel::NormalEquationBackend::Eigen
@ Eigen
Definition
RFFModel.h:58
gpr::RFFModel::meanHessianVector
bool meanHessianVector(const Eigen::VectorXd &x, const Eigen::VectorXd &v, Eigen::VectorXd &action) const
Exact Hessian of the predicted energy at x applied to v.
Definition
RFFModel.cpp:436
gpr::SexpatCF
Pair-type inverse-distance squared-exponential primitive.
Definition
SexpatCF.h:74
gpr::linalg::DistributedState
Definition
DistributedState.h:72
gpr::linalg::MpiCommunicator
Definition
MpiCommunicator.h:16
Eigen
Definition
CountedReal.h:166
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::AtomsConfiguration
Stores configurations of all atoms in the system.
Definition
Structures.h:832
gpr::Observation
Observation data: energy, gradient and positions.
Definition
Structures.h:1029
gpr
ml
RFFModel.h
Generated by
1.17.0
Generated by
Doxygen 1.17.0
Analytics by
Antics
provided by
TurtleTech ehf