Created
May 19, 2021 09:43
-
-
Save 18182324/28fdb93d24834896d7afd630001dc478 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
py1_post = np.sum((res["theta"])*res["post"]) | |
py0_post = 1.0 - py1_post | |
py0_post, py1_post | |
py1_prior = np.sum((res["theta"])*res["prior"]) | |
py0_prior = 1 - py1_prior | |
py0_prior, py1_prior | |
#Plot posterior and prior | |
plt.figure(figsize=(16,12)) | |
plt.subplot(2,2,1) | |
plt.stem(res["theta"],res["prior"]) | |
plt.xlabel("theta") | |
plt.ylabel("probability") | |
plt.ylim([0,0.5]) | |
plt.title("prior distribution for theta") | |
plt.subplot(2,2,2) | |
plt.stem(res["theta"],res["post"]) | |
plt.ylim([0,0.5]) | |
plt.xlabel("theta") | |
plt.ylabel("probability") | |
plt.title("posterior distribution for theta") | |
plt.savefig("test.pdf") | |
plt.subplot(2,2,3) | |
plt.stem([0,1],[py0_prior,py1_prior]) | |
plt.xlabel("Y") | |
plt.ylabel("P(y)") | |
plt.ylim([0,1]) | |
plt.title("prior predictive distribution") | |
plt.subplot(2,2,4) | |
plt.stem([0,1],[py0_post,py1_post]) | |
plt.ylim([0,1]) | |
plt.xlabel("Y") | |
plt.ylabel("P(y)") | |
plt.title("posterior predictive distribution") | |
#plt.show() | |
plt.savefig("ch07_b2a.pdf") | |
# from google.colab import files | |
# files.download('ch07_b2a') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment