20 double log_ls_min,
double log_ls_max,
21 double log_noise_min,
double log_noise_max)
22 : n_ls_per_dim_(n_ls_per_dim),
25 log_ls_min_(log_ls_min),
26 log_ls_max_(log_ls_max),
27 log_noise_min_(log_noise_min),
28 log_noise_max_(log_noise_max)
30 if (n_ls_per_dim < 2 || n_noise < 2 || n_refine < 0 ||
31 !std::isfinite(log_ls_min) || !std::isfinite(log_ls_max) ||
32 !std::isfinite(log_noise_min) || !std::isfinite(log_noise_max) ||
33 log_ls_min > log_ls_max || log_noise_min > log_noise_max) {
34 throw std::invalid_argument(
"invalid ARD search grid");
40 int n_pairtypes)
const
42 if (
y.size() == 0 || !
y.allFinite() || n_pairtypes <= 0) {
43 throw std::invalid_argument(
44 "ARD search needs finite targets and positive dimensions");
46 std::exception_ptr failure;
52 std::vector<double> ls_grid(n_ls_per_dim_);
53 for (
int i = 0; i < n_ls_per_dim_; ++i) {
54 ls_grid[i] = std::pow(10.0, log_ls_min_ + (log_ls_max_ - log_ls_min_) *
55 i / (n_ls_per_dim_ - 1));
59 std::vector<double> noise_grid(n_noise_);
60 for (
int i = 0; i < n_noise_; ++i) {
62 std::pow(10.0, log_noise_min_ + (log_noise_max_ - log_noise_min_) *
68 if (n_pairtypes == 1) {
69 const int n_total = n_ls_per_dim_ * n_noise_;
70 int best_idx = n_total;
77 std::numeric_limits<double>::infinity();
78 int local_best_idx = n_total;
82#pragma omp for nowait schedule(static)
84 for (
int idx = 0; idx < n_total; ++idx) {
85 int i_ls = idx / n_noise_;
86 int i_noise = idx % n_noise_;
87 double ls = ls_grid[i_ls];
88 double noise = noise_grid[i_noise];
92 if (K.rows() !=
y.size() || K.cols() !=
y.size() ||
94 throw std::invalid_argument(
95 "kernel matrix must match the finite targets");
97 Eigen::SelfAdjointEigenSolver<EigenMatrix> solver(K);
101 solver.eigenvectors(),
y);
105 if (std::isfinite(ll) &&
108 idx < local_best_idx))) {
110 local_best_idx = idx;
118#pragma omp critical(gpr_ard_search_error)
121 if (!failure) failure = std::current_exception();
130 if (local_best_idx < n_total &&
133 local_best_idx < best_idx))) {
135 best_idx = local_best_idx;
143 }
else if (n_pairtypes == 2) {
144 const int n_total = n_ls_per_dim_ * n_ls_per_dim_ * n_noise_;
145 int best_idx = n_total;
152 std::numeric_limits<double>::infinity();
153 int local_best_idx = n_total;
157#pragma omp for nowait schedule(static)
159 for (
int idx = 0; idx < n_total; ++idx) {
160 int i_ls1 = idx / (n_ls_per_dim_ * n_noise_);
161 int rem = idx % (n_ls_per_dim_ * n_noise_);
162 int i_ls2 = rem / n_noise_;
163 int i_noise = rem % n_noise_;
164 double ls1 = ls_grid[i_ls1];
165 double ls2 = ls_grid[i_ls2];
166 double noise = noise_grid[i_noise];
170 if (K.rows() !=
y.size() || K.cols() !=
y.size() ||
172 throw std::invalid_argument(
173 "kernel matrix must match the finite targets");
175 Eigen::SelfAdjointEigenSolver<EigenMatrix> solver(K);
179 solver.eigenvectors(),
y);
183 if (std::isfinite(ll) &&
186 idx < local_best_idx))) {
188 local_best_idx = idx;
196#pragma omp critical(gpr_ard_search_error)
199 if (!failure) failure = std::current_exception();
208 if (local_best_idx < n_total &&
211 local_best_idx < best_idx))) {
213 best_idx = local_best_idx;
224 const int n_total = n_ls_per_dim_ * n_noise_;
225 int best_idx = n_total;
232 std::numeric_limits<double>::infinity();
233 int local_best_idx = n_total;
237#pragma omp for nowait schedule(static)
239 for (
int idx = 0; idx < n_total; ++idx) {
240 int i_ls = idx / n_noise_;
241 int i_noise = idx % n_noise_;
242 double ls = ls_grid[i_ls];
243 double noise = noise_grid[i_noise];
244 std::vector<double> ls_vec(n_pairtypes, ls);
248 if (K.rows() !=
y.size() || K.cols() !=
y.size() ||
250 throw std::invalid_argument(
251 "kernel matrix must match the finite targets");
253 Eigen::SelfAdjointEigenSolver<EigenMatrix> solver(K);
257 solver.eigenvectors(),
y);
261 if (std::isfinite(ll) &&
264 idx < local_best_idx))) {
266 local_best_idx = idx;
274#pragma omp critical(gpr_ard_search_error)
277 if (!failure) failure = std::current_exception();
286 if (local_best_idx < n_total &&
289 local_best_idx < best_idx))) {
291 best_idx = local_best_idx;
301 if (failure) std::rethrow_exception(failure);