From 742400485dcc3b9f3bea21bd861d98a9b9990fe1 Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Sun, 28 Jun 2015 18:53:32 +0200 Subject: [PATCH] vMF sampling simplification suggested by Stephen Hill --- src/libcore/vmf.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/libcore/vmf.cpp b/src/libcore/vmf.cpp index 8626fdff..aae1fc47 100644 --- a/src/libcore/vmf.cpp +++ b/src/libcore/vmf.cpp @@ -45,13 +45,8 @@ Vector VonMisesFisherDistr::sample(const Point2 &sample) const { sample.x * std::sinh(m_kappa)) / m_kappa; #else /* Numerically stable version */ - Float cosTheta; - if (sample.x > 0) { - cosTheta = 1 + (math::fastlog(sample.x) + math::fastlog( - 1 - math::fastexp(-2*m_kappa) * ((sample.x-1) / sample.x))) / m_kappa; - } else { - cosTheta = 1 + math::fastexp(-2*m_kappa) / m_kappa; - } + Float cosTheta = 1 + (math::fastlog(sample.x + + math::fastexp(-2 * m_kappa) * (1 - sample.x))) / m_kappa; #endif Float sinTheta = math::safe_sqrt(1-cosTheta*cosTheta),