Two coins refresher

Given a world that consist of bunch random events (2 coins for simplicity) we are interested in quantifying the probability of different combinations of the world state.

The state space

The combination of all possible outcomes is called the state space $\Omega$, in our example

Coin 1 Coin 2
H H
H T
T H
T T

An event is a subset of the state space, denoted as $A \subseteq \Omega$, the following are examples of events

  • E1: Exactly one head occurs or {HT, TH}
  • E2: Exactly one tail occurs or {HT, TH}

Proababilty

The probability measure is a function $P: \mathbb{R}\rightarrow[0,1]$ that satisfies 3 axioms

  • $P(A) >= 0$, $\forall A \subseteq \Omega$
  • $P(\Omega) = 0$
  • for disjoint $A1, A2$ $P(A1, A2) = P(A1) + P(A2)$

Our understanding of probability

  • Frequentist interpretation
    • The probability is the fraction of the event occurrence to number of trials
    • $P(X=x) = \lim_{N\rightarrow \infty}\frac{n_x}{N}.$
  • Bayesian interpretation
    • The probability represents our belief that some event will occur (examples later)

Some rules

if we have two events $A$ and $B$

  • $P(A, B)$ is called the Joint probability
  • $P(A)$ is the Marginal probability and can be computed by $\sum_{B} P(A, B)$
  • $P(A|B)$ is the Conditional probability and can be cumputed by $\frac{P(A, B)}{P(B)}$
  • $A$ and $B$ are independent if $P(A|B) = P(A)$
  • If A and B are independent then $P(A, B) = P(A)P(B)$

Problem

Given the three fair coins find the follwing

  • The state space
  • P(C1 = H)
  • P(C1 = H, C2 = T)
  • Check that C1 is H and C2 is H are independent

In [2]:
#Your code here

Probability is amazing - Computing integrals


In [47]:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

radius = 1
N = 10000

X = np.random.uniform(low=-radius, high=radius, size=N)  # Random numbers from -1 to 1
Y = np.random.uniform(low=-radius, high=radius, size=N)   

is_point_inside = np.sqrt(X**2 + Y**2) < radius

plt.scatter(X,Y, c=is_point_inside, s=5.0, edgecolors='none', cmap=plt.cm.Accent)  
plt.axis('equal')


Out[47]:
(-1.5, 1.5, -1.5, 1.5)
/home/condauser/anaconda3/lib/python3.4/site-packages/matplotlib/collections.py:590: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
  if self._edgecolors == str('face'):

In [46]:
p_inside = np.sum(is_point_inside) / N
circle_area = box_area * p_inside

print ("Area of the circle = ", circle_area)
print ("pi = ", circle_area/radius**2)


Area of the circle =  1.488
pi =  1.488

Your turn

Compute the area of the normal distribution between [-3, 3]


In [1]:
#Your code here