Did HW4 - Q1a

This commit is contained in:
Uzair Mohammed 2024-04-28 13:35:09 -07:00
parent 33c4f6605c
commit e06f60b7be
8 changed files with 64 additions and 21 deletions

28
hw4/bn.py Normal file
View File

@ -0,0 +1,28 @@
# Defining the local conditional probability distributions
P_F = {1: 0.01, 0: 0.99}
P_E = {1: 0.02, 0: 0.98}
P_A_given_FE = {(1, 1): 0.95, (1, 0): 0.94, (0, 1): 0.29, (0, 0): 0.001}
P_B_given_A = {1: 0.90, 0: 0.05}
P_C_given_A = {1: 0.70, 0: 0.01}
# Function to calculate joint probabilities
def joint_probability(f, e, a, b, c):
return (P_F[f] * P_E[e] * P_A_given_FE[(f, e)] *
P_B_given_A[a if b else 0] *
P_C_given_A[a if c else 0])
# Calculating total probabilities where B=1 and C=1 respectively
total_P_B_1 = sum([joint_probability(f, e, a, b, c) for f in [1, 0] for e in [1, 0]
for a in [1, 0] for b in [1, 0] for c in [1, 0]])
total_P_C_1 = sum([joint_probability(f, e, a, b, c) for f in [1, 0] for e in [1, 0]
for a in [1, 0] for b in [1, 0] for c in [1, 1]])
# Calculate P(F=1 | B=1)
P_F_given_B = total_P_B_1 / (total_P_B_1 + total_P_B_1)
# Calculate P(F=1 | C=1)
P_F_given_C = total_P_C_1 / (total_P_C_1 + total_P_C_1)
# Print the results
print(f"P(F=1 | B=1): {P_F_given_B:.6f}")
print(f"P(F=1 | C=1): {P_F_given_C:.6f}")

BIN
hw4/hw4.pdf Normal file

Binary file not shown.

View File

@ -14,7 +14,9 @@
\@writefile{toc}{\contentsline {subsection}{\numberline {2.1}Cake}{8}{}\protected@file@percent }
\@writefile{toc}{\contentsline {subsection}{\numberline {2.2}Knights and Knaves}{10}{}\protected@file@percent }
\@writefile{toc}{\contentsline {subsection}{\numberline {2.3}Odds and Evens}{10}{}\protected@file@percent }
\@writefile{toc}{\contentsline {section}{\numberline {3}Homework 3}{10}{}\protected@file@percent }
\@writefile{toc}{\contentsline {subsection}{\numberline {3.1}Probability}{10}{}\protected@file@percent }
\@writefile{toc}{\contentsline {subsection}{\numberline {3.2}Bayesian Networks}{12}{}\protected@file@percent }
\gdef \@abspage@last{14}
\@writefile{toc}{\contentsline {section}{\numberline {3}Homework 3}{11}{}\protected@file@percent }
\@writefile{toc}{\contentsline {subsection}{\numberline {3.1}Probability}{11}{}\protected@file@percent }
\@writefile{toc}{\contentsline {subsection}{\numberline {3.2}Bayesian Networks}{13}{}\protected@file@percent }
\@writefile{toc}{\contentsline {section}{\numberline {4}Homework 4}{15}{}\protected@file@percent }
\@writefile{toc}{\contentsline {subsection}{\numberline {4.1}Inference in Bayesian Networks}{15}{}\protected@file@percent }
\gdef \@abspage@last{16}

View File

