{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# SMIPP 21/22 - Exercise Sheet 1\n",
    "\n",
    "## Prof. Dr. K. Reygers, Dr. R. Stamen\n",
    "\n",
    "## Hand in by: Thursday, October 28th: 12:00\n",
    "### Submit the file(s) through the Übungsgruppenverwaltung\n",
    "\n",
    "\n",
    "### Names (up to two):\n",
    "### Points:      "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.1 Independence and the complementary event (10 points)\n",
    "Show that if $A$ and $B$ are statistically independent, i.e., $P(A \\cap B) = P(A)P(B)$, then also $A$ and $\\bar{B}$ (the complement of $B$) are statistically independent, i.e., $P(A\\cap \\bar{B}) = P(A)P(\\bar{B})$. Use the three Kolmogorov axioms that define probability.\n",
    "\n",
    "Hint: Write $A$ as $A = (A \\cap B)\\cup (A\\cap \\bar B)$."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.2 Identification of electrons and photons (10 point)\n",
    "\n",
    "A beam of particles consists of a fraction of $10^{−4}$ electrons and the rest photons. The\n",
    "particles pass through a double-layered detector which gives signals in either zero, one or both layers. The probabilities of these outcomes for electrons ($e$) and photons ($\\gamma$) are: \n",
    "$$\n",
    "\\begin{array}{ll}{P(0 | \\mathrm{e})=0.001} & {P(0 | \\gamma)=0.99899} \\\\ {P(1 | \\mathrm{e})=0.01} & {P(1 | \\gamma)=0.001} \\\\ {P(2 | \\mathrm{e})=0.989} & {P(2 | \\gamma)=10^{-5}}\\end{array}\n",
    "$$\n",
    "\n",
    "a) What is the probability for the particle to be a photon given a detected signal in one layer only?\n",
    "\n",
    "b) What is the probability for a particle to be an electron given a detected signal in both layers?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.3 Mean, mode, median and variance (10 points)\n",
    "\n",
    "Consider a function $f(x)$ of exponential shape given by:\n",
    "\n",
    "\\begin{equation}\n",
    "f(x) = e^{- x/a}\n",
    "\\end{equation}\n",
    "\n",
    "with the positive real paramater $a$ in the range $x \\in [0,\\infty]$.  The following calculations you can perform analytically by hand or you can use Mathematica, Wolfram-alpha, sympy, etc. For the plot in f) use Python please.\n",
    "\n",
    "a) Determine the normalisied pdf $f_N(x)$.\n",
    "\n",
    "b) Determine the Mode.\n",
    "\n",
    "c) Determine the Mean.\n",
    "\n",
    "d) Determnine the Median.\n",
    "\n",
    "e) Deternmine the Variance.\n",
    "\n",
    "f) Plot $f_N(x)$ in the range $[0,5]$ for $a = 1$, $a=2$ and $a=5$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.4 Bayesian priors (10 points)\n",
    "\n",
    "An unstable particle is created in a reaction at time $t_0 = 0$. The probability density distribution for the decay of the particle at time $t$ is given by $f(t; \\tau) = 1/\\tau \\exp(-t/\\tau)$ where $\\tau$ is the (unkown) mean lifetime. You observe that the particle decays at time $t_d$.\n",
    "\n",
    "a) Write down the posterior distribution for the mean lifetime $\\tau$ (i) assuming a flat prior for $\\tau$, (ii) using Jeffreys's prior $\\pi(\\tau) = 1 / \\tau$, and (iii) assuming a flat prior for the decay rate $\\lambda = 1 / \\tau$. Start with the numerator of Bayes's formula and then calculate the normalization for each case. Can all posterior distributions be normalized?\n",
    "\n",
    "b) What is the most likely value $\\hat \\tau$ for the mean lifetime in the cases  for (i), (ii), and (iii)? \n",
    "\n",
    "Hints: \n",
    "1. The math is not complicated, but it is perfectly fine to use a computer algebra system like Mathematica, Wolfram Alpha or sympy.\n",
    "2. In case (iii) one needs to calculate a probability distribution function (pdf) after a change of variables. Let $f_x(x)$ be a pdf and $y$ a new random variable given by $y = g(x)$ where $g$ is a monotonic function. The resulting pdf $f_y(y)$ is then given by \n",
    "$$f_y(y) = f_x(g^{-1}(y)) \\, |\\frac{dx}{dy}|$$ \n",
    "where $g^{-1}$ is the inverse function. This follows from $|f_y(y) \\, dy| = |f_x(x) \\, dx|$.  \n",
    "Show that if the prior as function of $\\lambda$ is flat (i.e. $\\pi(\\lambda) = const.$), the prior as function of $\\tau$ follows $\\pi(\\tau) \\propto  1/\\tau^2$."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "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.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
