Introduce approxNormal and approxLognormalGaussHermite and two helper functions for converting between location and scale in normal<->lognormal.
@@ -12,6 +12,7 @@ from builtins import object
import functools
import warnings
import numpy as np # Python's numeric library, abbreviated "np"
+import math
try:
import matplotlib.pyplot as plt # Python's plotting library
except ImportError:
@@ -551,6 +552,27 @@ def approxMeanOneLognormal(N, sigma=1.0, **kwargs):
pmf,X = approxLognormal(N=N, mu=mu_adj, sigma=sigma, **kwargs)
return [pmf,X]
+def approxNormal(N, mu=0.0, sigma=1.0):
+ x, w = np.polynomial.hermite.hermgauss(N)
+ # normalize w
+ pmf = w*np.pi**-0.5
+ # correct x
+ X = 2.0**0.5*sigma*x + mu
+ return [pmf, X]
+
+def approxLogNormalGaussHermite(N, mu=0.0, sigma=1.0):
+ pmf, X = approxNormal(N)
+ return pmf, np.exp(X)
+
+def calcNormalStyleParsFromLognormal(avgLognormal, varLognormal):
+ avgNormal = math.log(avgLognormal/math.sqrt(1+varLognormal/avgLognormal**2))
+ varNormal = math.sqrt(math.log(1+varLognormal/avgLognormal**2))
+ return avgNormal, varNormal
+
+def calcLognormalStyleParsFromNormal(mu, sigma):
+
+
+
def approxBeta(N,a=1.0,b=1.0):
'''
Calculate a discrete approximation to the beta distribution. May be quite