@ -1,5 +1,5 @@
# Fdb version 4
["pdflatex"] 1712556659.16135 "d:/uzair/projects/sfsu/csc-665-homework/main.tex" "main.pdf" "main" 1712556660.13536 0
["pdflatex"] 1714185989.04402 "d:/uzair/projects/sfsu/csc-665-homework/main.tex" "main.pdf" "main" 1714185989.96268 0
"C:/Users/uzair/AppData/Local/MiKTeX/fonts/map/pdftex/pdftex.map" 1712556651 80909 eab91d9745dd2edfd62a31d53cd5fe15 ""
"C:/Users/uzair/AppData/Local/MiKTeX/fonts/pk/ljfour/jknappen/ec/dpi600/tcrm1000.pk" 1712556658 11548 a6bc95c64a58583bcc706361e95fcb96 ""
"C:/Users/uzair/AppData/Local/MiKTeX/miktex/data/le/pdftex/pdflatex.fmt" 1712556641 24236005 6c179fc8e955800dbf130a4c2d55d82a ""
@ -53,13 +53,13 @@
"C:/Users/uzair/AppData/Local/Programs/MiKTeX/tex/latex/mathtools/mathtools.sty" 1710159379 62672 9ff036bc89365461cc2bd482cc1e4879 ""
"C:/Users/uzair/AppData/Local/Programs/MiKTeX/tex/latex/mathtools/mhsetup.sty" 1710159379 5582 a43dedf8e5ec418356f1e9dfe5d29fc3 ""
"C:/Users/uzair/AppData/Local/Programs/MiKTeX/tex/latex/tools/calc.sty" 1700599895 10214 547fd4d29642cb7c80bf54b49d447f01 ""
"d:/uzair/projects/sfsu/csc-665-homework/main.tex" 1712556613 22454 30dc189b4988585fda24a0c9b097eb14 ""
"d:/uzair/projects/sfsu/csc-665-homework/main.tex" 1714185988 22634 95ce1149903e46d013b118eb7ea9940f ""
"hw2/gameTree.png" 1712556571 51736 b13904e696801b947e455a901505f683 ""
"hw3/bayesian_network_1_hw3.png" 1712533911 42320 08df33c7ebceab0a98b148f3e43f6efe ""
"hw3/motorcade.png" 1712535186 144191 cdb52bfe315df9dd25d1d06a6414fa5c ""
"main.aux" 1712556659 1818 bf4e5b12f9cccaa5b4ee523e32be112d "pdflatex"
"main.tex" 1712556613 22454 30dc189b4988585fda24a0c9b097eb14 ""
"titlePage.aux" 1712556659 456 c979711f53deacf2b09031977e556db8 "pdflatex"
"main.aux" 1714185989 2041 3a2a9817ca7427fc0eaaae9b1490a77a "pdflatex"
"main.tex" 1714185988 22634 95ce1149903e46d013b118eb7ea9940f ""
"titlePage.aux" 1714185989 456 c979711f53deacf2b09031977e556db8 "pdflatex"
"titlePage.tex" 1712556571 407 ccdbd50244b3194dbad72dd1c7995bf0 ""
(generated)
"main.aux"

View File

