.. title: Engineering Probability Class 5 Thu 2020-01-30
.. slug: class05
.. date: 2020-01-29
.. tags: class
.. link: 
.. description: 
.. type: text
.. has_math: true

.. sectnum::
.. contents:: Table of contents::
..

Probability in the real world - enrichment
------------------------------------------

See examples in the random section below.


Homework 3
----------

is online `here <../posts/homework03.html>`_ , due in a week.


Chapter 2 ctd
-------------
 
#. Example 2.28, p51.    Chip quality control.
   
   a. Each chip is either *good* or *bad*.
   #. P[good]=(1-p), P[bad]=p.
   #. If the chip is good: P[still alive at t] = :math:`e^{-at}`
   #. If the chip is bad: P[still alive at t] = :math:`e^{-1000at}`
   #. What's the probability that a random chip is still alive at t?

#. 2.4.1, p52. Bayes' rule.  This lets you invert the conditional probabilities.
   
   a. :math:`B_j` partition S.   That means that
      
      i. If :math:`i\ne j` then :math:`B_i\cap B_j=\emptyset` and
      #. :math:`\bigcup_i B_i = S`
	 
   #. :math:`P[B_j|A] = \frac{B_j\cap A}{P[A]}` :math:`= \frac{P[A|B_j] P[B_j]}{\sum_k P[A|B_k] P[B_k]}`
   #. application:
      
      i. We have a priori probs :math:`P[B_j]`
      #. Event A occurs.  Knowing that A has happened gives us info that
         changes the probs.
      #. Compute a posteriori probs :math:`P[B_j|A]`

#. In the above diagram, what's the probability that an undergrad is an
   engineer?

#. Example 2.29 comm channel: If receiver sees 1, which input was more
   probable?  (You hope the answer is 1.)   

#. Example 2.30 chip quality control: For example 2.28, how long do we have
   to burn in chips so that the survivors have a 99% probability of being
   good?  p=0.1, a=1/20000.

#. Example:
   False positives in a medical test

   a. T = test for disease was positive; T' = .. negative
   #. D = you have disease; D' = .. don't ..
   #. P[T|D] = .99,   P[T' | D'] = .95, P[D] = 0.001
   #. P[D' | T] (false positive) = 0.98 !!!



Bayes theorem ctd
--------------------------

#. `Wikipedia on Bayes theorem <https://en.wikipedia.org/wiki/Bayes%27_theorem>`_.

   We'll do the examples.
   
#. We'll do these examples from Leon-Garcia in class.

#. Example 2.28, page 51.   I'll use e=0.1.

   Variant:  Assume that P[A0]=.9.  Redo the example.
   
#. Example 2.30, page 53, chip quality control: For example 2.28, how long do we have
   to burn in chips so that the survivors have a 99% probability of being
   good?  p=0.1, a=1/20000.   



#. Event A is that a random person has a lycanthopy gene.  Assume P(A) = .01.

   Genes-R-Us has a DNA test for this.  B is the event of a positive test.  There are
   false positives and false negatives each w.p. (with probability) 0.1.  That is,
   P(B|A') = P(B' | A) = 0.1

   #.  What's P(A')?

   #. What's P(A and B)?

   #. What's P(A' and B)?

   #. What's P(B)?

   #. You test positive.   What's the probability you're really positive, P(A|B)?


Chapter 2 ctd: Independent events
---------------------------------

#. 2.5 Independent events
   
   a. :math:`P[A\cap B] = P[A] P[B]`
   #. P[A|B] = P[A],  P[B|A] = P[B]

#. A,B independent means that knowing A doesn't help you with B.

#. Mutually exclusive events w.p.>0 must be dependent.

#. Example 2.33, page 56.  

   .. image:: /images/fig214.jpg

#. More that 2 events:
   
   a. N events are independent iff the occurrence of no combo of the events
      affects another event.
   #. Each pair is independent.
   #. Also need :math:`P[A\cap B\cap C] = P[A] P[B] P[C]`
   #. *This is not intuitive*  A, B, and C might be pairwise independent,
      but, as a group of 3, are dependent.
   #. See example 2.32, page 55.  A: x>1/2.  B: y>1/2.  C: x>y

#. Common application: independence of experiments in a sequence.

#. Example 2.34: coin tosses are assumed to be independent of each other.

   P[HHT] = P[1st coin is H] P[2nd is H] P[3rd is T].

#. Example 2.35, page 58. System reliability
   
   a. Controller and 3 peripherals.
   #. System is up iff controller and at least 2 peripherals are up.
   #. Add a 2nd controller.

#. 2.6 p59 Sequential experiments:  *maybe* independent

#. 2.6.1 Sequences of independent experiments
   
   a. Example 2.36 

#. 2.6.2 Binomial probability
   
   a. *Bernoulli trial* flip a possibly unfair coin once. *p* is
      probability of head.
   #. (Bernoulli did stats, econ, physics, ... in 18th century.)
   
#. Example 2.37
   
   a. P[TTH] = :math:`(1-p)^2 p`
   #. P[1 head] =  :math:`3 (1-p)^2 p`

#. Probability of exactly k successes = :math:`p_n(k) = {n \choose k} p^k (1-p)^{n-k}`

#. :math:`\sum_{k=0}^n p_n(k) = 1`

#. Example 2.38

#. Can avoid computing n! by computing :math:`p_n(k)` recursively, or by using
   approximation.  Also, in C++, using double instead of float helps.
   (Almost always you should use double instead of float.  It's the same
   speed.)

#. Example 2.39 

#. Example 2.40 Error correction coding

   

Xkcd comic
----------

`Linear Regression <https://xkcd.com/1725/>`_
