<jupyter_start><jupyter_text>Bayesovský odhad střední hodnoty normálního rozdělení se známým rozptylem<jupyter_code>import numpy as np
from matplotlib import pyplot as plt
from scipy.stats import norm
def posterior(mpr, s2pr, s2T, x):
    """
    returns posterior parametes (mean, variance)
    mpr: prior mean parameter
    s2pr: prior variance parameter
    s2T: true variance of data
    x: data
    """
    t = len(x) # number of data
    s2po = (1./s2pr+t/s2T)**(-1)  # posterior variance
    mpo = (mpr/s2pr+np.sum(x)/s2T)*s2po  # posterior mean
    return mpo, s2po

mTrue = 5     # true mean
s2True = 10   # true variance 
N = 5    # number of data
np.random.seed(220214)
data = np.random.normal(mTrue, s2True, size=N) # data

# parametry normalniho apriorniho rozdeleni
mPr  = -5
s2Pr = 50  
mPo, s2Po = posterior(mPr, s2Pr, s2True, data)

xs = np.linspace(-30, 30, 200)
plt.figure()
plt.plot(xs, norm.pdf(xs, loc=mPr, scale=s2Pr**0.5), 'b')
plt.plot(xs, norm.pdf(xs, loc=mPo, scale=s2Po**0.5), 'r')
mPo
s2Po
norm.pdf?<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1275992438563327, 'fraction_numerical': 0.043478260869565216, 'mean_word_length': 3.8136363636363635, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '282876', 'license': 'MIT', 'n_tokens_mistral': 459, 'n_tokens_neox': 444, 'n_words': 114, 'path': 'normal_mu.ipynb', 'repo_name': 'ea542/MN', 'size': '1058'}