1. Probability
a. Show that if two variables x and y are independent, then their covariance is zero.
     For two random variables x and y, the co-variance is defined by \(cov\left(x,y\right)=E_{x,y}\left[xy\right]-E_{ }\left[x\right]E_{ }\left[y\right]\)   ---eq 1         (Bishop page 20 eq 1.41)
Also, if variables x and y are independent, we are aware that \(E\left(x,y\right)=E\left(x\right).E\left(y\right)\)    ---eq2
Substituting the value of E[xy] from  eq2 in eq 1 we get  \(cov\left(x,y\right)=E_{ }\left[x\right]E_{ }\left[y\right]-E_{ }\left[x\right]E_{ }\left[y\right]=0\)
Thus, we can conclude that if two variables are independent then their co-variance is zero.
    
b.
i. Calculate the probability of test being positive given the patient has HIV
    \(P\left(test+ve\mid has\ hiv\right)=\frac{72}{75}=0.96\)   
ii. Calculate the probability of test being negative given the patient has HIV     
    \(P\left(test-ve\mid has\ hiv\right)=1-P\left(test+ve\mid has\ hiv\right)=0.04\)
    or 
    \(P\left(test-ve\mid has\ hiv\right)=\frac{3}{75}=0.04\)
iii. If the prevalence of HIV is 12% in intravenous drug users (12 cases per 100 patients), what is the probability of the patient having HIV after a positive test? A negative test?
     
\(P\left(has\ hiv\mid+ve\ test\right)=P\left(+ve\ test\mid has\ hiv\right)\ast\frac{P\left(prevalence\ of\ hiv\right)}{p\left(+ve\ test\right)}\) =\(0.96\ast\frac{0.12}{\frac{84}{158}}\) =0.2166
    \(P\left(has\ hiv\mid-ve\ test\right)==P\left(-ve\ test\mid has\ hiv\right)\ast\frac{P\left(prevalence\ of\ hiv\right)}{p\left(-ve\ test\right)}\)=\(0.04\ast\frac{0.12}{\frac{74}{158}}=0.0102\)
2. Bayes Theorem
(a) Monty Hall problem: On the game show, Let’s make a Deal, you are shown four doors: A, B, C, and D, and behind exactly one of them is a big prize. Michael, the contestant, selects one of them, say door C, because he know from having watched countless number of past shows that door C has twice the probability of being the right door than door A or door B or door D. To make things more interesting, Monty Hall, game show host, opens one of the other doors, say door B, revealing that the big prize is not behind door B. He then offers Michael the opportunity to change the selection to one of the remaining doors (door A or door D). Should Michael change his selection? Justify your answer by calculating the probability that the prize is behind door A, the probability that the prize is behind door C, and the probability that the prize is behind door D, given that Monty Hall opened door B (to show that prize is not there), using Bayes Theorem.
\(P\left(prize\ is\ in\ A\right)=\frac{1}{5}\)
\(P\left(prize\ is\ in\ B\right)=\frac{1}{5}\)
\(P\left(prize\ is\ in\ C\right)=\frac{2}{5}\)
\(P\left(prize\ is\ in\ D\right)=\frac{1}{5}\)\(P\left(C\ has\ the\ prize\mid B\ is\ open\ and\ empty\right)=\frac{P\left(B\ is\ open\ and\ empty\mid C\ has\ the\ prize\right)}{\left(P\left(B\ is\ open\ and\ empty\right)\right)}\ast P\left(C\ has\ the\ prize\right)\)
P(B is empty) can have 3 different cases as listed below
p(Neither B or C have the prize)=1/5
p( B does not have the prize but C Does)=2/5
p( B has the prize  and C does not=2/5
P(b is open and empty)=P(..|b has the prize but c does not)*P(B has the prize but c does not)+p(....|not b but c)*p(not b but c)+p...|neither b nor c)*p(neither b nor c)=\(\frac{1}{5}\ast0+\frac{2}{5}\ast\frac{1}{3}+\frac{1}{2}\ast\frac{2}{5}=0.333\)
Also we know that P(B is open)does not depend on P(B is empty)
\(\Rightarrow P\left(C\ has\ prize\text{| }B\ is\ opened\ and\ empty\right)\)\(\frac{P\left(B\ is\ opene\mid\ C\ has\ the\ prize\right)}{\frac{1}{3}}\ast P\left(B\ is\ emptye\mid C\ has\ the\ prize\right)\ast\frac{2}{5}\approx0.4\)
We know that \(P\left(A\ has\ prize\text{| }B\ is\ opened\ and\ empty\right)=P\left(D\ has\ prize\text{| }B\ is\ opened\ and\ empty\right)\) ...eq 1
\(P\left(A\ has\ prize\text{| }B\ is\ opened\ and\ empty\right)=\)\(P\left(B\ is\ opened\ and\ empty\text{| }A\ has\ the\ prize\right)\ast\frac{P\left(A\ has\ the\ prize\right)}{P\left(B\ is\ open\ and\ empty\right)}\)
    =\(P\left(B\ is\ opened\ \text{| }A\ has\ the\ prize\right)\ast\frac{\left(P\left(B\ is\ empty\ \text{| }A\ has\ the\ prize\right)\ast P\right)\left(A\ has\ the\ prize\right)}{P\left(B\ is\ open\ and\ empty\right)}\)
Similar to previous case we can find P(B opened and empty)=P(b is open|A has the prize)* p(A has the prize)=1/30
\(\therefore\ P\left(A\ has\ the\ prize\mid B\ is\ opened\ and\ empty\right)=\frac{1}{3}\ast\frac{1}{5}\ast\frac{30}{11}=0.181\approx0.182\)
from eq 1 \(P\left(D\ has\ prize\text{| }B\ is\ opened\ and\ empty\right)=0.182\)
Clearly Probability of the prize being behind C is still greater and therefore the contestant should not switch his choice and should stick with C.
(b) Prof. Chin knows that historically 2 out 75 students in his CS 542 class cheats (!) on his exams. Last semester, he suspected one of the students engaged in cheating during the final, but when he gently confronted the student, the student vehemently denied that he was cheating. If Prof. Chin has 90% accuracy in identifying cheaters (i.e. if a student is cheating, 90% of the time, Prof. Chin will indeed identify that the student as a cheater), but also has 20% false alarm rate (i.e. even though a student is not cheating, Prof. Chin will erroneously identify that student as a cheater). What is the probability that the student Prof. Chin confronted in the last semester’s final was indeed cheating?
P(student is really cheating|student is identified as cheater)=\(\frac{P\left(student\ is\ identified\ as\ cheater\mid student\ is\ really\ cheating\right)}{P\left(student\ is\ identified\ as\ a\ cheater\right)}\ast P\left(student\ is\ really\ cheating\right)\) ...eq1
Furthermore, P(student is identified as cheater)=\(P\left(student\ identified\ as\ cheater\mid student\ is\ really\ cheating\right)\cdot P\left(student\ is\ really\ cheating\right)+\)   \(P\left(student\ identified\ as\ cheater\mid student\ is\ not\ cheating\right)\cdot P\left(student\ is\ not\ cheating\right)\)=\(\frac{90\ast2}{100\ast75}+\frac{73}{75}\ast\frac{20}{100}=0.22\)    ..val 1
Using val 1 in eq 1
we get   P(student is really cheating | student is identified as cheater)= \(0.9\ast2\ast\frac{375}{75\ast82}=0.109\)
question 3 ,4 are attached after q5
5.
Code is in file RPC.py
Result when i played ny times:W30 L36 D34
Result when algo played ny times:W34 L33 D 33