Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,43 +13,39 @@ alpha = st.slider('Alpha', 0.5, 5.0, 0.5)
|
|
| 13 |
beta = st.slider('Beta', 0.5, 5.0, 0.5)
|
| 14 |
|
| 15 |
theta = np.linspace(0.01,0.99,100)
|
| 16 |
-
rc('font', size=20)
|
| 17 |
# rc('text', usetex=True)
|
| 18 |
-
fig, ax = plt.subplots(
|
| 19 |
axs = ax.twinx()
|
| 20 |
|
| 21 |
def Bernoulli(theta, N, h):
|
| 22 |
return (theta ** h) * ((1-theta) ** (N-h))
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
axs.set_ylabel('Prior/Posterior', color='r', rotation=270, labelpad=30)
|
| 47 |
-
return fig
|
| 48 |
-
|
| 49 |
-
|
| 50 |
|
| 51 |
with st_col:
|
| 52 |
-
st.pyplot(
|
| 53 |
|
| 54 |
hide_streamlit_style = """
|
| 55 |
<style>
|
|
|
|
| 13 |
beta = st.slider('Beta', 0.5, 5.0, 0.5)
|
| 14 |
|
| 15 |
theta = np.linspace(0.01,0.99,100)
|
| 16 |
+
#rc('font', size=20)
|
| 17 |
# rc('text', usetex=True)
|
| 18 |
+
fig, ax = plt.subplots()
|
| 19 |
axs = ax.twinx()
|
| 20 |
|
| 21 |
def Bernoulli(theta, N, h):
|
| 22 |
return (theta ** h) * ((1-theta) ** (N-h))
|
| 23 |
|
| 24 |
+
Likelihood = [Bernoulli(t,N,h) for t in theta]
|
| 25 |
+
|
| 26 |
+
ax.cla();axs.cla()
|
| 27 |
+
ax.plot(theta, Likelihood, label='Likelihood',color='b');
|
| 28 |
+
axs.plot(theta, scipy.stats.beta.pdf(theta, alpha,beta), label='Prior',color='k');
|
| 29 |
+
ax.set_xlabel('p(head)');
|
| 30 |
+
ax.vlines(h/N, *ax.get_ylim(), linestyle='--',label='MLE', color='b')
|
| 31 |
+
axs.text(h/N,2,'MLE', color='b')
|
| 32 |
+
|
| 33 |
+
axs.plot(theta, [scipy.stats.beta.pdf(t, h+alpha, N-h+beta) for t in theta], color='r')
|
| 34 |
+
ax.text(theta[0], Likelihood[0],'Likelihood', color='b')
|
| 35 |
+
axs.text(theta[-5], scipy.stats.beta.pdf(theta, alpha,beta)[-5],'Prior')
|
| 36 |
+
axs.text(alpha/(alpha+beta)-0.1,1,'Prior mean')
|
| 37 |
+
axs.text(theta[0],scipy.stats.beta.pdf(theta[0], h+alpha, N-h+beta),'Posterior',color='r')
|
| 38 |
+
axs.text((h+alpha)/(N+alpha+beta)-0.1,3,'Post. Mean',color='r')
|
| 39 |
+
ax.vlines(alpha/(alpha+beta), *ax.get_ylim(), linestyle='--',label='Prior mean',color='k')
|
| 40 |
+
ax.vlines((h+alpha)/(N+alpha+beta), *ax.get_ylim(), linestyle='--',label='Post. Mean',color='r')
|
| 41 |
+
# ax.set_title(f"n_samples={int(N)}, n_heads={int(h)}");
|
| 42 |
+
ax.tick_params(axis='y', colors='b')
|
| 43 |
+
axs.tick_params(axis='y', colors='r')
|
| 44 |
+
ax.set_ylabel('Likelihood',color='b')
|
| 45 |
+
axs.set_ylabel('Prior/Posterior', color='r', rotation=270, labelpad=30)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
with st_col:
|
| 48 |
+
st.pyplot(fig)
|
| 49 |
|
| 50 |
hide_streamlit_style = """
|
| 51 |
<style>
|