Skip to content

Instantly share code, notes, and snippets.

@sergeyf
Created July 9, 2013 23:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sergeyf/5962317 to your computer and use it in GitHub Desktop.
Save sergeyf/5962317 to your computer and use it in GitHub Desktop.
import numpy as np
import matplotlib.pyplot
mu, sigma = 3., 1. # mean and standard deviation
s = np.random.lognormal(mu, sigma, 10000)
log_s = np.log(s)
subplot(211)
count,bins,_ = hist(s, 100, normed=True, align='mid')
x = np.linspace(min(bins), max(bins), 10000)
pdf = (np.exp(-(np.log(x) - mu)**2 / (2 * sigma**2)) / (x * sigma * np.sqrt(2 * np.pi)))
plot(x, pdf, linewidth=2, color='r')
axis('tight')
ylabel('relative frequency')
title('Log-normal distribution & log-normal samples histogram')
subplot(212)
count_log,bins_log,_ = hist(log_s, 100, normed=True, align='mid')
x_log = np.linspace(min(bins_log), max(bins_log), 10000)
pdf_log = (np.exp(-(x_log - mu)**2 / (2 * sigma**2)) / (sigma * np.sqrt(2 * np.pi)))
plot(x_log, pdf_log, linewidth=2, color='r')
axis('tight')
ylabel('relative frequency')
title('Normal distribution & log of log-normal samples histogram')
show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment