Loading...
Searching...
No Matches
ExpectedImprovement.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// Copyright (c) gpridge developers
3// See LICENSE for details.
4
10
11#ifndef GPR_BO_EXPECTED_IMPROVEMENT_H_
12#define GPR_BO_EXPECTED_IMPROVEMENT_H_
13
14#include <cmath>
15#include <limits>
16
17namespace gpr {
18namespace bo {
19
27inline double expectedImprovementScore(double mu, double mu_best, double sigma)
28{
29 if (!(sigma > 0.0) || !std::isfinite(sigma) || !std::isfinite(mu) ||
30 !std::isfinite(mu_best)) {
31 return 0.0;
32 }
33 const double z = (mu - mu_best) / sigma;
34 const double phi = std::exp(-0.5 * z * z) / std::sqrt(2.0 * M_PI);
35 const double Phi = 0.5 * std::erfc(-z / std::sqrt(2.0));
36 const double ei = (mu - mu_best) * Phi + sigma * phi;
37 return (std::isfinite(ei) && ei > 0.0) ? ei : 0.0;
38}
39
46inline double expectedImprovementForMinimum(double mu, double best,
47 double sigma)
48{
49 return expectedImprovementScore(-mu, -best, sigma);
50}
51
60inline double probabilityOfFeasibility(double mu, double sigma,
61 double threshold = 0.0)
62{
63 if (!(sigma >= 0.0) || !std::isfinite(sigma) || !std::isfinite(mu) ||
64 !std::isfinite(threshold)) {
65 return 0.0;
66 }
67 if (sigma == 0.0) return mu <= threshold ? 1.0 : 0.0;
68 return 0.5 * std::erfc(-(threshold - mu) / (sigma * std::sqrt(2.0)));
69}
70
79inline double constrainedExpectedImprovementForMinimum(double mu, double best,
80 double sigma,
81 double constraint_mu,
82 double constraint_sigma)
83{
84 return expectedImprovementForMinimum(mu, best, sigma) *
85 probabilityOfFeasibility(constraint_mu, constraint_sigma);
86}
87
93inline double lowerConfidenceBound(double mu, double sigma, double kappa)
94{
95 if (!(sigma >= 0.0) || !std::isfinite(sigma) || !std::isfinite(mu) ||
96 !(kappa >= 0.0) || !std::isfinite(kappa)) {
97 return std::numeric_limits<double>::infinity();
98 }
99 return mu - kappa * sigma;
100}
101
102} // namespace bo
103} // namespace gpr
104
105#endif // GPR_BO_EXPECTED_IMPROVEMENT_H_
@ z
Definition Enums.h:28
double probabilityOfFeasibility(double mu, double sigma, double threshold=0.0)
Probability that a normal constraint value is feasible.
double expectedImprovementForMinimum(double mu, double best, double sigma)
Expected improvement for a minimizer.
double expectedImprovementScore(double mu, double mu_best, double sigma)
Jones expected improvement for a maximizer.
double constrainedExpectedImprovementForMinimum(double mu, double best, double sigma, double constraint_mu, double constraint_sigma)
Constrained expected improvement for a minimizer.
double lowerConfidenceBound(double mu, double sigma, double kappa)
Lower confidence bound for a minimizer, mu - kappa * sigma.
Gaussian-process regression, kernels, priors, and the searches that run on the surrogate.
Definition Macros.h:16