0

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?

Fihu
  • 3
  • 3
  • You have to calculate appropriate parameters for the `scipy.lognorm` class from the mean and standard deviation. See answer [here](https://stackoverflow.com/a/73567355/10020283). – mcsoini Sep 01 '22 at 09:53

1 Answers1

1

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.

Suthiro
  • 1,210
  • 1
  • 7
  • 18