Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added a useful formula page
  • Loading branch information
jet08013 committed Apr 27, 2018
1 parent 104f3ce commit aa114e2
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions Useful Formulae.ipynb
@@ -0,0 +1,61 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Conjugate Normal Distributions (known variance)\n",
"\n",
"We are trying to learn about the unknown mean of a normal distribution with known variance. \n",
"We choose a prior distribution is normal with mean $\\mu_{0}$ and variance $\\tau_{0}^2$. \n",
"We draw $n$ values $y_1,\\ldots, y_n$ from the distribution with known variance $\\sigma^2$. The posterior distribution\n",
"$p(\\mu|y_1,\\ldots,y_n)=p(y_1,\\ldots,y_n|\\mu)p(\\mu)$ is again normal. Let \n",
"$$\n",
"\\overline{y}=\\frac{1}{n}\\sum_{i=1}^{n} y_i\n",
"$$\n",
"be the sample mean. \n",
"\n",
"The posterior variance\n",
"is\n",
"$$\\frac{1}{\\tau_1^2}=\\frac{1}{\\tau_0^2}+\\frac{n}{\\sigma^2}$$\n",
"and the posterior mean is\n",
"$$\n",
"\\mu_1=\\frac{\\frac{\\mu_0}{\\tau_0^2}+\\frac{n\\overline{y}}{\\sigma^2}}{\\frac{1}{\\tau_{1}^2}}\n",
"$$\n"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"def posterior(prior_mean,prior_variance,sample_mean,pop_variance,n):\n",
" post_var=1/((1/prior_variance) + n/pop_variance)\n",
" post_mean=(prior_mean/prior_variance+sample_mean*n/pop_variance)/(1/post_var)\n",
" return post_mean, post_var"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit aa114e2

Please sign in to comment.