Fetch the repository succeeded.
This action will force synchronization from Higkoo/Book5_Essentials-of-Probability-and-Statistics, which will overwrite any changes that you have made since you forked the repository, and can not be recovered!!!
Synchronous operation will process in the background and will refresh the page when finishing processing. Please be patient.
###############
# Authored by Weisheng Jiang
# Book 5 | From Basic Arithmetic to Machine Learning
# Published and copyrighted by Tsinghua University Press
# Beijing, China, 2022
###############
import streamlit as st
from scipy.stats import beta
import matplotlib.pyplot as plt
import numpy as np
x_array = np.linspace(0,1,200)
with st.sidebar:
st.write('Beta distribution PDF')
st.latex(r'''
{\displaystyle {\begin{aligned}f(x;\alpha ,\beta )&=
\mathrm {constant} \cdot x^{\alpha -1}(1-x)^{\beta -1}\\
&=
{\frac {x^{\alpha -1}(1-x)^{\beta -1}}
{\displaystyle \int _{0}^{1}u^{\alpha -1}
(1-u)^{\beta -1}\,du}}\\
&=
{\frac {\Gamma (\alpha +\beta )}
{\Gamma (\alpha )\Gamma (\beta )}}\,x^{\alpha -1}(1-x)^{\beta -1}\\
&=
{\frac {1}{\mathrm {B} (\alpha ,\beta )}}
x^{\alpha -1}(1-x)^{\beta -1}\end{aligned}}}
''')
alpha_input = st.slider('alpha', min_value=0.0, max_value=10.0, value=2.0, step=0.1)
beta_input = st.slider('beta', min_value=0.0, max_value=10.0, value=2.0, step=0.1)
mean_loc = alpha_input/(alpha_input + beta_input)
pdf_array = beta.pdf(x_array, alpha_input, beta_input)
fig, ax = plt.subplots(figsize=(8, 8))
title_idx = '\u03B1 = ' + str(alpha_input) + '; \u03B2 = ' + str(beta_input)
ax.plot(x_array, pdf_array,
'b', lw=1)
ax.axvline (x = mean_loc, c = 'r', ls = '--')
ax.set_title(title_idx)
ax.set_xlim(0,1)
ax.set_ylim(0,4)
ax.set_xticks([0,0.5,1])
ax.set_yticks([0,2,4])
ax.spines.right.set_visible(False)
ax.spines.top.set_visible(False)
ax.yaxis.set_ticks_position('left')
ax.xaxis.set_ticks_position('bottom')
ax.tick_params(axis="x", direction='in')
ax.tick_params(axis="y", direction='in')
st.pyplot(fig)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。