Skip to content

Commit

Permalink
Added error heuristic with region size.
Browse files Browse the repository at this point in the history
  • Loading branch information
adolfomunoz committed Feb 27, 2024
1 parent f3fd995 commit 750a7a2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion main/compilation-tests/multiple-parameters-sequence.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ int main() {
LoggerProgress logger("New Fubini");
std::vector<float> sol(bins,0.0f);
integrate(integrator_adaptive_fubini_variance_reduction_parallel<4>(
nested(simpson,trapezoidal),error_heuristic_default(error_metric_absolute()),128,10,
nested(simpson,trapezoidal),error_heuristic_size(error_metric_absolute(),1.e-5),128,10,
rr_error_region(),cv_optimize_weight(),region_sampling_uniform(),samples*10),
sol,f,range_infinite(-1.0,-1.0,1.0,1.0),logger);
for (float v : sol) std::cout<<std::fixed<<std::setprecision(2)<<std::setw(4)<<v<<" ";
Expand Down
26 changes: 26 additions & 0 deletions src/nested/error-heuristic.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,31 @@ class error_heuristic_default {
}
};

template<typename ErrorMetric>
class error_heuristic_size {
ErrorMetric error_metric;
double size_weight;
public:
error_heuristic_size(const ErrorMetric& em, double sw = 1.e-5) :
error_metric(em), size_weight(sw) {}

template<typename R>
auto operator()(const R& region) const {
auto max_err = region.error(0,error_metric);
max_err += size_weight*std::abs(region.range().max(0) - region.range().min(0));
std::size_t max_dim = 0;
auto err = max_err;
for (std::size_t d = 1; d<R::dimensions; ++d) {
err = region.error(d,error_metric) +
size_weight*std::abs(region.range().max(d) - region.range().min(d));
if (err>max_err) {
max_err = err; max_dim = d;
}
}
return std::tuple(max_err,max_dim);
}
};



}

0 comments on commit 750a7a2

Please sign in to comment.