%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import poisson
def plot(n=1000,normalize=False):
"""Plot variance vs mean"""
means = np.empty(n)
variances = np.empty(n)
for i in range(n):
x = poisson.rvs(i+1,size=100)
if normalize:
x_max = x.max()
x_min = x.min()
x = 255*(x-x_min)/(x_max-x_min)
means[i] = x.mean()
variances[i] = x.var()
plt.scatter(means,variances)
plot(normalize=False)
plot(normalize=True)
def plot2(n=100,normalize=False):
"""Plot variance vs mean"""
means = np.empty(n)
cvs = np.empty(n)
for i in range(n):
x = poisson.rvs(i+1,size=100)
if normalize:
x_max = x.max()
x_min = x.min()
x = 255*(x-x_min)/(x_max-x_min)
means[i] = x.mean()
cvs[i] = x.std()/x.mean()
plt.scatter(means,cvs)
plot2(normalize=False)
plot2(normalize=True)
def plot3(n=100,normalize=False):
"""Plot variance vs mean"""
means = np.empty(n)
stds = np.empty(n)
for i in range(n):
x = poisson.rvs(i+1,size=100)
if normalize:
x_max = x.max()
x_min = x.min()
x = 255*(x-x_min)/(x_max-x_min)
means[i] = x.mean()
stds[i] = x.std()
plt.scatter(means,stds)
plot3(normalize=False)
plot3(normalize=True)