Avoid log(0) if probability is too low
authorMagnus Lundborg <magnus.lundborg@scilifelab.se>
Tue, 25 Aug 2020 13:01:59 +0000 (13:01 +0000)
committerJoe Jordan <ejjordan12@gmail.com>
Tue, 25 Aug 2020 13:01:59 +0000 (13:01 +0000)
Change-Id: I96f5aa61f21303c4c382b8a0664cffd20e85bbd6

src/gromacs/awh/biasstate.cpp

index 24dec6dca849b0f8e883c1f10b4c717f8bda88fd..356cb1ac2bf79de88d42c46ed3157e77e480a1e3 100644 (file)
@@ -1446,8 +1446,8 @@ void BiasState::sampleCoordAndPmf(const std::vector<DimParams>& dimParams,
                     bias = calcConvolvedBias(dimParams, grid, coordValueAlongLambda);
                 }
 
-                const double probWeight   = lambdaMarginalDistribution[neighborLambda];
-                const double weightedBias = bias - std::log(probWeight);
+                const double probWeight = lambdaMarginalDistribution[neighborLambda];
+                const double weightedBias = bias - std::log(std::max(probWeight, GMX_DOUBLE_MIN)); // avoid log(0)
 
                 if (neighbor == gridPointIndex && grid.covers(coordState_.coordValue()))
                 {