42 std::vector<double>
expNormalize(
const std::vector<double>& logProbs) {
43 double maxLogProb = -std::numeric_limits<double>::infinity();
44 for (
size_t i = 0;
i < logProbs.size();
i++) {
45 double logProb = logProbs[
i];
46 if ((logProb != std::numeric_limits<double>::infinity()) &&
47 logProb > maxLogProb) {
55 for (
size_t i = 0;
i < logProbs.size();
i++) {
56 double probPrime =
exp(logProbs[
i] - maxLogProb);
59 double logTotal =
log(total);
63 double checkNormalization = 0.0;
64 std::vector<double> probs;
65 for (
size_t i = 0;
i < logProbs.size();
i++) {
66 double prob =
exp(logProbs[
i] - maxLogProb - logTotal);
67 probs.push_back(prob);
68 checkNormalization += prob;
76 std::string(
"expNormalize failed to normalize probabilities. ") +
77 std::string(
"Expected normalization constant = 1.0. Got value: ") +
78 std::to_string(checkNormalization) +
80 "\n This could have resulted from numerical overflow/underflow.");
81 throw std::logic_error(errMsg);
EIGEN_DEVICE_FUNC const LogReturnType log() const
bool fpEqual(double a, double b, double tol, bool check_relative_also)
EIGEN_DEVICE_FUNC const ExpReturnType exp() const
Array< double, 1, 3 > e(1./3., 0.5, 2.)
typedef and functions to augment Eigen's VectorXd
std::vector< double > expNormalize(const std::vector< double > &logProbs)
Normalize a set of log probabilities.
const DiscreteValues & discrete() const
Return the discrete values.