简体   繁体   中英

SciPy stats lognormal distribution obtain pdf with given lognormal distribution mean and lognormal distribution geometric standard deviation

I am working with droplets distribution, for purpose of my work I would like to create droplet distribution plot. In this case I need lognorm.pdf for scipy . Unfortunately scipy build function lognorm.pdf has an equation like this:

lognorm.pdf(x, s) = 1 / (s*x*sqrt(2*pi)) * exp(-1/2*(log(x)/s)**2)

For my case I want to use a formula form Wikipedia :

pdf = 1 / (s*x*sqrt(2*pi)) * exp(-1/2*((log(x)-mu)/s)**2)

The best equation would be like this:

(np.exp(-(np.log10(x) - np.log10(mu))**2 / (2 * np.log10(s)**2)) / ( np.log10(s) * np.sqrt(2 * np.pi)))*N

I do have a code which follows the lest equation, but I just wonder if there is any way of doing this with scipy or any other python library?

The simplest way, if x is not too memory consuming:

tempX = x / np.exp(mu)
distr = lognorm.pdf(tempX, s)

or even define your own function:

def lognormMu(x, mu, s):
    tempX = x / np.exp(mu)
    return lognorm.pdf(tempX, s)

#EDIT

also, lognorm docs state explicitly that

The probability density above is defined in the “standardized” form. To shift and/or scale the distribution use the loc and scale parameters. Specifically, lognorm.pdf(x, s, loc, scale) is identically equivalent to lognorm.pdf(y, s) / scale with y = (x - loc) / scale .

So it seems that it should be called as

distr = lognorm.pdf(x, s, mu)

to obtain a desired effect.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM