manyspikes

Log-normal distribution

Initialising environment...

Now that you have seen how to build probability density functions, let's try to implement a new one.

The distribution we will be implementing in this exercise is called the log-normal distribution. It has the following PDF:

f(x,μ,σ)=1xσ2πexp((ln(x)μ)22σ2)\begin{equation} f(x, \mu, \sigma) = \frac{1}{x \sigma \sqrt{2 \pi}} \exp \left( - \frac{(\ln(x) - \mu)^2}{2 \sigma^2} \right) \end{equation}

Note that the log-normal distribution is only defined for positive numbers (since the logarithm is only defined for such numbers).

Instructions

Implement a function called lognormal that takes as input three values: one for xx, one for μ\mu and one for σ\sigma. The function must return the value of the PDF. Thus funtion should have the following definition:

def lognormal(x, mu, sigma): # Your implementation here

The input xx can be either a scalar or a numpy array.