You have a mode and a standard deviation of the logarithmic distribution. To use the rvs()scipy method lognorm, you need to parameterize the distribution in terms of the shape parameter s, which is the standard deviation of the sigmabasic normal distribution and scalewhich exp(mu), where muis the average of the underlying distribution.
You indicated that for this reparametrization a quartic polynomial solution is required. For this we can use a class numpy.poly1d. Instances of this class have an attribute roots.
, exp(sigma**2) -
x**4 - x**3 - (stddev/mode)**2 = 0
stddev mode - - , scale (.. exp(mu))
scale = mode*x
, :
def lognorm_params(mode, stddev):
"""
Given the mode and std. dev. of the log-normal distribution, this function
returns the shape and scale parameters for scipy parameterization of the
distribution.
"""
p = np.poly1d([1, -1, 0, 0, -(stddev/mode)**2])
r = p.roots
sol = r[(r.imag == 0) & (r.real > 0)].real
shape = np.sqrt(np.log(sol))
scale = mode * sol
return shape, scale
,
In [155]: mode = 123
In [156]: stddev = 99
In [157]: sigma, scale = lognorm_params(mode, stddev)
:
In [158]: from scipy.stats import lognorm
In [159]: sample = lognorm.rvs(sigma, 0, scale, size=1000000)
:
In [160]: np.std(sample)
Out[160]: 99.12048952171304
- matplotlib , , :
In [176]: tmp = plt.hist(sample, normed=True, bins=1000, alpha=0.6, color='c', ec='c')
In [177]: plt.xlim(0, 600)
Out[177]: (0, 600)
In [178]: plt.axvline(mode)
Out[178]: <matplotlib.lines.Line2D at 0x12c5a12e8>
:

numpy.random.lognormal() scipy.stats.lognorm.rvs(), :
In [200]: sigma, scale = lognorm_params(mode, stddev)
In [201]: mu = np.log(scale)
In [202]: sample = np.random.lognormal(mu, sigma, size=1000000)
In [203]: np.std(sample)
Out[203]: 99.078297384090902
, poly1d roots, . , scipy x. , :
max(sqrt(stddev/mode), 1) <= x <= sqrt(stddev/mode) + 1