アットウィキロゴ

pyy

import numpy as np
import numpy.random as rd
import matplotlib.mlab as mlab
import scipy.stats as st
import matplotlib.pyplot as plt
 
n = 10000
sample_size = 10000
 
def sample_to_mean_var(sample):
    mean = np.mean(sample)
    var  = np.var(sample)
    return [mean, var]
 
def plot_mean_var(stats, dist_name=""):
    mu = stats[:,0]
    var = stats[:,1]
    bins = 40
 
    plt.figure(figsize=(7,5))
    plt.hist(mu, bins=bins, normed=True, color="plum")
    plt.title("mu from %s distribution"%(dist_name))
    plt.show()
 
    plt.figure(figsize=(7,5))
    plt.hist(var, bins=bins, color="lightblue", normed=True)
    plt.title("var from %s distribution"%(dist_name))
    plt.show()
 
def plot_dist(data, bins, title =""):
    plt.figure(figsize=(7,5))
    plt.title(title)
    plt.hist(data, bins, color="lightgreen", normed=True)
    plt.show()
 
lam = 0.1  
x = rd.exponential(2./lam, size=sample_size)
plot_dist(x, 100, "exponential dist")  
最終更新:2018年01月11日 00:11