25 template <
class... CounterTArgs>
27 const std::string & name,
28 const std::string & desc,
29 const size_t num_contexts,
30 CounterTArgs && ...args) :
34 static_cast<uint32_t
>(num_contexts),
36 std::forward<CounterTArgs>(args)...),
39 REGISTER_CONTEXT_COUNTER_AGGREGATE_FCN(
42 REGISTER_CONTEXT_COUNTER_AGGREGATE_FCN(
46 const CounterT & context(
const uint32_t idx)
const {
50 CounterT & context(
const uint32_t idx) {
54 void assignContextWeights(
const std::vector<double> & weights) {
55 if (!weights.empty()) {
56 if (weights.size() > 1 && weights.size() != this->numContexts()) {
57 throw SpartaException(
"Invalid weights passed to WeightedContextCounter. The ")
58 <<
"weights vector passed in had " << weights.size() <<
" values in it, "
59 <<
"but this context counter has " << this->
numContexts() <<
" contexts in it.";
63 if (weights_.size() == 1) {
64 const double weight = weights_[0];
65 weights_ = std::vector<double>(this->
numContexts(), weight);
69 double calculateWeightedAverage() {
71 return calculated_average_;
76 calculated_average_ = 0;
77 auto weight_iter = weights_.begin();
78 for (
const auto & internal_ctr : *
this) {
79 calculated_average_ += internal_ctr.get() * *weight_iter++;
86 maximum_ = std::numeric_limits<double>::min();
87 for (
const auto & internal_ctr : *
this) {
88 maximum_ = std::max(maximum_,
static_cast<double>(internal_ctr.get()));
92 std::vector<double> weights_;
93 double calculated_average_;
A container type that allows a modeler to build, store, and charge counts to a specific context.
uint32_t numContexts() const
Return the number of contexts in this ContextCounter.
const counter_type & context(const uint32_t idx) const
Return the internal counter at the given context.
This is an example context counter subclass used to show how users may supply their own "aggregated v...