Readable names

This commit is contained in:
Georgy Evtushenko
2024-01-10 10:12:19 -08:00
parent bd23bcac31
commit 6b5315fc8f
2 changed files with 8 additions and 6 deletions

View File

@@ -40,7 +40,9 @@ class entropy_criterion final : public stopping_criterion
// TODO The window size should be user-configurable
nvbench::detail::ring_buffer<nvbench::float64_t> m_entropy_tracker{299};
std::vector<nvbench::float64_t> m_ps;
// Used to avoid re-allocating temporary memory
std::vector<nvbench::float64_t> m_probabilities;
nvbench::float64_t compute_entropy();

View File

@@ -29,7 +29,7 @@ entropy_criterion::entropy_criterion()
: stopping_criterion{"entropy"}
{
m_freq_tracker.reserve(m_entropy_tracker.capacity() * 2);
m_ps.reserve(m_entropy_tracker.capacity() * 2);
m_probabilities.reserve(m_entropy_tracker.capacity() * 2);
}
void entropy_criterion::initialize(const criterion_params &params)
@@ -59,15 +59,15 @@ nvbench::float64_t entropy_criterion::compute_entropy()
return 0.0;
}
m_ps.resize(n);
m_probabilities.resize(n);
for (std::size_t i = 0; i < n; i++)
{
m_ps[i] = static_cast<nvbench::float64_t>(m_freq_tracker[i].second) /
static_cast<nvbench::float64_t>(m_total_samples);
m_probabilities[i] = static_cast<nvbench::float64_t>(m_freq_tracker[i].second) /
static_cast<nvbench::float64_t>(m_total_samples);
}
nvbench::float64_t entropy{};
for (nvbench::float64_t p : m_ps)
for (nvbench::float64_t p : m_probabilities)
{
entropy -= p * std::log2(p);
}