59 const auto assignments = DiscreteValues::CartesianProduct(rdkeys);
62 std::vector<double> errors;
63 for (
const auto& assignment : assignments) {
64 errors.push_back(
error(assignment));
70 std::vector<double>
expNormalize(
const std::vector<double>& logProbs) {
71 double maxLogProb = -std::numeric_limits<double>::infinity();
72 for (
size_t i = 0;
i < logProbs.size();
i++) {
73 double logProb = logProbs[
i];
74 if ((logProb != std::numeric_limits<double>::infinity()) &&
75 logProb > maxLogProb) {
83 for (
size_t i = 0;
i < logProbs.size();
i++) {
84 double probPrime =
exp(logProbs[
i] - maxLogProb);
87 double logTotal =
log(total);
91 double checkNormalization = 0.0;
92 std::vector<double> probs;
93 for (
size_t i = 0;
i < logProbs.size();
i++) {
94 double prob =
exp(logProbs[
i] - maxLogProb - logTotal);
95 probs.push_back(prob);
96 checkNormalization += prob;
104 std::string(
"expNormalize failed to normalize probabilities. ") +
105 std::string(
"Expected normalization constant = 1.0. Got value: ") +
106 std::to_string(checkNormalization) +
108 "\n This could have resulted from numerical overflow/underflow.");
109 throw std::logic_error(errMsg);