prevent excessive MLT/ERPT error messages due to roundoff errors

metadata
Wenzel Jakob 2012-11-15 00:52:14 -05:00
parent 0a441e78a8
commit fb7fe6a8e1
3 changed files with 16 additions and 9 deletions

View File

@ -234,15 +234,17 @@ public:
} }
#endif #endif
if (Qxy == 0) { // be tolerant of this (can occasionally happen due to floating point inaccuracies)
a = 0;
} else if (Qxy < 0 || Qyx < 0 || std::isnan(Qxy) || std::isnan(Qyx)) {
#if defined(MTS_BD_DEBUG) #if defined(MTS_BD_DEBUG)
if (Qxy <= 0 || Qyx < 0 || std::isnan(Qxy) || std::isnan(Qyx)) {
Log(EDebug, "Source path: %s", current->toString().c_str()); Log(EDebug, "Source path: %s", current->toString().c_str());
Log(EDebug, "Proposal path: %s", proposed->toString().c_str()); Log(EDebug, "Proposal path: %s", proposed->toString().c_str());
Log(EWarn, "Internal error while computing acceptance probabilities: " Log(EWarn, "Internal error while computing acceptance probabilities: "
"Qxy=%f, Qyx=%f, muRec=%s", Qxy, Qyx, muRec.toString().c_str()); "Qxy=%f, Qyx=%f, muRec=%s", Qxy, Qyx, muRec.toString().c_str());
#endif
a = 0; a = 0;
} }
#endif
accumulatedWeight += 1-a; accumulatedWeight += 1-a;

View File

@ -235,7 +235,9 @@ public:
} }
#endif #endif
if (Qxy <= 0 || Qyx < 0 || std::isnan(Qxy) || std::isnan(Qyx)) { if (Qxy == 0) { // be tolerant of this (can occasionally happen due to floating point inaccuracies)
a = 0;
} else if (Qxy < 0 || Qyx < 0 || std::isnan(Qxy) || std::isnan(Qyx)) {
#if defined(MTS_BD_DEBUG) #if defined(MTS_BD_DEBUG)
Log(EDebug, "Source path: %s", current->toString().c_str()); Log(EDebug, "Source path: %s", current->toString().c_str());
Log(EDebug, "Proposal path: %s", proposed->toString().c_str()); Log(EDebug, "Proposal path: %s", proposed->toString().c_str());

View File

@ -272,7 +272,6 @@ bool ManifoldPerturbation::sampleMutation(
for (int i=l+1; i<m; ++i) { for (int i=l+1; i<m; ++i) {
proposal.append(m_pool.allocVertex()); proposal.append(m_pool.allocVertex());
proposal.append(m_pool.allocEdge()); proposal.append(m_pool.allocEdge());
memset(proposal.vertex(proposal.vertexCount()-1), 0, sizeof(PathVertex)); /// XXX
} }
proposal.append(source, m, k+1); proposal.append(source, m, k+1);
@ -665,6 +664,10 @@ Float ManifoldPerturbation::Q(const Path &source, const Path &proposal,
if (prob == 0) if (prob == 0)
return 0.0f; return 0.0f;
weight /= prob; weight /= prob;
/* Catch very low probabilities which round to +inf in the above division operation */
if (!std::isfinite(weight.average()))
return 0.0f;
} else { } else {
Frame frame(source.vertex(a+step)->getGeometricNormal()); Frame frame(source.vertex(a+step)->getGeometricNormal());