Local check instead of suppressing warnings
@@ -3,7 +3,6 @@ import math
import numpy as np
from scipy.special import erf, erfc
import scipy.stats as stats
-import warnings
class Distribution():
@@ -150,18 +149,17 @@ class Lognormal(Distribution):
cutoffs = [0] + temp_cutoffs + [np.inf]
CDF_vals = np.array(CDF_vals)
- # Construct the discrete approximation by finding the average value within each segment.
- # This codeblock ignores warnings because it throws a "divide by zero encountered in log"
- # warning due to computing erf(infty) at the tail boundary. This is irrelevant and
- # apparently freaks new users out.
- with warnings.catch_warnings():
- warnings.simplefilter("ignore")
K = CDF_vals.size-1 # number of points in approximation
pmf = CDF_vals[1:(K+1)] - CDF_vals[0:K]
X = np.zeros(K)
for i in range(K):
zBot = cutoffs[i]
zTop = cutoffs[i+1]
+ # Manual check to avoid the RuntimeWarning generated by "divide by zero"
+ # with np.log(zBot).
+ if zBot == 0:
+ tempBot = np.inf
+ else:
tempBot = (self.mu+self.sigma**2-np.log(zBot))/(np.sqrt(2)*self.sigma)
tempTop = (self.mu+self.sigma**2-np.log(zTop))/(np.sqrt(2)*self.sigma)
if tempBot <= 4:
