17 log_noise_min_(log_noise_min),
18 log_noise_max_(log_noise_max)
25 double best_log_noise = 0.0;
26 double best_value = std::numeric_limits<double>::infinity();
31GridResult searchGrid(
const std::vector<double>& log_noise_vals,
35 result.best_value = std::numeric_limits<double>::infinity();
38 for (
int i = 0; i < static_cast<int>(log_noise_vals.size()); ++i) {
39 double noise_var = std::pow(10.0, log_noise_vals[i]);
40 double val = eval_fn(noise_var);
41 if (std::isfinite(val) && val < result.best_value) {
42 result.best_value = val;
43 result.best_log_noise = log_noise_vals[i];
56 double lo = log_noise_min_;
57 double hi = log_noise_max_;
60 best.best_value = std::numeric_limits<double>::infinity();
62 for (
int refine = 0; refine <= n_refine_; ++refine) {
63 std::vector<double> grid(n_grid_);
64 for (
int i = 0; i < n_grid_; ++i) {
65 grid[i] = lo + (hi - lo) * i / (n_grid_ - 1);
68 auto result = searchGrid(
69 grid, [&](
double nv) {
return likelihood.
evaluateGP(nv); });
70 total_evals += n_grid_;
72 if (result.best_value < best.best_value) {
77 double margin = (hi - lo) / n_grid_;
78 lo = best.best_log_noise - margin;
79 hi = best.best_log_noise + margin;
82 double best_noise = std::pow(10.0, best.best_log_noise);
83 return {best_noise, best.best_value,
91 double lo = log_noise_min_;
92 double hi = log_noise_max_;
95 best.best_value = std::numeric_limits<double>::infinity();
97 for (
int refine = 0; refine <= n_refine_; ++refine) {
98 std::vector<double> grid(n_grid_);
99 for (
int i = 0; i < n_grid_; ++i) {
100 grid[i] = lo + (hi - lo) * i / (n_grid_ - 1);
103 auto result = searchGrid(
104 grid, [&](
double nv) {
return likelihood.
evaluateTP(nv, a, b); });
105 total_evals += n_grid_;
107 if (result.best_value < best.best_value) {
111 double margin = (hi - lo) / n_grid_;
112 lo = best.best_log_noise - margin;
113 hi = best.best_log_noise + margin;
116 double best_noise = std::pow(10.0, best.best_log_noise);
117 return {best_noise, best.best_value,
118 likelihood.
tpPrefactor(best_noise, a, b), total_evals};
Exponential grid search for noise hyperparameter optimization.
double evaluateGP(double noise_variance) const
GP negative log marginal likelihood at given noise level.
double evaluateTP(double noise_variance, double a, double b) const
TP negative log marginal likelihood at given noise level.
double analyticalPrefactor(double noise_variance) const
Analytically optimal GP prefactor (signal variance).
double tpPrefactor(double noise_variance, double a, double b) const
TP prefactor from inverse-gamma hyperprior.
NoiseSearchResult searchTP(const FactorizedLikelihood &likelihood, double a, double b) const
Search for optimal noise using TP factorized likelihood.
NoiseSearchResult searchGP(const FactorizedLikelihood &likelihood) const
Search for optimal noise using GP factorized likelihood.
NoiseGridSearch(int n_grid=80, int n_refine=2, double log_noise_min=-10.0, double log_noise_max=2.0)
Configure the grid search.
Gaussian-process regression, kernels, priors, and the searches that run on the surrogate.
Result of a noise grid search.