@ -1,4 +1,4 @@
This is pdfTeX, Version 3.141592653-2.6-1.40.26 (MiKTeX 24.3.31) (preloaded format=pdflatex 2024.4.7) 7 APR 2024 23:10
This is pdfTeX, Version 3.141592653-2.6-1.40.26 (MiKTeX 24.3.31) (preloaded format=pdflatex 2024.4.7) 26 APR 2024 19:46
entering extended mode
restricted \write18 enabled.
file:line:error style messages enabled.
@ -221,23 +221,23 @@ File: hw2/gameTree.png Graphic file (type png)
<use hw2/gameTree.png>
Package pdftex.def Info: hw2/gameTree.png used on input line 271.
(pdftex.def) Requested size: 153.57494pt x 128.73192pt.
[8] [9 <./hw2/gameTree.png>] [10] [11]
<hw3/bayesian_network_1_hw3.png, id=55, 392.46625pt x 302.12875pt>
[8] [9 <./hw2/gameTree.png>] [10] [11] [12]
<hw3/bayesian_network_1_hw3.png, id=59, 392.46625pt x 302.12875pt>
File: hw3/bayesian_network_1_hw3.png Graphic file (type png)
<use hw3/bayesian_network_1_hw3.png>
Package pdftex.def Info: hw3/bayesian_network_1_hw3.png used on input line 424.
Package pdftex.def Info: hw3/bayesian_network_1_hw3.png used on input line 426.
(pdftex.def) Requested size: 117.74077pt x 90.63931pt.
<hw3/motorcade.png, id=56, 607.51968pt x 603.0028pt>
<hw3/motorcade.png, id=60, 607.51968pt x 603.0028pt>
File: hw3/motorcade.png Graphic file (type png)
<use hw3/motorcade.png>
Package pdftex.def Info: hw3/motorcade.png used on input line 445.
Package pdftex.def Info: hw3/motorcade.png used on input line 447.
(pdftex.def) Requested size: 182.25731pt x 180.90224pt.
[12 <./hw3/bayesian_network_1_hw3.png>]
Underfull \hbox (badness 10000) in paragraph at lines 448--449
[13 <./hw3/bayesian_network_1_hw3.png>]
Underfull \hbox (badness 10000) in paragraph at lines 450--451
[]
[13 <./hw3/motorcade.png>] (main.aux (titlePage.aux))
[14 <./hw3/motorcade.png>] [15] (main.aux (titlePage.aux))
***********
LaTeX2e <2023-11-01> patch level 1
L3 programming layer <2024-03-14>
@ -246,15 +246,15 @@ L3 programming layer <2024-03-14>
Here is how much of TeX's memory you used:
3249 strings out of 474424
50932 string characters out of 5741740
1939496 words of memory out of 5000000
1940496 words of memory out of 5000000
25579 multiletter control sequences out of 15000+600000
562573 words of font info for 53 fonts, out of 8000000 for 9000
1141 hyphenation exceptions out of 8191
65i,19n,72p,462b,279s stack positions out of 10000i,1000n,20000p,200000b,200000s
<C:\Users\uzair\AppData\Local\MiKTeX\fonts/pk/ljfour/jknappen/ec/dpi600\tcrm1000.pk><C:/Users/uzair/AppData/Local/Programs/MiKTeX/fonts/type1/public/amsfonts/cm/cmbx10.pfb><C:/Users/uzair/AppData/Local/Programs/MiKTeX/fonts/type1/public/amsfonts/cm/cmbx12.pfb><C:/Users/uzair/AppData/Local/Programs/MiKTeX/fonts/type1/public/amsfonts/cm/cmex10.pfb><C:/Users/uzair/AppData/Local/Programs/MiKTeX/fonts/type1/public/amsfonts/cm/cmmi10.pfb><C:/Users/uzair/AppData/Local/Programs/MiKTeX/fonts/type1/public/amsfonts/cm/cmmi7.pfb><C:/Users/uzair/AppData/Local/Programs/MiKTeX/fonts/type1/public/amsfonts/cm/cmr10.pfb><C:/Users/uzair/AppData/Local/Programs/MiKTeX/fonts/type1/public/amsfonts/cm/cmr12.pfb><C:/Users/uzair/AppData/Local/Programs/MiKTeX/fonts/type1/public/amsfonts/cm/cmr7.pfb><C:/Users/uzair/AppData/Local/Programs/MiKTeX/fonts/type1/public/amsfonts/cm/cmsy10.pfb><C:/Users/uzair/AppData/Local/Programs/MiKTeX/fonts/type1/public/amsfonts/cm/cmsy7.pfb><C:/Users/uzair/AppData/Local/Programs/MiKTeX/fonts/type1/public/amsfonts/cm/cmti10.pfb><C:/Users/uzair/AppData/Local/Programs/MiKTeX/fonts/type1/public/amsfonts/latxfont/line10.pfb>
Output written on main.pdf (14 pages, 381374 bytes).
Output written on main.pdf (16 pages, 382453 bytes).
PDF statistics:
120 PDF objects out of 1000 (max. 8388607)
126 PDF objects out of 1000 (max. 8388607)
0 named destinations out of 1000 (max. 500000)
16 words of extra memory for PDF output out of 10000 (max. 10000000)

BIN
main.pdf

Binary file not shown.

Binary file not shown.

View File

@ -320,6 +320,8 @@ See attached puzzle.py file
\subsection{Odds and Evens}
See attached submission.py file
\newpage
\section{Homework 3}
\subsection{Probability}
@ -466,7 +468,18 @@ See attached submission.py file
P(\text{Accident} = 1 | \text{Traffic} = 1) \rightarrow P(A | T) = \frac{P(T | A) \cdot P(A)}{P(T)}
$$
\end{itemize}
\newpage
\section{Homework 4}
\subsection{Inference in Bayesian Networks}
\begin{itemize}
\item[a - c. ] Refer to bn.py
\item[d. ]
\end{itemize}
\end{document}