64 const auto assignments = DiscreteValues::CartesianProduct(rdkeys);
67 std::vector<double> errors;
68 for (
const auto& assignment : assignments) {
69 errors.push_back(
error(assignment));
75 std::vector<double>
expNormalize(
const std::vector<double>& logProbs) {
76 double maxLogProb = -std::numeric_limits<double>::infinity();
77 for (
size_t i = 0;
i < logProbs.size();
i++) {
78 double logProb = logProbs[
i];
79 if ((logProb != std::numeric_limits<double>::infinity()) &&
80 logProb > maxLogProb) {
88 for (
size_t i = 0;
i < logProbs.size();
i++) {
89 double probPrime =
exp(logProbs[
i] - maxLogProb);
92 double logTotal =
log(total);
96 double checkNormalization = 0.0;
97 std::vector<double> probs;
98 for (
size_t i = 0;
i < logProbs.size();
i++) {
99 double prob =
exp(logProbs[
i] - maxLogProb - logTotal);
100 probs.push_back(prob);
101 checkNormalization += prob;
109 std::string(
"expNormalize failed to normalize probabilities. ") +
110 std::string(
"Expected normalization constant = 1.0. Got value: ") +
111 std::to_string(checkNormalization) +
113 "\n This could have resulted from numerical overflow/underflow.");
114 throw std::logic_error(errMsg);