Loading...
Searching...
No Matches
ARDGridSearch.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// Copyright (c) gpridge developers
3// See LICENSE for details.
4
18
19#ifndef GPR_ML_ARDGRIDSEARCH_H_
20#define GPR_ML_ARDGRIDSEARCH_H_
21
22#include <Eigen/Dense>
23#include <cmath>
24#include <functional>
25#include <limits>
26#include <vector>
27
29
30namespace gpr {
31
36 std::vector<double> best_lengthscales;
37 // Default-initialised so a search that finds no finite likelihood returns
38 // defined values. searchGP only writes best_noise / best_prefactor inside
39 // the `ll < best_likelihood` branch, so if every grid point yields a
40 // non-finite likelihood -- a kernel singular across the whole grid -- the
41 // members were returned to the caller uninitialised, and
42 // best_likelihood == infinity is the only signal that happened.
43 double best_noise = std::numeric_limits<double>::quiet_NaN();
44 double best_likelihood = std::numeric_limits<double>::infinity();
45 double best_prefactor = std::numeric_limits<double>::quiet_NaN();
47
49 [[nodiscard]] bool valid() const noexcept
50 {
51 return std::isfinite(best_likelihood);
52 }
53};
54
58using KernelMatrixBuilder = std::function<EigenMatrix(
59 const std::vector<double>& lengthscales, double noise)>;
60
65public:
66 ARDGridSearch(int n_ls_per_dim = 10, int n_noise = 20, int n_refine = 1,
67 double log_ls_min = -3.0, double log_ls_max = 1.0,
68 double log_noise_min = -10.0, double log_noise_max = 2.0);
69
79 ARDSearchResult searchGP(const Eigen::VectorXd& y,
80 KernelMatrixBuilder kernel_builder,
81 int n_pairtypes) const;
82
83private:
84 int n_ls_per_dim_;
85 int n_noise_;
86 int n_refine_;
87 double log_ls_min_, log_ls_max_;
88 double log_noise_min_, log_noise_max_;
89};
90
91} // namespace gpr
92
93#endif // GPR_ML_ARDGRIDSEARCH_H_
@ y
Definition Enums.h:28
ARDSearchResult searchGP(const Eigen::VectorXd &y, KernelMatrixBuilder kernel_builder, int n_pairtypes) const
Search for optimal (lengthscales, noise) using GP likelihood.
ARDGridSearch(int n_ls_per_dim=10, int n_noise=20, int n_refine=1, double log_ls_min=-3.0, double log_ls_max=1.0, double log_noise_min=-10.0, double log_noise_max=2.0)
Gaussian-process regression, kernels, priors, and the searches that run on the surrogate.
Definition Macros.h:16
Eigen::Matrix< double, EigenDynamic, EigenDynamic, EigenMatrixStorage > EigenMatrix
Definition Macros.h:20
std::function< EigenMatrix( const std::vector< double > &lengthscales, double noise)> KernelMatrixBuilder
Kernel matrix builder: given lengthscales and noise, return K_XX.
Result of ARD grid search.
bool valid() const noexcept
Whether the search actually found a usable point.
std::vector< double > best_lengthscales