Guest User

Untitled

a guest
Mar 22nd, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. plt.style.use("seaborn")
  4. import seaborn as sns
  5. from scipy.stats import t
  6.  
  7. """Generate t distributed values"""
  8. def f(x, mu):
  9. n = len(x)
  10. return np.sqrt(n) * (x.mean()-mu)/ x.std()
  11.  
  12. mu = 0
  13. df = 3
  14.  
  15.  
  16. for i in range(5):
  17. plt.subplot(2,5,i+1)
  18. t_vals = [f(np.random.normal(loc = mu, size = df + 1), mu) for i in range(10000)]
  19. sns.distplot(t_vals, kde = False, norm_hist = True)
  20. x = np.linspace(-5, 5, 100)
  21. plt.plot(x, t.pdf(x, df))
  22. plt.xlim([-5, 5])
  23. plt.xlabel(r"$x$")
  24. if i == 0:
  25. plt.ylabel(r"$p(x)$")
  26. if i == 2:
  27. plt.title("Manually generated")
  28.  
  29. for i in range(5):
  30. plt.subplot(2,5,i+6)
  31. t_vals = np.random.standard_t(df, size = 10000)
  32. sns.distplot(t_vals, kde = False, norm_hist = True)
  33. x = np.linspace(-5, 5, 100)
  34. plt.plot(x, t.pdf(x, df))
  35. plt.xlim([-5, 5])
  36. plt.xlabel(r"$x$")
  37. if i == 0:
  38. plt.ylabel(r"$p(x)$")
  39. if i == 2:
  40. plt.title("Generated using python")
  41.  
  42. plt.tight_layout()
  43. plt.savefig("t_dists.pdf", bboxinches = "tight")
Add Comment
Please, Sign In to add comment