Loading...
Searching...
No Matches
SexpatCF.inl
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// Copyright (c) gpridge developers
3// See LICENSE for details.
4
5//
6// SexpatCF.inl
7// gpr_dimer
8//
9// Created by Maxim Masterov on 21/01/2021.
10//
11
12#ifndef SexpatCF_inl
13#define SexpatCF_inl
14
16
17namespace gpr {
18
19inline void SexpatCF::setMagnSigma2(double value)
20{
21 magnSigma2 = value;
22}
23
24inline void SexpatCF::setLengthScale(double value)
25{
26 auto& lengths = getLengthScaleRef();
27 if (lengths.size() == 0) lengths.resize(1, 1);
28 lengths.setConstant(value);
30}
31
32inline void SexpatCF::setFarFieldRadius(double radius)
33{
34 dist_calculator_.setFarFieldRadius(radius);
35 far_field_radius_ = dist_calculator_.farFieldRadius();
36}
37
39{
41 conf_info = value;
42}
43
44inline void SexpatCF::setParameters(const Eigen::VectorXd& w)
45{
46 auto& lengths = getLengthScaleRef();
47 magnSigma2 = numerics::exp(w(0));
48 for (Eigen::Index n = 0; n < lengths.size(); ++n)
49 *(lengths.data() + n) = numerics::exp(w(n + 1));
51}
52
54{
55 return magnSigma2;
56}
57
59{
60 return usesManifoldChart() ? chart_length_scale_ : lengthScale;
61}
62
64{
65 return usesManifoldChart() ? chart_length_scale_ : lengthScale;
66}
67
68inline void SexpatCF::clear()
69{
71 initialized = false;
72 magnSigma2 = 0.;
73 lengthScale.setConstant(0.);
74 chart_length_scale_.setConstant(0.);
75 conf_info.clearDistribution();
76}
77
79{
80 prior_parameters_gaussian.setParameters(prior);
81}
82
84{
85 prior_parameters_sqrtt.setParameters(prior);
86}
87
89{
90 prior_parameters_lognormal.setParameters(prior);
91}
92
94{
95 return prior_parameters_gaussian;
96}
97
99{
100 return prior_parameters_sqrtt;
101}
102
104{
105 return prior_parameters_lognormal;
106}
107
108inline void SexpatCF::setUseLogNormalMagnPrior(bool enabled) noexcept
109{
110 use_lognormal_magn_prior_ = enabled;
111}
112
113inline bool SexpatCF::useLogNormalMagnPrior() const noexcept
114{
115 return use_lognormal_magn_prior_;
116}
117
119{
120 model_profile_ = profile;
124 // Chart and heat components have independent configuration; choosing
125 // a hyperparameter prior preserves the assembled covariance.
126 }
127}
128
129inline void SexpatCF::setHierarchicalPrior(const Eigen::VectorXd& mu_log,
130 double s2_log)
131{
132 hierarchical_mu_log_ = mu_log;
133 hierarchical_s2_log_ = s2_log;
134 hierarchical_s2_log_per_.resize(0);
135 use_hierarchical_prior_ = (mu_log.size() > 0 && s2_log > 0.0);
136}
137
138inline void SexpatCF::setHierarchicalPrior(const Eigen::VectorXd& mu_log,
139 double s2_log,
140 const Eigen::VectorXd& s2_log_per)
141{
142 setHierarchicalPrior(mu_log, s2_log);
143 hierarchical_s2_log_per_ =
144 s2_log_per.size() == mu_log.size() ? s2_log_per : Eigen::VectorXd();
145 // A prior with no shared width still applies to the parameters that
146 // carry their own.
147 use_hierarchical_prior_ =
148 mu_log.size() > 0 &&
149 (s2_log > 0.0 || (hierarchical_s2_log_per_.array() > 0.0).any());
150}
151
153{
154 use_hierarchical_prior_ = false;
155 hierarchical_mu_log_.resize(0);
156 hierarchical_s2_log_ = 0.0;
157 hierarchical_s2_log_per_.resize(0);
158 hierarchical_anchor_.clear();
159}
160
161inline void SexpatCF::setPcLengthScalePrior(const Eigen::VectorXd& lambda)
162{
163 pc_lambda_ = lambda;
164 use_pc_lengthscale_prior_ = (lambda.size() > 0);
165}
166
168{
169 use_pc_lengthscale_prior_ = false;
170 pc_lambda_.resize(0);
171}
172
173inline Eigen::VectorXd SexpatCF::combineParameters()
174{
175 const auto& lengths = getLengthScaleRef();
176 Eigen::VectorXd res(1 + lengths.size());
177
178 res(0) = numerics::log(magnSigma2);
179
180 for (Eigen::Index n = 0; n < lengths.size(); ++n)
181 res(n + 1) = numerics::log(*(lengths.data() + n));
182
183 // NOTE: Only magnSigma2 and lengths are packed, matching MATLAB
184 // gpcf_sexpat_pak. Prior parameters are not part of the optimization
185 // vector.
186 return res;
187}
188
189} /* namespace gpr */
190
191#endif /* SexpatCF_inl */
Class of prior parameters.
Definition PriorBase.h:23
void setParameters(const Eigen::VectorXd &w)
Set parameters of this covariance function using the provided vector.
Definition SexpatCF.inl:44
PriorBase getPriorParametersSqrtt()
Definition SexpatCF.inl:98
void setUseLogNormalMagnPrior(bool enabled) noexcept
Definition SexpatCF.inl:108
void setFarFieldRadius(double radius)
Definition SexpatCF.inl:32
void setPcLengthScalePrior(const Eigen::VectorXd &lambda)
Definition SexpatCF.inl:161
void clearGeodesicHeatKernel() noexcept
Definition SexpatCF.cpp:723
void setModelProfile(GPModelProfile profile)
Definition SexpatCF.inl:118
void setLengthScale(double value)
Definition SexpatCF.inl:24
Eigen::VectorXd combineParameters()
Combine parameters of the covariance function into one Eigen vector.
Definition SexpatCF.inl:173
void setPriorParametersSqrtt(const PriorBase &prior)
Definition SexpatCF.inl:83
PriorBase getPriorParametersGaussian()
Definition SexpatCF.inl:93
bool usesManifoldChart() const noexcept
Definition SexpatCF.h:616
void clearHierarchicalPrior()
Definition SexpatCF.inl:152
double getMagnSigma2()
Definition SexpatCF.inl:53
void setHierarchicalPrior(const Eigen::VectorXd &mu_log, double s2_log)
Definition SexpatCF.inl:129
void clearPcLengthScalePrior()
Definition SexpatCF.inl:167
void setMagnSigma2(double value)
Definition SexpatCF.inl:19
void setPriorParametersGaussian(const PriorBase &prior)
Definition SexpatCF.inl:78
void setPriorParametersLogNormal(const PriorBase &prior)
Definition SexpatCF.inl:88
PriorBase getPriorParametersLogNormal()
Definition SexpatCF.inl:103
FieldMatrixd & getLengthScaleRef()
Definition SexpatCF.inl:58
bool useLogNormalMagnPrior() const noexcept
Definition SexpatCF.inl:113
void setConfInfo(const AtomsConfiguration &value)
Definition SexpatCF.inl:38
void clearDistanceCache()
Invalidate the distance cache.
double log(double x) noexcept
double exp(double x) noexcept
Gaussian-process regression, kernels, priors, and the searches that run on the surrogate.
Definition Macros.h:16
bool usesClassicJointEnergyForcePrior(GPModelProfile profile) noexcept
Definition Structures.h:206
GPModelProfile
Definition Structures.h:201
Eigen::Matrix< double, EigenDynamic, EigenDynamic, FieldMatrixStorage > FieldMatrixd
Definition Macros.h:25
Stores configurations of all atoms in the system.
Definition Structures.h:832