Skip to content

Commit

Permalink
style(pre-commit): autofix
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Jun 7, 2024
1 parent 6c93592 commit 33e2bef
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ class TreeStructuredParzenEstimator

TreeStructuredParzenEstimator() = delete;
TreeStructuredParzenEstimator(
const Direction direction, const int64_t n_startup_trials,
std::vector<double> & sample_mean, std::vector<double> & sample_stddev);
const Direction direction, const int64_t n_startup_trials, std::vector<double> & sample_mean,
std::vector<double> & sample_stddev);
void add_trial(const Trial & trial);
[[nodiscard]] Input get_next_input() const;

Expand All @@ -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<Trial> trials_;
int64_t above_num_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<double> & sample_mean, std::vector<double> & sample_stddev)
const Direction direction, const int64_t n_startup_trials, std::vector<double> & sample_mean,
std::vector<double> & sample_stddev)
: above_num_(0),
direction_(direction),
n_startup_trials_(n_startup_trials),
Expand Down Expand Up @@ -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<int64_t>(10),
static_cast<int64_t>(static_cast<double>(trials_.size()) * max_good_rate)
});
above_num_ = std::min(
{static_cast<int64_t>(10),
static_cast<int64_t>(static_cast<double>(trials_.size()) * max_good_rate)});
}

TreeStructuredParzenEstimator::Input TreeStructuredParzenEstimator::get_next_input() const
Expand Down Expand Up @@ -132,9 +130,9 @@ double TreeStructuredParzenEstimator::compute_log_likelihood_ratio(const Input &

auto log_sum_exp = [](const std::vector<double> & 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);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<double>(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<double>(scores.size()));

std::cout << method << ", mean = " << mean << ", stddev = " << stddev << std::endl;
Expand Down

0 comments on commit 33e2bef

Please sign in to comment.