% Exercise 3.39 Ternary Channel
%
% prsissj means probability recieved si if sent sj (given)
% prsi    means probability received si (qusetion in (a))
% pssi    means probability sent si (given 1/3 each)
% pssirsj means probability sent si if recieved sj (question in (b))
%
prs1ss1 = 0.75;  prs2ss1 = 0.1; prs3ss1 = 0.15;
prs1ss2 = 0.098; prs2ss2 = 0.9; prs3ss2 = 0.002;
prs1ss3 = 0.02;  prs2ss3 = 0.08; prs3ss3 = 0.9;

pss1 = 1/3; pss2 = 1/3; pss3 = 1/3; 

%(a) total probabaility formula
prs1 = prs1ss1 * pss1 + prs1ss2 * pss2 + prs1ss3 * pss3  %0.2893
prs2 = prs2ss1 * pss1 + prs2ss2 * pss2 + prs2ss3 * pss3  %0.3600
prs3 = prs3ss1 * pss1 + prs3ss2 * pss2 + prs3ss3 * pss3  %0.3507

%(b) Bayes' formula
pss1rs1 = prs1ss1 * pss1/prs1 %0.8641
pss2rs1 = prs1ss2 * pss2/prs1 %0.1129
pss3rs1 = prs1ss3 * pss3/prs1 %0.0230
    
pss1rs2 = prs2ss1 * pss1/prs2 %0.0926
pss2rs2 = prs2ss2 * pss2/prs2 %0.8333
pss3rs2 = prs2ss3 * pss3/prs2 %0.0741
    
pss1rs3 = prs3ss1 * pss1/prs3 %0.1426
pss2rs3 = prs3ss2 * pss2/prs3 %0.0019
pss3rs3 = prs3ss3 * pss3/prs3 %0.8555 


 %0.8641  0.1129   0.0230
 %0.0926  0.8333   0.0741
 %0.1426  0.0019   0.8555 


