diff --git a/localization/tree_structured_parzen_estimator/include/tree_structured_parzen_estimator/tree_structured_parzen_estimator.hpp b/localization/tree_structured_parzen_estimator/include/tree_structured_parzen_estimator/tree_structured_parzen_estimator.hpp index b081482adb8ec..e475f707ade2d 100644 --- a/localization/tree_structured_parzen_estimator/include/tree_structured_parzen_estimator/tree_structured_parzen_estimator.hpp +++ b/localization/tree_structured_parzen_estimator/include/tree_structured_parzen_estimator/tree_structured_parzen_estimator.hpp @@ -56,8 +56,8 @@ class TreeStructuredParzenEstimator TreeStructuredParzenEstimator() = delete; TreeStructuredParzenEstimator( - const Direction direction, const int64_t n_startup_trials, - std::vector & sample_mean, std::vector & sample_stddev); + const Direction direction, const int64_t n_startup_trials, std::vector & sample_mean, + std::vector & sample_stddev); void add_trial(const Trial & trial); [[nodiscard]] Input get_next_input() const; @@ -69,8 +69,7 @@ class TreeStructuredParzenEstimator [[nodiscard]] double compute_log_likelihood_ratio(const Input & input) const; [[nodiscard]] static double log_gaussian_pdf( - const Input & input, const Input & mu, const Input & sigma - ) ; + const Input & input, const Input & mu, const Input & sigma); std::vector trials_; int64_t above_num_; diff --git a/localization/tree_structured_parzen_estimator/src/tree_structured_parzen_estimator.cpp b/localization/tree_structured_parzen_estimator/src/tree_structured_parzen_estimator.cpp index c0f4217505f1a..cb0d0f67ab80c 100644 --- a/localization/tree_structured_parzen_estimator/src/tree_structured_parzen_estimator.cpp +++ b/localization/tree_structured_parzen_estimator/src/tree_structured_parzen_estimator.cpp @@ -23,8 +23,8 @@ std::mt19937_64 TreeStructuredParzenEstimator::engine(std::random_device{}()); TreeStructuredParzenEstimator::TreeStructuredParzenEstimator( - const Direction direction, const int64_t n_startup_trials, - std::vector & sample_mean, std::vector & sample_stddev) + const Direction direction, const int64_t n_startup_trials, std::vector & sample_mean, + std::vector & sample_stddev) : above_num_(0), direction_(direction), n_startup_trials_(n_startup_trials), @@ -56,11 +56,9 @@ void TreeStructuredParzenEstimator::add_trial(const Trial & trial) std::sort(trials_.begin(), trials_.end(), [this](const Trial & lhs, const Trial & rhs) { return (direction_ == Direction::MAXIMIZE ? lhs.score > rhs.score : lhs.score < rhs.score); }); - above_num_ = - std::min({ - static_cast(10), - static_cast(static_cast(trials_.size()) * max_good_rate) - }); + above_num_ = std::min( + {static_cast(10), + static_cast(static_cast(trials_.size()) * max_good_rate)}); } TreeStructuredParzenEstimator::Input TreeStructuredParzenEstimator::get_next_input() const @@ -132,9 +130,9 @@ double TreeStructuredParzenEstimator::compute_log_likelihood_ratio(const Input & auto log_sum_exp = [](const std::vector & log_vec) { const double max = *std::max_element(log_vec.begin(), log_vec.end()); - double sum = std::accumulate(log_vec.begin(), log_vec.end(), 0.0, - [max](double total, double log_v) {return total + std::exp(log_v - max);} - ); + double sum = std::accumulate( + log_vec.begin(), log_vec.end(), 0.0, + [max](double total, double log_v) { return total + std::exp(log_v - max); }); return max + std::log(sum); }; diff --git a/localization/tree_structured_parzen_estimator/test/test_tpe.cpp b/localization/tree_structured_parzen_estimator/test/test_tpe.cpp index 2f57c2fb39ff2..357c86289ef1f 100644 --- a/localization/tree_structured_parzen_estimator/test/test_tpe.cpp +++ b/localization/tree_structured_parzen_estimator/test/test_tpe.cpp @@ -56,9 +56,9 @@ TEST(TreeStructuredParzenEstimatorTest, TPE_is_better_than_random_search_on_sphe const double sum = std::accumulate(scores.begin(), scores.end(), 0.0); const double mean = sum / static_cast(scores.size()); mean_scores.push_back(mean); - double sq_sum = std::accumulate(scores.begin(), scores.end(), 0.0, - [mean](double total, double score) {return total + (score - mean) * (score - mean);} - ); + double sq_sum = std::accumulate( + scores.begin(), scores.end(), 0.0, + [mean](double total, double score) { return total + (score - mean) * (score - mean); }); const double stddev = std::sqrt(sq_sum / static_cast(scores.size())); std::cout << method << ", mean = " << mean << ", stddev = " << stddev << std::endl;