Loading...
Searching...
No Matches
HyperparameterDomain.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// Copyright (c) gpridge developers
3// See LICENSE for details.
4#pragma once
5
6#include <Eigen/Core>
7#include <cmath>
8#include <limits>
9
12
13namespace gpr::detail {
14
15// Packed hyperparameters are logarithms of positive kernel scales and noise.
16// Reject a proposal before unpacking so the accepted covariance state survives
17// an underflow, overflow, or non-finite optimizer trial.
18inline bool logParametersAreRepresentable(const Eigen::VectorXd& theta)
19{
20 for (Eigen::Index j = 0; j < theta.size(); ++j) {
21 const double value = numerics::exp(theta(j));
22 if (!(value > 0.0) || !std::isfinite(value)) return false;
23 }
24 return true;
25}
26
27inline bool rejectInvalidHyperparameters(const Eigen::VectorXd& theta,
28 EnergyAndGradient& result)
29{
30 if (logParametersAreRepresentable(theta)) return false;
31 result.energy = std::numeric_limits<double>::infinity();
32 result.gradient = Eigen::VectorXd::Zero(theta.size());
33 return true;
34}
35
36} // namespace gpr::detail
double exp(double x) noexcept