├── .gitignore ├── Homework1 ├── PB17000297_罗晏宸.pdf └── PB17000297_罗晏宸.tex ├── Homework2 ├── Figure6-1(a).png ├── Figure6-1(b).png ├── Figure6-2(a).png ├── Figure6-2(b).png ├── PB17000297_罗晏宸.pdf └── PB17000297_罗晏宸.tex ├── Homework3 ├── Figure5-17.png ├── Figure5-18.png ├── PB17000297_罗晏宸.pdf └── PB17000297_罗晏宸.tex ├── Homework4 ├── PB17000297_罗晏宸.pdf └── PB17000297_罗晏宸.tex ├── Homework5 ├── PB17000297_罗晏宸.pdf └── PB17000297_罗晏宸.tex ├── Homework6 ├── PB17000297_罗晏宸.pdf └── PB17000297_罗晏宸.tex ├── Homework7 ├── Figure │ ├── 14-11.pdf │ ├── 14-22(i).pdf │ ├── 14-22(ii).pdf │ ├── 14-22(iii).pdf │ └── 14-9.pdf ├── PB17000297_罗晏宸.pdf ├── PB17000297_罗晏宸.tex └── Script.nb └── Homework8 ├── Figure └── SVM.pdf ├── PB17000297_罗晏宸.pdf ├── PB17000297_罗晏宸.tex └── SVM.nb /.gitignore: -------------------------------------------------------------------------------- 1 | *.aux 2 | *.log 3 | *.out 4 | *.synctex.gz -------------------------------------------------------------------------------- /Homework1/PB17000297_罗晏宸.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyc0930/AI-Homework/81cc1ab4c2b3cedc1df2cf2ae56b02232aa47563/Homework1/PB17000297_罗晏宸.pdf -------------------------------------------------------------------------------- /Homework1/PB17000297_罗晏宸.tex: -------------------------------------------------------------------------------- 1 | \documentclass{article} 2 | \usepackage[UTF8]{ctex} 3 | \usepackage[T1]{fontenc} 4 | \usepackage[utf8]{inputenc} 5 | \usepackage{titlesec} 6 | \usepackage[colorlinks, linkcolor = black]{hyperref} 7 | \usepackage{float} 8 | \usepackage{xcolor} 9 | \usepackage{tikz} 10 | \usepackage{subfigure} 11 | \usetikzlibrary{positioning} 12 | \usetikzlibrary[arrows, shapes, chains] 13 | 14 | \titleformat{\section}[block]{\LARGE\scshape}{\arabic{section}}{1em}{}[] 15 | 16 | \title{Homework 1} 17 | \author{PB17000297 罗晏宸} 18 | \date{March 1 2020} 19 | 20 | \begin{document} 21 | \maketitle 22 | 23 | \section{Exercise 3.6} 24 | 对以下问题给出完整的形式化。选择的形式化方法要足够精确以便于实现。 25 | \subparagraph{a} 26 | 只用四种颜色对平面地图着色,要求每两个相邻的地区不能具有相同的颜色。 27 | \subparagraph{b} 28 | 屋子里有只3英尺高的猴子,离地8英尺的屋顶上挂着一串香蕉。猴子想吃香蕉。屋子里有两个可叠放、可移动、可攀爬的3英尺高的箱子。 29 | \subparagraph{d} 30 | 有三个水壶,容量分别为12加仑、8加仑和3加仑,还有一个放液嘴。可以把水壶装满或者倒空,从一个壶倒进另一个壶或者倒在地上。请量出刚好1加仑水。 31 | 32 | \paragraph{解} 33 | \subparagraph{a} 34 | \begin{itemize} 35 | \item 初始状态:所有地区均未被着色 36 | \item 可能的行动:给定一个状态,对其中一个未被着色的地区分配一种和与其相邻的已着色地区都不相同的颜色 37 | \item 转移模型:从一个状态达到一个已着色地区数加一的状态 38 | \item 目标测试:所有地区都已被着色,且每两个相邻的地区都不具有相同的颜色 39 | \item 路径耗散:总共的着色次数 40 | \end{itemize} 41 | \subparagraph{b} 42 | \begin{itemize} 43 | \item 初始状态:箱子未被叠放,猴子活动在地面上 44 | \item 可能的行动:在(某一高度上)移动,移动一个(猴子不站立在其上的)箱子,(在两个箱子均放置在地面上时)叠放两个箱子,跳上一个(与猴子在同一高度的)箱子,从一个箱子上跳下,(在猴子最高处达到或超过香蕉高度时)摘取香蕉 45 | \item 转移模型:从一个状态达到另一个状态,猴子以及两个箱子彼此相对位置改变 46 | \item 目标测试:猴子摘取到香蕉 47 | \item 路径耗散:行动次数 48 | \end{itemize} 49 | \subparagraph{d} 50 | \begin{itemize} 51 | \item 初始状态:三个水壶均为空,记为三元组$(0,\,0,\,0)$ 52 | \item 可能的行动:把其中一个水壶倒满,把其中一个水壶倒空,从一个壶倒进另一个壶 53 | \item 转移模型:对于状态$(x_1,\,x_2,\,x_3)$,把一个水壶倒满后可以达到$(3,\,x_2,\,x_3)$、$(x_1,\,8,\,x_3)$或$(x_1,\,x_2,\,12)$,把一个水壶倒空后可以达到$(0,\,x_2,\,x_3)$、$(x_1,\,0,\,x_3)$或$(x_1,\,x_2,\,0)$,从一个壶$i(i = 1,2,3)$倒进另一个壶$j(j = 1,2,3,\, j \neq i)$后可以达到 $x'_i = 0,\, x'_j = x_i + x_j,\ (x_i + x_j \leq C_j)$ 或 $x'_i = x_i + x_j - C_j,\, x'_j = C_j,\ (x_i + x_j > C_j)$ ,其中$C_j$是壶$j$的容量 54 | \item 目标测试:其中一个水壶中刚好有一加仑水 55 | \item 路径耗散:行动次数 56 | \end{itemize} 57 | 58 | \section{Exercise 3.9} 59 | \textbf{传教士和野人}问题。三个传教士和三个野人在河的一岸,有一条能载一个人或者两个人的船。请设法使所有人都渡到河的另一岸,要求在任何地方野人数都不能多于传教士的人数,这个问题在AI领域中很有名,是因为它是第一个从分析的观点探讨问题形式化的论文的主题(Amarel, 1968)。 60 | \subparagraph{a} 61 | 请对该问题进行详细形式化,只描述确保该问题求解所必需的特性。画出完整的状态空间图。 62 | \subparagraph{b} 63 | 应用合适的搜索算法求出该问题的最优解。对于这个问题检查重复状态是个好主意吗? 64 | \subparagraph{c} 65 | 这个问题的状态空间很简单,你认为是什么导致人们求解它很困难? 66 | 67 | \paragraph{解} 68 | \subparagraph{a} 69 | \begin{itemize} 70 | \item 状态:用三元组$(M,\,C,\,B)$表示,其中$M$表示左岸(不妨将开始六人所在的河岸设为左岸)的传教士人数,$C$表示左岸野人数,$B = L$表示船在左岸,$B = R$表示船在右岸。因此可能的状态有$4 \times 4 \times 2 = 32$个,其中受限于在任何地方野人数都不能多于传教士人数的要求,有12个状态不合法,另有5个状态在问题中不存在,因此总的状态有$15$个。 71 | \item 初始状态:三个传教士和三个野人在河的左岸,记为$(3, 3, L)$ 72 | \item 行动:用$T_{M,C}$表示$M$个传教士和$C$个野人划船去另一岸。因此可能的行动有$T_{0,1},\,T_{0,2},\,T_{1,0},\,T_{1,1},\,T_{2,0}$共5种 73 | \item 转移模型:对于状态$(M,\,C,\,B = L/R)$,行动$T_{0,1},\,T_{0,2},\,T_{1,0},\,T_{1,1},\,T_{2,0}$分别转移到$(M,\,C - 1,\,B = R/L),\,(M,\,C - 2,\,B = R/L),\,(M - 1,\,C,\,B = R/L),\,(M - 1,\,C - 1,\,B = R/L),\,(M - 2,\,C,\,B = R/L)$,完整的状态空间如图\ref{figure:1}所示 74 | \item 目标测试:达到状态$(3, 3, R)$ 75 | \item 路径耗散:划船行动的次数 76 | \end{itemize} 77 | \begin{figure}[H] 78 | \centering 79 | \begin{tikzpicture}[node distance = 1.0em] 80 | \tikzstyle{state} = [scale = 0.6, circle, draw=black, text ragged]; 81 | \tikzstyle{illegal} = [scale = 0.6, circle, draw=red!30!white, text ragged, red!30!white] 82 | \node [state] (S0) {$(3, 3, L)$}; 83 | 84 | \node [illegal, below = of S0] (S1) {$(2, 3, R)$}; 85 | \node [state, left = of S1] (S2) {$(3, 1, R)$}; 86 | \node [state, right = of S1] (S3) {$(2, 2, R)$}; 87 | \node [state, left = of S2] (S4) {$(3, 2, R)$}; 88 | \node [illegal, right = of S3] (S5) {$(1, 3, R)$}; 89 | 90 | \node [state, below = of S1] (S6) {$(3, 2, L)$}; 91 | \node [illegal, right = of S6] (S7) {$(2, 3, L)$}; 92 | 93 | \node [illegal, below = of S6] (S8) {$(2, 1, R)$}; 94 | \node [state, left = of S8] (S9) {$(3, 0, R)$}; 95 | \node [illegal, right = of S8] (S10) {$(1, 2, R)$}; 96 | 97 | \node [state, below = of S8] (S11) {$(3, 1, L)$}; 98 | 99 | \node [state, below = of S11] (S12) {$(1, 1, R)$}; 100 | \node [illegal, right = of S12] (S13) {$(2, 0, R)$}; 101 | 102 | 103 | \node [illegal, below = of S12] (S14) {$(2, 1, L)$}; 104 | \node [state, left = of S14] (S15) {$(2, 2, L)$}; 105 | \node [illegal, right = of S14] (S16) {$(1, 2, L)$}; 106 | 107 | \node [state, below = of S14] (S17) {$(0, 2, R)$}; 108 | 109 | \node [state, below = of S17] (S18) {$(0, 3, L)$}; 110 | 111 | \node [state, below = of S18] (S19) {$(0, 1, R)$}; 112 | 113 | \node [state, below = of S19] (S20) {$(1, 1, L)$}; 114 | \node [state, right = of S20] (S21) {$(0, 2, L)$}; 115 | 116 | \node [state, below = of S20] (S22) {$(0, 0, R)$}; 117 | 118 | \foreach \i in {1, ..., 5} 119 | \draw [-triangle 60] (S0) to (S\i); 120 | \foreach \i/\j in {2/6, 3/6, 3/7} 121 | \draw [-triangle 60] (S\i) to (S\j); 122 | \foreach \i in {8, 9, 10} 123 | \draw [-triangle 60] (S6) to (S\i); 124 | \draw [-triangle 60] (S9) to (S11); 125 | \foreach \i in {12, 13, 8} 126 | \draw [-triangle 60] (S11) to (S\i); 127 | \foreach \i in {14, 15, 16} 128 | \draw [-triangle 60] (S12) to (S\i); 129 | \foreach \i in {17, 13} 130 | \draw [-triangle 60] (S15) to (S\i); 131 | \foreach \i/\j in {17/18, 18/19, 19/20, 19/21, 20/22, 21/22} 132 | \draw [-triangle 60] (S\i) to (S\j); 133 | \end{tikzpicture} 134 | \caption{传教士和野人问题的状态空间} 135 | \label{figure:1} 136 | \end{figure} 137 | \subparagraph{b} 138 | 由于状态空间比较简单,应用宽度优先搜索,搜索过程如图\ref{figure:2}所示 139 | \begin{figure} 140 | \centering 141 | \subfigure{ 142 | \begin{tikzpicture}[node distance = 0.3em] 143 | \tikzstyle{state} = [scale = 0.25, circle, draw=black, text ragged]; 144 | \tikzstyle{illegal} = [scale = 0.25, circle, draw=red!30!white, text ragged, red!30!white] 145 | \node [state] (S0) {$(3, 3, L)$}; 146 | \end{tikzpicture} 147 | } 148 | \subfigure{ 149 | \begin{tikzpicture}[node distance = 0.3em] 150 | \tikzstyle{state} = [scale = 0.25, circle, draw=black, text ragged]; 151 | \tikzstyle{illegal} = [scale = 0.25, circle, draw=red!30!white, text ragged, red!30!white] 152 | \node [state] (S0) {$(3, 3, L)$}; 153 | 154 | \node [illegal, below = of S0] (S1) {$(2, 3, R)$}; 155 | \node [state, left = of S1] (S2) {$(3, 1, R)$}; 156 | \node [state, right = of S1] (S3) {$(2, 2, R)$}; 157 | \node [state, left = of S2] (S4) {$(3, 2, R)$}; 158 | \node [illegal, right = of S3] (S5) {$(1, 3, R)$}; 159 | 160 | \foreach \i in {1, ..., 5} 161 | \draw [->] (S0) to (S\i); 162 | 163 | \end{tikzpicture} 164 | } 165 | \subfigure{ 166 | \begin{tikzpicture}[node distance = 0.3em] 167 | \tikzstyle{state} = [scale = 0.25, circle, draw=black, text ragged]; 168 | \tikzstyle{illegal} = [scale = 0.25, circle, draw=red!30!white, text ragged, red!30!white] 169 | \node [state] (S0) {$(3, 3, L)$}; 170 | 171 | \node [illegal, below = of S0] (S1) {$(2, 3, R)$}; 172 | \node [state, left = of S1] (S2) {$(3, 1, R)$}; 173 | \node [state, right = of S1] (S3) {$(2, 2, R)$}; 174 | \node [state, left = of S2] (S4) {$(3, 2, R)$}; 175 | \node [illegal, right = of S3] (S5) {$(1, 3, R)$}; 176 | 177 | \node [state, below = of S1] (S6) {$(3, 2, L)$}; 178 | \node [illegal, right = of S6] (S7) {$(2, 3, L)$}; 179 | 180 | \draw [->] (S0) to (S2); 181 | \draw [->] (S2) to (S6); 182 | \end{tikzpicture} 183 | } 184 | \subfigure{ 185 | \begin{tikzpicture}[node distance = 0.3em] 186 | \tikzstyle{state} = [scale = 0.25, circle, draw=black, text ragged]; 187 | \tikzstyle{illegal} = [scale = 0.25, circle, draw=red!30!white, text ragged, red!30!white] 188 | \node [state] (S0) {$(3, 3, L)$}; 189 | 190 | \node [illegal, below = of S0] (S1) {$(2, 3, R)$}; 191 | \node [state, left = of S1] (S2) {$(3, 1, R)$}; 192 | \node [state, right = of S1] (S3) {$(2, 2, R)$}; 193 | \node [state, left = of S2] (S4) {$(3, 2, R)$}; 194 | \node [illegal, right = of S3] (S5) {$(1, 3, R)$}; 195 | 196 | \node [state, below = of S1] (S6) {$(3, 2, L)$}; 197 | \node [illegal, right = of S6] (S7) {$(2, 3, L)$}; 198 | 199 | \node [illegal, below = of S6] (S8) {$(2, 1, R)$}; 200 | \node [state, left = of S8] (S9) {$(3, 0, R)$}; 201 | \node [illegal, right = of S8] (S10) {$(1, 2, R)$}; 202 | 203 | 204 | \draw [->] (S0) to (S2); 205 | \draw [->] (S2) to (S6); 206 | \foreach \i in {8, 9, 10} 207 | \draw [->] (S6) to (S\i); 208 | \end{tikzpicture} 209 | } 210 | 211 | \subfigure{ 212 | \begin{tikzpicture}[node distance = 0.3em] 213 | \tikzstyle{state} = [scale = 0.25, circle, draw=black, text ragged]; 214 | \tikzstyle{illegal} = [scale = 0.25, circle, draw=red!30!white, text ragged, red!30!white] 215 | \node [state] (S0) {$(3, 3, L)$}; 216 | 217 | \node [illegal, below = of S0] (S1) {$(2, 3, R)$}; 218 | \node [state, left = of S1] (S2) {$(3, 1, R)$}; 219 | \node [state, right = of S1] (S3) {$(2, 2, R)$}; 220 | \node [state, left = of S2] (S4) {$(3, 2, R)$}; 221 | \node [illegal, right = of S3] (S5) {$(1, 3, R)$}; 222 | 223 | \node [state, below = of S1] (S6) {$(3, 2, L)$}; 224 | \node [illegal, right = of S6] (S7) {$(2, 3, L)$}; 225 | 226 | \node [illegal, below = of S6] (S8) {$(2, 1, R)$}; 227 | \node [state, left = of S8] (S9) {$(3, 0, R)$}; 228 | \node [illegal, right = of S8] (S10) {$(1, 2, R)$}; 229 | 230 | \node [state, below = of S8] (S11) {$(3, 1, L)$}; 231 | 232 | 233 | \draw [->] (S0) to (S2); 234 | \draw [->] (S2) to (S6); 235 | \draw [->] (S6) to (S9); 236 | \draw [->] (S9) to (S11); 237 | \end{tikzpicture} 238 | } 239 | \subfigure{ 240 | \begin{tikzpicture}[node distance = 0.3em] 241 | \tikzstyle{state} = [scale = 0.25, circle, draw=black, text ragged]; 242 | \tikzstyle{illegal} = [scale = 0.25, circle, draw=red!30!white, text ragged, red!30!white] 243 | \node [state] (S0) {$(3, 3, L)$}; 244 | 245 | \node [illegal, below = of S0] (S1) {$(2, 3, R)$}; 246 | \node [state, left = of S1] (S2) {$(3, 1, R)$}; 247 | \node [state, right = of S1] (S3) {$(2, 2, R)$}; 248 | \node [state, left = of S2] (S4) {$(3, 2, R)$}; 249 | \node [illegal, right = of S3] (S5) {$(1, 3, R)$}; 250 | 251 | \node [state, below = of S1] (S6) {$(3, 2, L)$}; 252 | \node [illegal, right = of S6] (S7) {$(2, 3, L)$}; 253 | 254 | \node [illegal, below = of S6] (S8) {$(2, 1, R)$}; 255 | \node [state, left = of S8] (S9) {$(3, 0, R)$}; 256 | \node [illegal, right = of S8] (S10) {$(1, 2, R)$}; 257 | 258 | \node [state, below = of S8] (S11) {$(3, 1, L)$}; 259 | 260 | \node [state, below = of S11] (S12) {$(1, 1, R)$}; 261 | \node [illegal, right = of S12] (S13) {$(2, 0, R)$}; 262 | 263 | \draw [->] (S0) to (S2); 264 | \draw [->] (S2) to (S6); 265 | \draw [->] (S6) to (S9); 266 | \draw [->] (S9) to (S11); 267 | \foreach \i in {12, 13, 8} 268 | \draw [->] (S11) to (S\i); 269 | \end{tikzpicture} 270 | } 271 | \subfigure{ 272 | \begin{tikzpicture}[node distance = 0.3em] 273 | \tikzstyle{state} = [scale = 0.25, circle, draw=black, text ragged]; 274 | \tikzstyle{illegal} = [scale = 0.25, circle, draw=red!30!white, text ragged, red!30!white] 275 | \node [state] (S0) {$(3, 3, L)$}; 276 | 277 | \node [illegal, below = of S0] (S1) {$(2, 3, R)$}; 278 | \node [state, left = of S1] (S2) {$(3, 1, R)$}; 279 | \node [state, right = of S1] (S3) {$(2, 2, R)$}; 280 | \node [state, left = of S2] (S4) {$(3, 2, R)$}; 281 | \node [illegal, right = of S3] (S5) {$(1, 3, R)$}; 282 | 283 | \node [state, below = of S1] (S6) {$(3, 2, L)$}; 284 | \node [illegal, right = of S6] (S7) {$(2, 3, L)$}; 285 | 286 | \node [illegal, below = of S6] (S8) {$(2, 1, R)$}; 287 | \node [state, left = of S8] (S9) {$(3, 0, R)$}; 288 | \node [illegal, right = of S8] (S10) {$(1, 2, R)$}; 289 | 290 | \node [state, below = of S8] (S11) {$(3, 1, L)$}; 291 | 292 | \node [state, below = of S11] (S12) {$(1, 1, R)$}; 293 | \node [illegal, right = of S12] (S13) {$(2, 0, R)$}; 294 | 295 | 296 | \node [illegal, below = of S12] (S14) {$(2, 1, L)$}; 297 | \node [state, left = of S14] (S15) {$(2, 2, L)$}; 298 | \node [illegal, right = of S14] (S16) {$(1, 2, L)$}; 299 | 300 | \draw [->] (S0) to (S2); 301 | \draw [->] (S2) to (S6); 302 | \draw [->] (S6) to (S9); 303 | \draw [->] (S9) to (S11); 304 | \draw [->] (S11) to (S12); 305 | \foreach \i in {14, 15, 16} 306 | \draw [->] (S12) to (S\i); 307 | \end{tikzpicture} 308 | } 309 | \subfigure{ 310 | \begin{tikzpicture}[node distance = 0.3em] 311 | \tikzstyle{state} = [scale = 0.25, circle, draw=black, text ragged]; 312 | \tikzstyle{illegal} = [scale = 0.25, circle, draw=red!30!white, text ragged, red!30!white] 313 | \node [state] (S0) {$(3, 3, L)$}; 314 | 315 | \node [illegal, below = of S0] (S1) {$(2, 3, R)$}; 316 | \node [state, left = of S1] (S2) {$(3, 1, R)$}; 317 | \node [state, right = of S1] (S3) {$(2, 2, R)$}; 318 | \node [state, left = of S2] (S4) {$(3, 2, R)$}; 319 | \node [illegal, right = of S3] (S5) {$(1, 3, R)$}; 320 | 321 | \node [state, below = of S1] (S6) {$(3, 2, L)$}; 322 | \node [illegal, right = of S6] (S7) {$(2, 3, L)$}; 323 | 324 | \node [illegal, below = of S6] (S8) {$(2, 1, R)$}; 325 | \node [state, left = of S8] (S9) {$(3, 0, R)$}; 326 | \node [illegal, right = of S8] (S10) {$(1, 2, R)$}; 327 | 328 | \node [state, below = of S8] (S11) {$(3, 1, L)$}; 329 | 330 | \node [state, below = of S11] (S12) {$(1, 1, R)$}; 331 | \node [illegal, right = of S12] (S13) {$(2, 0, R)$}; 332 | 333 | 334 | \node [illegal, below = of S12] (S14) {$(2, 1, L)$}; 335 | \node [state, left = of S14] (S15) {$(2, 2, L)$}; 336 | \node [illegal, right = of S14] (S16) {$(1, 2, L)$}; 337 | 338 | \node [state, below = of S14] (S17) {$(0, 2, R)$}; 339 | 340 | \draw [->] (S0) to (S2); 341 | \draw [->] (S2) to (S6); 342 | \draw [->] (S6) to (S9); 343 | \draw [->] (S9) to (S11); 344 | \draw [->] (S11) to (S12); 345 | \draw [->] (S12) to (S15); 346 | \foreach \i in {17, 13} 347 | \draw [->] (S15) to (S\i); 348 | \end{tikzpicture} 349 | } 350 | 351 | \subfigure{ 352 | \begin{tikzpicture}[node distance = 0.3em] 353 | \tikzstyle{state} = [scale = 0.25, circle, draw=black, text ragged]; 354 | \tikzstyle{illegal} = [scale = 0.25, circle, draw=red!30!white, text ragged, red!30!white] 355 | \node [state] (S0) {$(3, 3, L)$}; 356 | 357 | \node [illegal, below = of S0] (S1) {$(2, 3, R)$}; 358 | \node [state, left = of S1] (S2) {$(3, 1, R)$}; 359 | \node [state, right = of S1] (S3) {$(2, 2, R)$}; 360 | \node [state, left = of S2] (S4) {$(3, 2, R)$}; 361 | \node [illegal, right = of S3] (S5) {$(1, 3, R)$}; 362 | 363 | \node [state, below = of S1] (S6) {$(3, 2, L)$}; 364 | \node [illegal, right = of S6] (S7) {$(2, 3, L)$}; 365 | 366 | \node [illegal, below = of S6] (S8) {$(2, 1, R)$}; 367 | \node [state, left = of S8] (S9) {$(3, 0, R)$}; 368 | \node [illegal, right = of S8] (S10) {$(1, 2, R)$}; 369 | 370 | \node [state, below = of S8] (S11) {$(3, 1, L)$}; 371 | 372 | \node [state, below = of S11] (S12) {$(1, 1, R)$}; 373 | \node [illegal, right = of S12] (S13) {$(2, 0, R)$}; 374 | 375 | 376 | \node [illegal, below = of S12] (S14) {$(2, 1, L)$}; 377 | \node [state, left = of S14] (S15) {$(2, 2, L)$}; 378 | \node [illegal, right = of S14] (S16) {$(1, 2, L)$}; 379 | 380 | \node [state, below = of S14] (S17) {$(0, 2, R)$}; 381 | 382 | \node [state, below = of S17] (S18) {$(0, 3, L)$}; 383 | 384 | \draw [->] (S0) to (S2); 385 | \draw [->] (S2) to (S6); 386 | \draw [->] (S6) to (S9); 387 | \draw [->] (S9) to (S11); 388 | \draw [->] (S11) to (S12); 389 | \draw [->] (S12) to (S15); 390 | \draw [->] (S15) to (S17); 391 | \draw [->] (S17) to (S18); 392 | \end{tikzpicture} 393 | } 394 | \subfigure{ 395 | \begin{tikzpicture}[node distance = 0.3em] 396 | \tikzstyle{state} = [scale = 0.25, circle, draw=black, text ragged]; 397 | \tikzstyle{illegal} = [scale = 0.25, circle, draw=red!30!white, text ragged, red!30!white] 398 | \node [state] (S0) {$(3, 3, L)$}; 399 | 400 | \node [illegal, below = of S0] (S1) {$(2, 3, R)$}; 401 | \node [state, left = of S1] (S2) {$(3, 1, R)$}; 402 | \node [state, right = of S1] (S3) {$(2, 2, R)$}; 403 | \node [state, left = of S2] (S4) {$(3, 2, R)$}; 404 | \node [illegal, right = of S3] (S5) {$(1, 3, R)$}; 405 | 406 | \node [state, below = of S1] (S6) {$(3, 2, L)$}; 407 | \node [illegal, right = of S6] (S7) {$(2, 3, L)$}; 408 | 409 | \node [illegal, below = of S6] (S8) {$(2, 1, R)$}; 410 | \node [state, left = of S8] (S9) {$(3, 0, R)$}; 411 | \node [illegal, right = of S8] (S10) {$(1, 2, R)$}; 412 | 413 | \node [state, below = of S8] (S11) {$(3, 1, L)$}; 414 | 415 | \node [state, below = of S11] (S12) {$(1, 1, R)$}; 416 | \node [illegal, right = of S12] (S13) {$(2, 0, R)$}; 417 | 418 | 419 | \node [illegal, below = of S12] (S14) {$(2, 1, L)$}; 420 | \node [state, left = of S14] (S15) {$(2, 2, L)$}; 421 | \node [illegal, right = of S14] (S16) {$(1, 2, L)$}; 422 | 423 | \node [state, below = of S14] (S17) {$(0, 2, R)$}; 424 | 425 | \node [state, below = of S17] (S18) {$(0, 3, L)$}; 426 | 427 | \node [state, below = of S18] (S19) {$(0, 1, R)$}; 428 | 429 | \draw [->] (S0) to (S2); 430 | \draw [->] (S2) to (S6); 431 | \draw [->] (S6) to (S9); 432 | \draw [->] (S9) to (S11); 433 | \draw [->] (S11) to (S12); 434 | \draw [->] (S12) to (S15); 435 | \draw [->] (S15) to (S17); 436 | \draw [->] (S17) to (S18); 437 | \draw [->] (S18) to (S19); 438 | \end{tikzpicture} 439 | } 440 | \subfigure{ 441 | \begin{tikzpicture}[node distance = 0.3em] 442 | \tikzstyle{state} = [scale = 0.25, circle, draw=black, text ragged]; 443 | \tikzstyle{illegal} = [scale = 0.25, circle, draw=red!30!white, text ragged, red!30!white] 444 | \node [state] (S0) {$(3, 3, L)$}; 445 | 446 | \node [illegal, below = of S0] (S1) {$(2, 3, R)$}; 447 | \node [state, left = of S1] (S2) {$(3, 1, R)$}; 448 | \node [state, right = of S1] (S3) {$(2, 2, R)$}; 449 | \node [state, left = of S2] (S4) {$(3, 2, R)$}; 450 | \node [illegal, right = of S3] (S5) {$(1, 3, R)$}; 451 | 452 | \node [state, below = of S1] (S6) {$(3, 2, L)$}; 453 | \node [illegal, right = of S6] (S7) {$(2, 3, L)$}; 454 | 455 | \node [illegal, below = of S6] (S8) {$(2, 1, R)$}; 456 | \node [state, left = of S8] (S9) {$(3, 0, R)$}; 457 | \node [illegal, right = of S8] (S10) {$(1, 2, R)$}; 458 | 459 | \node [state, below = of S8] (S11) {$(3, 1, L)$}; 460 | 461 | \node [state, below = of S11] (S12) {$(1, 1, R)$}; 462 | \node [illegal, right = of S12] (S13) {$(2, 0, R)$}; 463 | 464 | 465 | \node [illegal, below = of S12] (S14) {$(2, 1, L)$}; 466 | \node [state, left = of S14] (S15) {$(2, 2, L)$}; 467 | \node [illegal, right = of S14] (S16) {$(1, 2, L)$}; 468 | 469 | \node [state, below = of S14] (S17) {$(0, 2, R)$}; 470 | 471 | \node [state, below = of S17] (S18) {$(0, 3, L)$}; 472 | 473 | \node [state, below = of S18] (S19) {$(0, 1, R)$}; 474 | 475 | \node [state, below = of S19] (S20) {$(1, 1, L)$}; 476 | \node [state, right = of S20] (S21) {$(0, 2, L)$}; 477 | 478 | \draw [->] (S0) to (S2); 479 | \draw [->] (S2) to (S6); 480 | \draw [->] (S6) to (S9); 481 | \draw [->] (S9) to (S11); 482 | \draw [->] (S11) to (S12); 483 | \draw [->] (S12) to (S15); 484 | \draw [->] (S15) to (S17); 485 | \draw [->] (S17) to (S18); 486 | \draw [->] (S18) to (S19); 487 | \foreach \i/\j in {19/20, 19/21} 488 | \draw [->] (S\i) to (S\j); 489 | \end{tikzpicture} 490 | } 491 | \subfigure{ 492 | \begin{tikzpicture}[node distance = 0.3em] 493 | \tikzstyle{state} = [scale = 0.25, circle, draw=black, text ragged]; 494 | \tikzstyle{illegal} = [scale = 0.25, circle, draw=red!30!white, text ragged, red!30!white] 495 | \node [state] (S0) {$(3, 3, L)$}; 496 | 497 | \node [illegal, below = of S0] (S1) {$(2, 3, R)$}; 498 | \node [state, left = of S1] (S2) {$(3, 1, R)$}; 499 | \node [state, right = of S1] (S3) {$(2, 2, R)$}; 500 | \node [state, left = of S2] (S4) {$(3, 2, R)$}; 501 | \node [illegal, right = of S3] (S5) {$(1, 3, R)$}; 502 | 503 | \node [state, below = of S1] (S6) {$(3, 2, L)$}; 504 | \node [illegal, right = of S6] (S7) {$(2, 3, L)$}; 505 | 506 | \node [illegal, below = of S6] (S8) {$(2, 1, R)$}; 507 | \node [state, left = of S8] (S9) {$(3, 0, R)$}; 508 | \node [illegal, right = of S8] (S10) {$(1, 2, R)$}; 509 | 510 | \node [state, below = of S8] (S11) {$(3, 1, L)$}; 511 | 512 | \node [state, below = of S11] (S12) {$(1, 1, R)$}; 513 | \node [illegal, right = of S12] (S13) {$(2, 0, R)$}; 514 | 515 | 516 | \node [illegal, below = of S12] (S14) {$(2, 1, L)$}; 517 | \node [state, left = of S14] (S15) {$(2, 2, L)$}; 518 | \node [illegal, right = of S14] (S16) {$(1, 2, L)$}; 519 | 520 | \node [state, below = of S14] (S17) {$(0, 2, R)$}; 521 | 522 | \node [state, below = of S17] (S18) {$(0, 3, L)$}; 523 | 524 | \node [state, below = of S18] (S19) {$(0, 1, R)$}; 525 | 526 | \node [state, below = of S19] (S20) {$(1, 1, L)$}; 527 | \node [state, right = of S20] (S21) {$(0, 2, L)$}; 528 | 529 | \node [state, below = of S20] (S22) {$(0, 0, R)$}; 530 | 531 | \draw [->] (S0) to (S2); 532 | \draw [->] (S2) to (S6); 533 | \draw [->] (S6) to (S9); 534 | \draw [->] (S9) to (S11); 535 | \draw [->] (S11) to (S12); 536 | \draw [->] (S12) to (S15); 537 | \draw [->] (S15) to (S17); 538 | \draw [->] (S17) to (S18); 539 | \draw [->] (S18) to (S19); 540 | \draw [->] (S19) to (S20); 541 | \draw [->] (S20) to (S22); 542 | \end{tikzpicture} 543 | } 544 | \label{figure:2} 545 | \caption{宽度优先搜索解决问题} 546 | \end{figure} 547 | \subparagraph{c} 548 | 尽管状态空间简单,但是有大量不合法的状态,并且存在状态的回溯,因此搜索的重复度较高,求解较为困难 549 | 550 | \end{document} -------------------------------------------------------------------------------- /Homework2/Figure6-1(a).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyc0930/AI-Homework/81cc1ab4c2b3cedc1df2cf2ae56b02232aa47563/Homework2/Figure6-1(a).png -------------------------------------------------------------------------------- /Homework2/Figure6-1(b).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyc0930/AI-Homework/81cc1ab4c2b3cedc1df2cf2ae56b02232aa47563/Homework2/Figure6-1(b).png -------------------------------------------------------------------------------- /Homework2/Figure6-2(a).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyc0930/AI-Homework/81cc1ab4c2b3cedc1df2cf2ae56b02232aa47563/Homework2/Figure6-2(a).png -------------------------------------------------------------------------------- /Homework2/Figure6-2(b).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyc0930/AI-Homework/81cc1ab4c2b3cedc1df2cf2ae56b02232aa47563/Homework2/Figure6-2(b).png -------------------------------------------------------------------------------- /Homework2/PB17000297_罗晏宸.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyc0930/AI-Homework/81cc1ab4c2b3cedc1df2cf2ae56b02232aa47563/Homework2/PB17000297_罗晏宸.pdf -------------------------------------------------------------------------------- /Homework2/PB17000297_罗晏宸.tex: -------------------------------------------------------------------------------- 1 | \documentclass{article} 2 | \usepackage[UTF8]{ctex} 3 | \usepackage[T1]{fontenc} 4 | \usepackage[utf8]{inputenc} 5 | \usepackage{titlesec} 6 | \usepackage{xcolor} 7 | \usepackage[colorlinks, linkcolor = black]{hyperref} 8 | \usepackage{tikz} 9 | \usepackage{mathpazo} 10 | \usepackage{subfigure} 11 | \usepackage{amsmath} 12 | \usepackage{amsthm} 13 | \usepackage{amssymb} 14 | \usepackage{enumerate} 15 | \usepackage{geometry} 16 | \usetikzlibrary{positioning} 17 | \usetikzlibrary[arrows, shapes, chains] 18 | \newcounter{row} 19 | \newcounter{col} 20 | 21 | \newcommand\setrow[3]{ 22 | \setcounter{col}{1} 23 | \foreach \n in {#1, #2, #3} { 24 | \edef\x{\value{col} - 0.5} 25 | \edef\y{3.5 - \value{row}} 26 | \node[anchor = center] at (\x, \y) {\n}; 27 | \stepcounter{col} 28 | } 29 | \stepcounter{row} 30 | } 31 | 32 | \titleformat{\section}[block]{\LARGE\scshape}{\arabic{section}}{1em}{}[] 33 | 34 | \tikzset{ 35 | normal/.style = {ellipse, draw = black, text ragged, minimum width = 6em, scale = 0.5}, 36 | expand/.style = {ellipse, draw = red!70!black, text ragged, minimum width = 6em, black, fill = red!30!white, scale = 0.5}, 37 | length/.style = {text ragged, scale = 0.4}, 38 | level distance = 5em, 39 | level 1/.style = {sibling distance = 60em}, 40 | level 2/.style = {sibling distance = 30em}, 41 | level 3/.style = {sibling distance = 20em}, 42 | level 4/.style = {sibling distance = 8em}, 43 | level 5/.style = {sibling distance = 10em} 44 | } 45 | 46 | \title{Homework 2} 47 | \author{PB17000297 罗晏宸} 48 | \date{March 8 2020} 49 | 50 | \begin{document} 51 | \maketitle 52 | 53 | \section{Exercise 3.6} 54 | 跟踪A$^*$算法应用直线距离启发式求解从 Lugoj 到 Bucharest 问题的过程。给出结点扩展的顺序和每个结点的$f$、$g$ 和 $h$ 值。 55 | 56 | \paragraph{解} 57 | Romania 问题中到 Bucharest 的直线距离如表所示: 58 | \begin{table}[h] 59 | \centering 60 | \begin{tabular}{lrlr} 61 | \textbf{Arad} & 366 & \textbf{Mehadia} & 241 \\ 62 | \textbf{Bucharest} & 0 & \textbf{Neamt} & 234 \\ 63 | \textbf{Craiova} & 160 & \textbf{Oradea} & 380 \\ 64 | \textbf{Drobeta} & 242 & \textbf{Pitesti} & 100 \\ 65 | \textbf{Eforie} & 161 & \textbf{Rimnicu Vilcea} & 193 \\ 66 | \textbf{Fagaras} & 176 & \textbf{Sibiu} & 253 \\ 67 | \textbf{Giurgiu} & 77 & \textbf{Timisoara} & 329 \\ 68 | \textbf{Hirsova} & 151 & \textbf{Urziceni} & 80 \\ 69 | \textbf{Iasi} & 226 & \textbf{Vaslui} & 199 \\ 70 | \textbf{Lugoj} & 244 & \textbf{Zerind} & 374 71 | \end{tabular} 72 | \caption{$h_{SLD}$的值——到 Bucharest 的直线距离} 73 | \end{table} 74 | 75 | 使用直线距离启发式,应用A$^*$算法,过程如下: 76 | \newgeometry{left = 1cm, right = 1cm, top = 0cm, bottom = 0.5cm} 77 | \begin{figure} 78 | \centering 79 | 80 | \subfigure 81 | { 82 | \begin{tikzpicture}[scale = 0.45] 83 | \node [normal] (L) {Lugoj}; 84 | 85 | \node [length, below = 0.2em of L] (dL) {$244 = 0 + 244$}; 86 | \end{tikzpicture} 87 | } 88 | 89 | \subfigure 90 | { 91 | \begin{tikzpicture}[scale = 0.45] 92 | \node [expand] (L) {Lugoj} 93 | child {node [normal] (M) {Mehadia}} 94 | child {node [normal] (T) {Timisoara}}; 95 | 96 | \node [length, below = 0.2em of M] (dM) {$311 = 70 + 241$}; 97 | \node [length, below = 0.2em of T] (dT) {$440 = 111 + 329$}; 98 | \end{tikzpicture} 99 | } 100 | 101 | \subfigure 102 | { 103 | \begin{tikzpicture}[scale = 0.45] 104 | \node [normal] (L) {Lugoj} 105 | child {node [expand] (M) {Mehadia} 106 | child {node [normal] (L2) {Lugoj}} 107 | child {node [normal] (D) {Drobeta}} 108 | } 109 | child {node [normal] (T) {Timisoara}}; 110 | 111 | \node [length, below = 0.2em of L2] (dL) {$384 = 140 + 244$}; 112 | \node [length, below = 0.2em of D] (dD) {$387 = 145 + 242$}; 113 | \node [length, below = 0.2em of T] (dT) {$440 = 111 + 329$}; 114 | \end{tikzpicture} 115 | } 116 | 117 | \subfigure 118 | { 119 | \begin{tikzpicture}[scale = 0.45] 120 | \node [normal] (L) {Lugoj} 121 | child {node [normal] (M) {Mehadia} 122 | child {node [expand] (L2) {Lugoj} 123 | child {node [normal] (M2) {Mehadia}} 124 | child {node [normal] (T2) {Timisoara}} 125 | } 126 | child {node [normal] (D) {Drobeta}} 127 | } 128 | child {node [normal] (T) {Timisoara}}; 129 | 130 | \node [length, below = 0.2em of M2] (dM2) {$451 = 210 + 241$}; 131 | \node [length, below = 0.2em of T2] (dT2) {$580 = 251 + 329$}; 132 | \node [length, below = 0.2em of D] (dD) {$387 = 145 + 242$}; 133 | \node [length, below = 0.2em of T] (dT) {$440 = 111 + 329$}; 134 | \end{tikzpicture} 135 | } 136 | 137 | \subfigure 138 | { 139 | \begin{tikzpicture}[scale = 0.45] 140 | \node [normal] (L) {Lugoj} 141 | child {node [normal] (M) {Mehadia} 142 | child {node [expand] (L2) {Lugoj} 143 | child {node [normal] (M2) {Mehadia}} 144 | child {node [normal] (T2) {Timisoara}} 145 | } 146 | child {node [normal] (D) {Drobeta}} 147 | } 148 | child {node [normal] (T) {Timisoara}}; 149 | 150 | \node [length, below = 0.2em of M2] (dM2) {$451 = 210 + 241$}; 151 | \node [length, below = 0.2em of T2] (dT2) {$580 = 251 + 329$}; 152 | \node [length, below = 0.2em of D] (dD) {$387 = 145 + 242$}; 153 | \node [length, below = 0.2em of T] (dT) {$440 = 111 + 329$}; 154 | \end{tikzpicture} 155 | } 156 | 157 | \subfigure 158 | { 159 | \begin{tikzpicture}[scale = 0.45] 160 | \node [normal] (L) {Lugoj} 161 | child {node [normal] (M) {Mehadia} 162 | child {node [normal] (L2) {Lugoj} 163 | child {node [normal] (M2) {Mehadia}} 164 | child {node [normal] (T2) {Timisoara}} 165 | } 166 | child {node [expand] (D) {Drobeta} 167 | child {node [normal] (C) {Craiova}} 168 | child {node [normal] (M3) {Mehadia}} 169 | } 170 | } 171 | child {node [normal] (T) {Timisoara}}; 172 | 173 | \node [length, below = 0.2em of M2] (dM2) {$451 = 210 + 241$}; 174 | \node [length, below = 0.2em of T2] (dT2) {$580 = 251 + 329$}; 175 | \node [length, below = 0.2em of M3] (dM3) {$461 = 220 + 241$}; 176 | \node [length, below = 0.2em of C] (dC) {$425 = 265 + 160$}; 177 | \node [length, below = 0.2em of T] (dT) {$440 = 111 + 329$}; 178 | \end{tikzpicture} 179 | } 180 | 181 | \subfigure 182 | { 183 | \begin{tikzpicture}[scale = 0.45] 184 | \node [normal] (L) {Lugoj} 185 | child {node [normal] (M) {Mehadia} 186 | child {node [normal] (L2) {Lugoj} 187 | child {node [normal] (M2) {Mehadia}} 188 | child {node [normal] (T2) {Timisoara}} 189 | } 190 | child {node [normal] (D) {Drobeta} 191 | child {node [expand] (C) {Craiova} 192 | child {node [normal] (P) {Pitesti}} 193 | child {node [normal] (R) {Rimnicu}} 194 | child {node [normal] (D2) {Drobeta}} 195 | } 196 | child {node [normal] (M3) {Mehadia}} 197 | } 198 | } 199 | child {node [normal] (T) {Timisoara}}; 200 | 201 | \node [length, below = 0.2em of M2] (dM2) {$451 = 210 + 241$}; 202 | \node [length, below = 0.2em of T2] (dT2) {$580 = 251 + 329$}; 203 | \node [length, below = 0.2em of M3] (dM3) {$461 = 220 + 241$}; 204 | \node [length, below = 0.2em of P] (dP) {$503 = 403 + 100$}; 205 | \node [length, below = 0.2em of R] (dR) {$604 = 411 + 193$}; 206 | \node [length, below = 0.2em of D2] (dD2) {$627 = 385 + 242$}; 207 | \node [length, below = 0.2em of T] (dT) {$440 = 111 + 329$}; 208 | \end{tikzpicture} 209 | } 210 | \caption{使用A$^*$搜索应用直线距离启发式求解从 Lugoj 到 Bucharest 问题} 211 | \label{figure:1} 212 | \end{figure} 213 | 214 | \begin{figure}[h] 215 | \centering 216 | \subfigure 217 | { 218 | \begin{tikzpicture}[scale = 0.45] 219 | \node [normal] (L) {Lugoj} 220 | child {node [normal] (M) {Mehadia} 221 | child {node [normal] (L2) {Lugoj} 222 | child {node [normal] (M2) {Mehadia}} 223 | child {node [normal] (T2) {Timisoara}} 224 | } 225 | child {node [normal] (D) {Drobeta} 226 | child {node [normal] (C) {Craiova} 227 | child {node [normal] (P) {Pitesti}} 228 | child {node [normal] (R) {Rimnicu}} 229 | child {node [normal] (D2) {Drobeta}} 230 | } 231 | child {node [normal] (M3) {Mehadia}} 232 | } 233 | } 234 | child {node [expand] (T) {Timisoara} 235 | child {node [normal] (L3) {Lugoj}} 236 | child {node [normal] (A) {Arad}} 237 | }; 238 | 239 | \node [length, below = 0.2em of M2] (dM2) {$451 = 210 + 241$}; 240 | \node [length, below = 0.2em of T2] (dT2) {$580 = 251 + 329$}; 241 | \node [length, below = 0.2em of M3] (dM3) {$461 = 220 + 241$}; 242 | \node [length, below = 0.2em of P] (dP) {$503 = 403 + 100$}; 243 | \node [length, below = 0.2em of R] (dR) {$604 = 411 + 193$}; 244 | \node [length, below = 0.2em of D2] (dD2) {$627 = 385 + 242$}; 245 | \node [length, below = 0.2em of L3] (dL3) {$466 = 222 + 244$}; 246 | \node [length, below = 0.2em of A] (dA) {$595 = 229 + 366$}; 247 | \end{tikzpicture} 248 | } 249 | 250 | \subfigure 251 | { 252 | \begin{tikzpicture}[scale = 0.45] 253 | \node [normal] (L) {Lugoj} 254 | child {node [normal] (M) {Mehadia} 255 | child {node [normal] (L2) {Lugoj} 256 | child {node [expand] (M2) {Mehadia} 257 | child {node [normal] (L4) {Lugoj}} 258 | child {node [normal] (D3) {Drobeta}} 259 | } 260 | child {node [normal] (T2) {Timisoara}} 261 | } 262 | child {node [normal] (D) {Drobeta} 263 | child {node [normal] (C) {Craiova} 264 | child {node [normal] (P) {Pitesti}} 265 | child {node [normal] (R) {Rimnicu}} 266 | child {node [normal] (D2) {Drobeta}} 267 | } 268 | child {node [normal] (M3) {Mehadia}} 269 | } 270 | } 271 | child {node [normal] (T) {Timisoara} 272 | child {node [normal] (L3) {Lugoj}} 273 | child {node [normal] (A) {Arad}} 274 | }; 275 | 276 | \node [length, below = 0.2em of L4] (dL4) {$524 = 280 + 244$}; 277 | \node [length, below = 0.2em of D3] (dD3) {$527 = 285 + 242$}; 278 | \node [length, below = 0.2em of T2] (dT2) {$580 = 251 + 329$}; 279 | \node [length, below = 0.2em of M3] (dM3) {$461 = 220 + 241$}; 280 | \node [length, below = 0.2em of P] (dP) {$503 = 403 + 100$}; 281 | \node [length, below = 0.2em of R] (dR) {$604 = 411 + 193$}; 282 | \node [length, below = 0.2em of D2] (dD2) {$627 = 385 + 242$}; 283 | \node [length, below = 0.2em of L3] (dL3) {$466 = 222 + 244$}; 284 | \node [length, below = 0.2em of A] (dA) {$595 = 229 + 366$}; 285 | \end{tikzpicture} 286 | } 287 | 288 | \subfigure 289 | { 290 | \begin{tikzpicture}[scale = 0.45] 291 | \node [normal] (L) {Lugoj} 292 | child {node [normal] (M) {Mehadia} 293 | child {node [normal] (L2) {Lugoj} 294 | child {node [normal] (M2) {Mehadia} 295 | child {node [normal] (L4) {Lugoj}} 296 | child {node [normal] (D3) {Drobeta}} 297 | } 298 | child {node [normal] (T2) {Timisoara}} 299 | } 300 | child {node [normal] (D) {Drobeta} 301 | child {node [normal] (C) {Craiova} 302 | child {node [normal] (P) {Pitesti}} 303 | child {node [normal] (R) {Rimnicu}} 304 | child {node [normal] (D2) {Drobeta}} 305 | } 306 | child {node [expand] (M3) {Mehadia} 307 | child {node [normal] (L5) {Lugoj}} 308 | child {node [normal] (D4) {Drobeta}} 309 | } 310 | } 311 | } 312 | child {node [normal] (T) {Timisoara} 313 | child {node [normal] (L3) {Lugoj}} 314 | child {node [normal] (A) {Arad}} 315 | }; 316 | 317 | \node [length, below = 0.2em of L4] (dL4) {$524 = 280 + 244$}; 318 | \node [length, below = 0.2em of D3] (dD3) {$527 = 285 + 242$}; 319 | \node [length, below = 0.2em of T2] (dT2) {$580 = 251 + 329$}; 320 | \node [length, below = 0.2em of L5] (dL5) {$534 = 290 + 244$}; 321 | \node [length, below = 0.2em of D4] (dD4) {$537 = 295 + 242$}; 322 | \node [length, below = 0.2em of P] (dP) {$503 = 403 + 100$}; 323 | \node [length, below = 0.2em of R] (dR) {$604 = 411 + 193$}; 324 | \node [length, below = 0.2em of D2] (dD2) {$627 = 385 + 242$}; 325 | \node [length, below = 0.2em of L3] (dL3) {$466 = 222 + 244$}; 326 | \node [length, below = 0.2em of A] (dA) {$595 = 229 + 366$}; 327 | \end{tikzpicture} 328 | } 329 | 330 | \subfigure 331 | { 332 | \begin{tikzpicture}[scale = 0.45] 333 | \node [normal] (L) {Lugoj} 334 | child {node [normal] (M) {Mehadia} 335 | child {node [normal] (L2) {Lugoj} 336 | child {node [normal] (M2) {Mehadia} 337 | child {node [normal] (L4) {Lugoj}} 338 | child {node [normal] (D3) {Drobeta}} 339 | } 340 | child {node [normal] (T2) {Timisoara}} 341 | } 342 | child {node [normal] (D) {Drobeta} 343 | child {node [normal] (C) {Craiova} 344 | child {node [normal] (P) {Pitesti}} 345 | child {node [normal] (R) {Rimnicu}} 346 | child {node [normal] (D2) {Drobeta}} 347 | } 348 | child {node [normal] (M3) {Mehadia} 349 | child {node [normal] (L5) {Lugoj}} 350 | child {node [normal] (D4) {Drobeta}} 351 | } 352 | } 353 | } 354 | child {node [normal] (T) {Timisoara} 355 | child {node [expand] (L3) {Lugoj} 356 | child {node [normal] (M4) {Mehadia}} 357 | child {node [normal] (T3) {Timisoara}} 358 | } 359 | child {node [normal] (A) {Arad}} 360 | }; 361 | 362 | \node [length, below = 0.2em of L4] (dL4) {$524 = 280 + 244$}; 363 | \node [length, below = 0.2em of D3] (dD3) {$527 = 285 + 242$}; 364 | \node [length, below = 0.2em of T2] (dT2) {$580 = 251 + 329$}; 365 | \node [length, below = 0.2em of L5] (dL5) {$534 = 290 + 244$}; 366 | \node [length, below = 0.2em of D4] (dD4) {$537 = 295 + 242$}; 367 | \node [length, below = 0.2em of P] (dP) {$503 = 403 + 100$}; 368 | \node [length, below = 0.2em of R] (dR) {$604 = 411 + 193$}; 369 | \node [length, below = 0.2em of D2] (dD2) {$627 = 385 + 242$}; 370 | \node [length, below = 0.2em of M4] (dM4) {$533 = 292 + 241$}; 371 | \node [length, below = 0.2em of T3] (dT3) {$662 = 333 + 329$}; 372 | \node [length, below = 0.2em of A] (dA) {$595 = 229 + 366$}; 373 | \end{tikzpicture} 374 | } 375 | 376 | \subfigure 377 | { 378 | \begin{tikzpicture}[scale = 0.45] 379 | \node [normal] (L) {Lugoj} 380 | child {node [normal] (M) {Mehadia} 381 | child {node [normal] (L2) {Lugoj} 382 | child {node [normal] (M2) {Mehadia} 383 | child {node [normal] (L4) {Lugoj}} 384 | child {node [normal] (D3) {Drobeta}} 385 | } 386 | child {node [normal] (T2) {Timisoara}} 387 | } 388 | child {node [normal] (D) {Drobeta} 389 | child {node [normal] (C) {Craiova} 390 | child {node [normal] (P) {Pitesti} 391 | child {node [normal] (B) {Bucharest}} 392 | child {node [normal] (R2) {Rimnicu}} 393 | child {node [normal] (C2) {Craiova}} 394 | } 395 | child {node [normal] (R) {Rimnicu}} 396 | child {node [normal] (D2) {Drobeta}} 397 | } 398 | child {node [normal] (M3) {Mehadia} 399 | child {node [normal] (L5) {Lugoj}} 400 | child {node [normal] (D4) {Drobeta}} 401 | } 402 | } 403 | } 404 | child {node [normal] (T) {Timisoara} 405 | child {node [expand] (L3) {Lugoj} 406 | child {node [normal] (M4) {Mehadia}} 407 | child {node [normal] (T3) {Timisoara}} 408 | } 409 | child {node [normal] (A) {Arad}} 410 | }; 411 | 412 | \node [length, below = 0.2em of L4] (dL4) {$524 = 280 + 244$}; 413 | \node [length, below = 0.2em of D3] (dD3) {$527 = 285 + 242$}; 414 | \node [length, below = 0.2em of T2] (dT2) {$580 = 251 + 329$}; 415 | \node [length, below = 0.2em of L5] (dL5) {$534 = 290 + 244$}; 416 | \node [length, below = 0.2em of D4] (dD4) {$537 = 295 + 242$}; 417 | \node [length, below = 0.2em of B] (dB) {$504 = 0 + 504$}; 418 | \node [length, below = 0.2em of R2] (dR2) {$693 = 500 + 193$}; 419 | \node [length, below = 0.2em of C2] (dC2) {$701 = 541 + 160$}; 420 | \node [length, below = 0.2em of R] (dR) {$604 = 411 + 193$}; 421 | \node [length, below = 0.2em of D2] (dD2) {$627 = 385 + 242$}; 422 | \node [length, below = 0.2em of M4] (dM4) {$533 = 292 + 241$}; 423 | \node [length, below = 0.2em of T3] (dT3) {$662 = 333 + 329$}; 424 | \node [length, below = 0.2em of A] (dA) {$595 = 229 + 366$}; 425 | \end{tikzpicture} 426 | } 427 | \caption{使用A$^*$搜索应用直线距离启发式求解从 Lugoj 到 Bucharest 问题(续)} 428 | \label{figure:2} 429 | \end{figure} 430 | \restoregeometry 431 | 432 | \section{Exercise 3.25} 433 | \textbf{启发式路径算法}(Pohl,1977)是一种最佳优先搜索,它的评估函数是$f(n) = (2 - w)g(n) + wh(n)$,假设 $h$ 是可采纳的。$w$取什么值能保证算法是最优的?当$w = 0,\ w = 1,\ w = 2$时,分别是什么搜索算法? 434 | 435 | \paragraph{解} 436 | 由于 $h$ 是可采纳的,为了保证一致性,应有: 437 | \begin{equation*} 438 | \left\{ 439 | \begin{aligned} 440 | & 2 - w > 0 \\ 441 | & w \geqslant 0 442 | \end{aligned} 443 | \right. 444 | \end{equation*} 445 | 同时成立,即 $0 \leqslant w < 2$ 时算法是最优的。 446 | 447 | 当$w = 0$时,$f(n) = 2g(n)$,算法退化为(带有常系数的)一致代价搜索;当$w = 1$时,$f(n) = g(n) + h(n)$,算法即A$^*$搜索;当$w = 2$时,算法是(带有常系数的)贪婪最佳优先搜索。 448 | 449 | \section{Exercise 3.28} 450 | 设计一个启发函数,它在八数码问题中有时会估计过高,并指出对某一特定问题它会求出次优解(可以用计算机编程找出)。证明:如果$h$被高估的部分不超过$c$,A$^*$算法返回的解代价比最优解代价多出的部分也不超过$c$。 451 | 452 | \paragraph{解} 453 | 启发式函数为不在位的棋子数与所有棋子到其目标位置的曼哈顿距离和之和,即$h = h_1 + h_2$。对于如图\ref{figure:2}的状态 454 | \begin{figure}[h] 455 | \centering 456 | \begin{tikzpicture}[scale=.5] 457 | \begin{scope} 458 | \draw[very thick] (0, 0) grid (3, 3); 459 | \setcounter{row}{1} 460 | \setrow {1}{ }{2} 461 | \setrow {3}{4}{5} 462 | \setrow {6}{7}{8} 463 | \end{scope} 464 | \end{tikzpicture} 465 | \label{figure:2} 466 | \caption{一个在八数码问题中估计过高的实例} 467 | \end{figure} 468 | 其启发式函数为$h = 1 + 1 = 2$,高于其实际的解代价1。 469 | \begin{proof} 470 | 设$h$被高估的部分不超过$c$,即$h(n) \leqslant h^*(n) + c$,则对于最优解路径上的任意结点$n$,有 471 | \begin{align*} 472 | f(n) = & g(n) + h(n) \\ 473 | \leqslant & g(n) + h^*(n) + c \\ 474 | \leqslant & C^* + c 475 | \end{align*} 476 | 即A$^*$算法返回的解代价比最优解代价多出的部分也不超过$c$。 477 | \end{proof} 478 | 479 | \section{Exercise 3.29} 480 | 证明如果启发式是一致的,它一定是可采纳的。构造一个非一致的可采纳启发式。 481 | 482 | \paragraph{解} 483 | 设启发式$h(n)$是一致的,即对于每个结点$n$和通过任一行动$a$生成的$n$的每个后继结点$n'$,从结点$n$到达目标的估计代价不大于从$n$到$n'$的单步代价与从$n'$到达目标的估计代价之和:$$h(n) \leqslant c(n,\, a,\, n') + h(n')$$ 484 | \begin{proof} 485 | 对从$n$到任何目标的最短路径上的结点数$k$进行归纳: 486 | 487 | 当$k = 1$时,取目标结点即$n'$,则$h(n) \leqslant c(n,\, a,\, n') + h(n')$成立。 488 | 489 | 当$k \leqslant 1$时,假设$h(n')$是可采纳的,则有 490 | \begin{equation*} 491 | h(n) \leqslant c(n,\, a,\, n') + h(n') \leqslant c(n,\, a,\, n') + h^*(n') = h^*(n) 492 | \end{equation*} 493 | 即$h(n)$对$k + 1$仍是可采纳的。 494 | 495 | 综上,$h(n)$是可采纳的。 496 | \end{proof} 497 | 在 Romania 问题中,如果使用到达 Bucharest 的最少经过一个中间结点的路径距离减去到达后继结点的最大直线距离作为启发式,这个启发式是非一致的,它并不满足三角不等式,但它仍不会给出过高的估计,因此是可采纳的。 498 | 499 | \section{Exercise 6.5} 500 | 使用带前向检验、MRV和最少约束值启发式的回溯算法手动求解图中的密码算术问题 501 | \begin{figure}[h] 502 | { 503 | \centering 504 | \subfigure[]{ 505 | \includegraphics[]{Figure6-2(a).png} 506 | } 507 | \subfigure[]{ 508 | \includegraphics[]{Figure6-2(b).png} 509 | } 510 | \caption{} 511 | } 512 | (a) 密码算术问题。不同字母表示不同的数字;目标是找到能够使加法算式成立的代替字母的数字,附加约束是最前面的数字不能是0。 (b) 密码算术的约束超图,给出的是 \textit{Alldiff} 约束(最上方的方框)和每列的相加约束(中间的四个方框)。变量$C_1$、$C_2$、$C_3$表示每列进位 513 | \end{figure} 514 | 515 | \paragraph{解} 516 | 手动求解过程如下: 517 | \begin{enumerate}[i] 518 | \item 选择变量$C_3$,其表示进位,因此有$C_3 \in \{0,\, 1\}$ 519 | \item 取$C_3 = 1$,由前向检验限制,附加约束是最前面的数字不能是0,因此$F$不能取0,故$C_3$不能取0 520 | \item 选择变量$F$,其只有一个可能的值 521 | \item 取$F = 1$ 522 | \item 选择变量$C_2$,其有两个可能的值 523 | \item 取$C_2 = 0$ 524 | \item 选择变量$X_1$,其现在只有一个可能的值 525 | \item 取$C_1 = 0$ 526 | \item 选择变量$O$,由于$O + O = R + 10 \times C_1 = R \leqslant 9$,且$T + T = O + 10 \times F = O + 10$,因此$O$是小于5的偶数,这是最严格的约束 527 | \item 取$O = 4$ 528 | \item 选择变量$R$,其现在只有一个可能的值 529 | \item 取$R = 8$ 530 | \item 选择变量$T$,其现在只有一个可能的值 531 | \item 取$T = 7$ 532 | \item 选择变量$U$,由于$W + W = U + 10 \times C_2 = U \leqslant 9$,因此$U$是小于9的偶数 533 | \item 取$U = 6$,由前向检验限制,不同的字母表示不同的数字,因此$U$不能取$4$或$8$ 534 | \item 选择变量$W$,其现在只有一个可能的值 535 | \item 取$W = 3$ 536 | \item 得到一个解:$F = 1,\ T = 7,\ U = 6,\ W = 3,\ R = 8,\ O = 4$ 537 | \end{enumerate} 538 | 539 | \section{Exercise 6.11} 540 | 用 AC-3 算法说明弧相容对图中问题能够检测出部分赋值$\{WA = red,\ V = blue\}$的不相容 541 | \begin{figure}[h] 542 | { 543 | \centering 544 | \subfigure[]{ 545 | \includegraphics[scale = 0.6]{Figure6-1(a).png} 546 | } 547 | \subfigure[]{ 548 | \includegraphics[scale = 0.6]{Figure6-1(b).png} 549 | } 550 | \caption{着色问题} 551 | } 552 | (a) 澳大利亚的洲和行政区。视此地图着色问题为约束满足问题(CSP)。目标是对每个区域分配颜色,使得相邻的区域不同色。 (b) 将地图着色问题表示成约束图 553 | \end{figure} 554 | 555 | \paragraph{解} 556 | 以下列出了 AC-3 算法的执行过程: 557 | \begin{enumerate}[i] 558 | \item 删除边\textit{SA}-\textit{WA},从\textit{SA}的值域中删除\textit{green},剩余\{\textit{red}, \textit{blue}\} 559 | \item 删除边\textit{SA}-\textit{V},从\textit{SA}的值域中删除\textit{red},剩余\{\textit{blue}\} 560 | \item 删除边\textit{NT}-\textit{WA},从\textit{NT}的值域中删除\textit{green},剩余\{\textit{red}, \textit{blue}\} 561 | \item 删除边\textit{NT}-\textit{SA},从\textit{NT}的值域中删除\textit{blue},剩余\{\textit{red}\} 562 | \item 删除边\textit{NSW}-\textit{SA},从\textit{NSW}的值域中删除\textit{blue},剩余\{\textit{red}, \textit{green}\} 563 | \item 删除边\textit{NSW}-\textit{V},从\textit{NSW}的值域中删除\textit{green},剩余\{\textit{green}\} 564 | \item 删除边\textit{Q}-\textit{NT},从\textit{Q}的值域中删除\textit{red},剩余\{\textit{blue}, \textit{green}\} 565 | \item 删除边\textit{Q}-\textit{SA},从\textit{Q}的值域中删除\textit{blue},剩余\{\textit{green}\} 566 | \item 删除边\textit{Q}-\textit{NSW},从\textit{Q}的值域中删除\textit{green},剩余$\varnothing$,返回\texttt{false} 567 | \end{enumerate} 568 | 因此部分赋值$\{WA = red,\ V = blue\}$不相容。 569 | 570 | \section{Exercise 6.12} 571 | 用 AC-3 算法求解树结构 CSP 在最坏情况下的复杂度是多少? 572 | 573 | \paragraph{解} 574 | 在树结构 CSP 中,最坏情况下,考虑每一条弧各一次,因此算法的复杂度是$O(ED)$,其中$E$是树结构中边的数量,$D$是最大的域的大小 575 | \end{document} -------------------------------------------------------------------------------- /Homework3/Figure5-17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyc0930/AI-Homework/81cc1ab4c2b3cedc1df2cf2ae56b02232aa47563/Homework3/Figure5-17.png -------------------------------------------------------------------------------- /Homework3/Figure5-18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyc0930/AI-Homework/81cc1ab4c2b3cedc1df2cf2ae56b02232aa47563/Homework3/Figure5-18.png -------------------------------------------------------------------------------- /Homework3/PB17000297_罗晏宸.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyc0930/AI-Homework/81cc1ab4c2b3cedc1df2cf2ae56b02232aa47563/Homework3/PB17000297_罗晏宸.pdf -------------------------------------------------------------------------------- /Homework3/PB17000297_罗晏宸.tex: -------------------------------------------------------------------------------- 1 | \documentclass{article} 2 | \usepackage[UTF8]{ctex} 3 | \usepackage[T1]{fontenc} 4 | \usepackage[utf8]{inputenc} 5 | \usepackage{titlesec} 6 | \usepackage[colorlinks, linkcolor = black]{hyperref} 7 | \usepackage{float} 8 | \usepackage{xcolor} 9 | \usepackage{tikz} 10 | \usepackage{amsmath} 11 | \usepackage{subfigure} 12 | \usetikzlibrary{positioning} 13 | \usetikzlibrary[arrows, shapes, chains] 14 | \newcounter{row} 15 | \newcounter{col} 16 | 17 | \newcommand\setrow[3]{ 18 | \setcounter{col}{1} 19 | \foreach \n in {#1, #2, #3} { 20 | \edef\x{\value{col} - 0.5} 21 | \edef\y{3.5 - \value{row}} 22 | \node[anchor = center] at (\x, \y) {\n}; 23 | \stepcounter{col} 24 | } 25 | \stepcounter{row} 26 | } 27 | \titleformat{\section}[block]{\LARGE\scshape}{\arabic{section}}{1em}{}[] 28 | 29 | \tikzset{ 30 | state/.style = {text ragged}, 31 | terminal/.style = {rectangle, draw = black, text ragged}, 32 | loop/.style = {rectangle, draw = black, double, text ragged}, 33 | value/.style = {circle, draw = black, text ragged, minimum width = 2em, scale = 0.7}, 34 | level distance = 3em 35 | } 36 | 37 | \title{Homework 3} 38 | \author{PB17000297 罗晏宸} 39 | \date{March 16 2020} 40 | 41 | \begin{document} 42 | \maketitle 43 | 44 | \section{Exercise 5.8} 45 | 考虑图\ref{figure5.17}中描述的两人游戏。 46 | \begin{figure}[h] 47 | { 48 | \centering 49 | \includegraphics[]{Figure5-17.png} 50 | \caption{一个简单游戏的初始棋局} 51 | \label{figure5.17} 52 | } 53 | 选手\textit{A}先走。两个选手轮流走棋,每个人必须把自己的棋子移动到任一方向上的相邻空位中。如果对方的棋子占据着相邻的位置,你可以跳过对方的棋子到下一个空位。(例如,\textit{A}在位置3,\textit{B}在位置2,那么\textit{A}可以移回1。)当一方的棋子移动到对方的端点时游戏结束。如果 \textit{A} 先到达位置4,\textit{A}的值为$+1$;如果\textit{B}先到达位置1,\textit{A}的值为$-1$。 54 | \end{figure} 55 | \subparagraph{a} 56 | 根据如下约定画出完整博弈树: 57 | \begin{itemize} 58 | \item 每个状态用$(s_A,\, s_B)$表示,其中$s_A$和$s_B$表示棋子的位置。 59 | \item 每个终止状态用方框画出,用圆圈写出它的博弈值。 60 | \item 把循环状态(在到根结点的路径上已经出现过的状态)画上双层方框。由于不清楚他们的值,在圆圈里标记一个“?”。 61 | \end{itemize} 62 | \subparagraph{b} 63 | 给出每个结点倒推的极小极大值(也标记在圆圈里)。解释怎样处理“?”值和为什么这么处理。 64 | \subparagraph{c} 65 | 解释标准的极小极大算法为什么在这棵博弈树中会失败,简要说明你将如何修正它,在(b)的图上画出你的答案。你修正后的算法对于所有包含循环的游戏都能给出最优决策吗? 66 | \subparagraph{d} 67 | 这个4-方格游戏可以推广到$n$个方格,其中$n > 2$。证明如果$n$是偶数\textit{A}一定能赢,而$n$是奇数则\textit{A}一定会输。 68 | 69 | \paragraph{解} 70 | \subparagraph{a} 71 | 博弈树如图\ref{figureTree}所示 72 | \begin{figure}[h] 73 | \centering 74 | \begin{tikzpicture} 75 | \node [state] (1) {$(1,\, 4)$} 76 | child {node [state] (2) {$(2,\, 4)$} 77 | child {node [state] (3) {$(2,\, 3)$} 78 | child {node [terminal] (4) {$(4,\, 3)$}} 79 | child {node [state] (5) {$(1,\, 3)$} 80 | child {node [state] (6) {$(1,\, 2)$} 81 | child {node [state] (8) {$(3,\, 2)$} 82 | child {node [terminal] (9) {$(3,\, 1)$}} 83 | child {node [state] (10) {$(3,\, 4)$} 84 | child {node [loop] (11) {$(2,\, 4)$}} 85 | } 86 | } 87 | } 88 | child {node [loop] (7) {$(1,\, 4)$}} 89 | } 90 | } 91 | }; 92 | \node [value, left = 0.1em of 1] (v1) {$+1$}; 93 | \node [value, left = 0.1em of 2] (v2) {$+1$}; 94 | \node [value, left = 0.1em of 3] (v3) {$+1$}; 95 | \node [value, left = 0.1em of 4] (v4) {$+1$}; 96 | \node [value, right = 0.1em of 5] (v5) {$-1$}; 97 | \node [value, left = 0.1em of 6] (v6) {$-1$}; 98 | \node [value, right = 0.1em of 7] (v7) {$?$}; 99 | \node [value, left = 0.1em of 8] (v8) {$-1$}; 100 | \node [value, left = 0.1em of 9] (v9) {$-1$}; 101 | \node [value, right = 0.1em of 10] (v10) {$?$}; 102 | \node [value, right = 0.1em of 11] (v11) {$?$}; 103 | \end{tikzpicture} 104 | \caption{两人游戏的博弈树} 105 | \label{figureTree} 106 | \end{figure} 107 | 108 | \subparagraph{b} 109 | 在圆圈中的博弈值后附上相应的极小与极大值,如图\ref{figureTree2}所示 110 | \begin{figure} 111 | \centering 112 | \begin{tikzpicture} 113 | \node [state] (1) {$(1,\, 4)$} 114 | child {node [state] (2) {$(2,\, 4)$} 115 | child {node [state] (3) {$(2,\, 3)$} 116 | child {node [terminal] (4) {$(4,\, 3)$}} 117 | child {node [state] (5) {$(1,\, 3)$} 118 | child {node [state] (6) {$(1,\, 2)$} 119 | child {node [state] (8) {$(3,\, 2)$} 120 | child {node [terminal] (9) {$(3,\, 1)$}} 121 | child {node [state] (10) {$(3,\, 4)$} 122 | child {node [loop] (11) {$(2,\, 4)$}} 123 | } 124 | } 125 | } 126 | child {node [loop] (7) {$(1,\, 4)$}} 127 | } 128 | } 129 | }; 130 | \node [value, scale = 0.7, left = 0.1em of 1] (v1) {$+1, +1, +1$}; 131 | \node [value, scale = 0.7, left = 0.1em of 2] (v2) {$+1, +1, +1$}; 132 | \node [value, scale = 0.7, left = 0.1em of 3] (v3) {$+1, +1, +1$}; 133 | \node [value, scale = 0.7, left = 0.1em of 4] (v4) {$+1, +1, +1$}; 134 | \node [value, scale = 0.7, right = 0.1em of 5] (v5) {$-1, -1, ?$}; 135 | \node [value, scale = 0.7, left = 0.1em of 6] (v6) {$-1, -1, -1$}; 136 | \node [value, scale = 0.7, right = 0.1em of 7] (v7) {$?, ?, ?$}; 137 | \node [value, scale = 0.7, left = 0.1em of 8] (v8) {$-1, -1, ?$}; 138 | \node [value, scale = 0.7, left = 0.1em of 9] (v9) {$-1, -1, -1$}; 139 | \node [value, scale = 0.7, right = 0.1em of 10] (v10) {$?, ?, ?$}; 140 | \node [value, scale = 0.7, right = 0.1em of 11] (v11) {$?, ?, ?$}; 141 | \end{tikzpicture} 142 | \caption{标注每个结点倒推极小极大值的博弈树} 143 | \label{figureTree2} 144 | \end{figure} 145 | 对于“?”值采取的处理办法是,如果Agent能够选择则总是会选择获胜(即博弈值为$+1$),因此除非后继结点均为“?”,可以将“?”视为介于$-1$与$+1$之间的值。 146 | \subparagraph{c} 147 | 标准的极小极大算法是深度优先的,会在遇到循环状态时陷入无限循环。一个可行的修正方式是带记录的深度优先搜索,通过维护一个队列记录已遍历的结点,如果遇到已在队列中的重复状态,就直接返回“?”,通过前述的处理方法来解决比较。答案如所示。 148 | \begin{figure}[h] 149 | \centering 150 | \begin{tikzpicture} 151 | \node [state, draw = red!70!black, red!70!black] (1) {$(1,\, 4)$} 152 | child {node [state, draw = red!70!black, red!70!black] (2) {$(2,\, 4)$} 153 | child {node [state, draw = red!70!black, red!70!black] (3) {$(2,\, 3)$} 154 | child {node [terminal] (4) {$(4,\, 3)$}} 155 | child {node [state, draw = red!70!black, red!70!black] (5) {$(1,\, 3)$} 156 | child {node [state, draw = red!70!black, red!70!black] (6) {$(1,\, 2)$} 157 | child {node [state, draw = red!70!black, red!70!black] (8) {$(3,\, 2)$} 158 | child {node [terminal] (9) {$(3,\, 1)$}} 159 | child {node [state, draw = red!70!black, red!70!black] (10) {$(3,\, 4)$} 160 | child {node [loop, draw = red!70!black, red!70!black] (11) {$(2,\, 4)$}} 161 | } 162 | } 163 | } 164 | child {node [loop] (7) {$(1,\, 4)$}} 165 | } 166 | } 167 | }; 168 | \node [value, scale = 0.7, left = 0.1em of 1] (v1) {$+1, +1, +1$}; 169 | \node [value, scale = 0.7, left = 0.1em of 2] (v2) {$+1, +1, +1$}; 170 | \node [value, scale = 0.7, left = 0.1em of 3] (v3) {$+1, +1, +1$}; 171 | \node [value, scale = 0.7, left = 0.1em of 4] (v4) {$+1, +1, +1$}; 172 | \node [value, scale = 0.7, right = 0.1em of 5] (v5) {$-1, -1, ?$}; 173 | \node [value, scale = 0.7, left = 0.1em of 6] (v6) {$-1, -1, -1$}; 174 | \node [value, scale = 0.7, right = 0.1em of 7] (v7) {$?, ?, ?$}; 175 | \node [value, scale = 0.7, left = 0.1em of 8] (v8) {$-1, -1, ?$}; 176 | \node [value, scale = 0.7, left = 0.1em of 9] (v9) {$-1, -1, -1$}; 177 | \node [value, scale = 0.7, right = 0.1em of 10] (v10) {$?, ?, ?$}; 178 | \node [value, scale = 0.7, right = 0.1em of 11] (v11) {$?, ?, ?$}; 179 | \end{tikzpicture} 180 | \caption{修正后求解两人游戏的答案} 181 | \end{figure} 182 | 修正后的算法并不能给出所有包含循环的游戏的最优决策,因为这样的处理方法不能区分不同的“?”值,在获胜情况并不唯一,或者有不同获胜程度的状态时,直接返回可能会丢失其他获胜程度较深的状态。 183 | \subparagraph{d} 184 | 当$n = 3$和$n = 4$时,\textit{A}分别输掉和赢得游戏,很显然对于$n \geq 4$的情况,\textit{A}和\textit{B}在开始都会向对方走一格,如果\textit{A}在$n - 2$的情况获胜,那么在这种情况(\textit{A}处于位置1,\textit{B}处于位置$n - 1$)下,\textit{A}将会在\textit{B}到达位置1之前到达位置$n - 1$,那么\textit{A}也将会在$n$的情况下获胜,在这种情况下\textit{A}不会向着自己的原始位置行棋;同理如果\textit{A}在$n - 2$的情况失败,意味着\textit{B}获胜,那么\textit{B}也将会在$n$的情况获胜。因此如果$n$是偶数\textit{A}一定能赢,而$n$是奇数则\textit{A}一定会输。 185 | 186 | \section{Exercise 5.9} 187 | 本题以井字棋(圈与十字游戏)为例练习博弈中的基本概念。定义$X_n$为恰好有$n$个$X$而没有$O$的行、列或者对角线的数目。同样$O_n$为正好有$n$个$O$的行、列或者对角线的数目。效用函数给$X_3 = 1$的棋局$+1$,给$O_3 = 1$的棋局$-1$。所有其他终止状态效用值为0。对于非终止状态,使用线性的评估函数定义为$\textit{Eval}(s) = 3X_2(s) + X_1(s) - (3O_2(s) + O_1(s))$。 188 | \subparagraph{a} 189 | 估算可能的井字棋局数。 190 | \subparagraph{b} 191 | 考虑对称性,给出从空棋盘开始的深度为2的完整博弈树(即,在棋盘上一个$X$一个$O$的棋局)。 192 | \subparagraph{c} 193 | 标出深度为2的棋局的评估函数值。 194 | \subparagraph{d} 195 | 使用极小极大算法标出深度为1和0的棋局的倒推值,并根据这些值选出最佳的起始行棋。 196 | \subparagraph{e} 197 | 假设结点按对$\alpha$-$\beta$剪枝的最优顺序生成,圈出使用$\alpha$-$\beta$剪枝将被剪掉的深度为2的结点。 198 | 199 | \paragraph{解} 200 | \subparagraph{a} 201 | 井字棋最多可能将棋盘的9个格子下满,最少需要双方轮流执棋两合后先手获胜,因此可能的局数在$\frac{9!}{4!}$到$9!$之间。 202 | 203 | \subparagraph{b} 204 | 完整博弈树如图\ref{figureDeep2}所示 205 | \begin{figure}[h] 206 | \centering 207 | \begin{tikzpicture}[scale = 1.3] 208 | \begin{scope}[scale = 0.2] 209 | \draw[very thick] (0, 0) grid (3, 3); 210 | \setcounter{row}{1} 211 | \setrow { }{ }{ } 212 | \setrow { }{ }{ } 213 | \setrow { }{ }{ } 214 | \end{scope} 215 | \begin{scope}[scale = 0.2, xshift = -14cm, yshift = -4cm] 216 | \draw[very thick] (0, 0) grid (3, 3); 217 | \setcounter{row}{1} 218 | \setrow {$\times$}{ }{ } 219 | \setrow { }{ }{ } 220 | \setrow { }{ }{ } 221 | \end{scope} 222 | \begin{scope}[scale = 0.2, yshift = -4cm] 223 | \draw[very thick] (0, 0) grid (3, 3); 224 | \setcounter{row}{1} 225 | \setrow { }{ }{ } 226 | \setrow { }{$\times$}{ } 227 | \setrow { }{ }{ } 228 | \end{scope} 229 | \begin{scope}[scale = 0.2, xshift = 14cm, yshift = -4cm] 230 | \draw[very thick] (0, 0) grid (3, 3); 231 | \setcounter{row}{1} 232 | \setrow { }{$\times$}{ } 233 | \setrow { }{ }{ } 234 | \setrow { }{ }{ } 235 | \end{scope} 236 | \begin{scope}[scale = 0.2, xshift = -22cm, yshift = -8cm] 237 | \draw[very thick] (0, 0) grid (3, 3); 238 | \setcounter{row}{1} 239 | \setrow {$\times$}{$\circ$}{ } 240 | \setrow { }{ }{ } 241 | \setrow { }{ }{ } 242 | \end{scope} 243 | \begin{scope}[scale = 0.2, xshift = -18cm, yshift = -8cm] 244 | \draw[very thick] (0, 0) grid (3, 3); 245 | \setcounter{row}{1} 246 | \setrow {$\times$}{ }{ } 247 | \setrow { }{$\circ$}{ } 248 | \setrow { }{ }{ } 249 | \end{scope} 250 | \begin{scope}[scale = 0.2, xshift = -14cm, yshift = -8cm] 251 | \draw[very thick] (0, 0) grid (3, 3); 252 | \setcounter{row}{1} 253 | \setrow {$\times$}{ }{$\circ$} 254 | \setrow { }{ }{ } 255 | \setrow { }{ }{ } 256 | \end{scope} 257 | \begin{scope}[scale = 0.2, xshift = -10cm, yshift = -8cm] 258 | \draw[very thick] (0, 0) grid (3, 3); 259 | \setcounter{row}{1} 260 | \setrow {$\times$}{ }{ } 261 | \setrow { }{ }{ } 262 | \setrow { }{ }{$\circ$} 263 | \end{scope} 264 | \begin{scope}[scale = 0.2, xshift = -6cm, yshift = -8cm] 265 | \draw[very thick] (0, 0) grid (3, 3); 266 | \setcounter{row}{1} 267 | \setrow {$\times$}{ }{ } 268 | \setrow { }{ }{$\circ$} 269 | \setrow { }{ }{ } 270 | \end{scope} 271 | \begin{scope}[scale = 0.2, xshift = -2cm, yshift = -8cm] 272 | \draw[very thick] (0, 0) grid (3, 3); 273 | \setcounter{row}{1} 274 | \setrow {$\circ$}{ }{ } 275 | \setrow { }{$\times$}{ } 276 | \setrow { }{ }{ } 277 | \end{scope} 278 | \begin{scope}[scale = 0.2, xshift = 2cm, yshift = -8cm] 279 | \draw[very thick] (0, 0) grid (3, 3); 280 | \setcounter{row}{1} 281 | \setrow { }{$\circ$}{ } 282 | \setrow { }{$\times$}{ } 283 | \setrow { }{ }{ } 284 | \end{scope} 285 | \begin{scope}[scale = 0.2, xshift = 6cm, yshift = -8cm] 286 | \draw[very thick] (0, 0) grid (3, 3); 287 | \setcounter{row}{1} 288 | \setrow { }{$\times$}{$\circ$} 289 | \setrow { }{ }{ } 290 | \setrow { }{ }{ } 291 | \end{scope} 292 | \begin{scope}[scale = 0.2, xshift = 10cm, yshift = -8cm] 293 | \draw[very thick] (0, 0) grid (3, 3); 294 | \setcounter{row}{1} 295 | \setrow { }{$\times$}{ } 296 | \setrow { }{$\circ$}{ } 297 | \setrow { }{ }{ } 298 | \end{scope} 299 | \begin{scope}[scale = 0.2, xshift = 14cm, yshift = -8cm] 300 | \draw[very thick] (0, 0) grid (3, 3); 301 | \setcounter{row}{1} 302 | \setrow { }{$\times$}{ } 303 | \setrow { }{ }{ } 304 | \setrow { }{$\circ$}{ } 305 | \end{scope} 306 | \begin{scope}[scale = 0.2, xshift = 18cm, yshift = -8cm] 307 | \draw[very thick] (0, 0) grid (3, 3); 308 | \setcounter{row}{1} 309 | \setrow { }{$\times$}{ } 310 | \setrow { }{ }{ } 311 | \setrow {$\circ$}{ }{ } 312 | \end{scope} 313 | \begin{scope}[scale = 0.2, xshift = 22cm, yshift = -8cm] 314 | \draw[very thick] (0, 0) grid (3, 3); 315 | \setcounter{row}{1} 316 | \setrow { }{$\times$}{ } 317 | \setrow {$\circ$}{ }{ } 318 | \setrow { }{ }{ } 319 | \end{scope} 320 | \draw [->] (0.3, 0) to (0.3, -0.2); 321 | \draw [->] (0.3, 0) to (-2.5, -0.2); 322 | \draw [->] (0.3, 0) to (3.1, -0.2); 323 | \draw [->] (-2.5, -0.8) to (-4.1, -1.0); 324 | \draw [->] (-2.5, -0.8) to (-3.3, -1.0); 325 | \draw [->] (-2.5, -0.8) to (-2.5, -1.0); 326 | \draw [->] (-2.5, -0.8) to (-1.7, -1.0); 327 | \draw [->] (-2.5, -0.8) to (-0.9, -1.0); 328 | \draw [->] (0.3, -0.8) to (-0.1, -1.0); 329 | \draw [->] (0.3, -0.8) to ( 0.7, -1.0); 330 | \draw [->] (3.1, -0.8) to ( 1.5, -1.0); 331 | \draw [->] (3.1, -0.8) to ( 2.3, -1.0); 332 | \draw [->] (3.1, -0.8) to ( 3.1, -1.0); 333 | \draw [->] (3.1, -0.8) to ( 3.9, -1.0); 334 | \draw [->] (3.1, -0.8) to ( 4.7, -1.0); 335 | 336 | \node [green!70!black] at (-4.1, -1.9) {$1$}; 337 | \node [green!70!black] at (-3.3, -1.9) {$-1$}; 338 | \node [green!70!black] at (-2.5, -1.9) {$0$}; 339 | \node [green!70!black] at (-1.7, -1.9) {$0$}; 340 | \node [green!70!black] at (-0.9, -1.9) {$1$}; 341 | \node [green!70!black] at (-0.1, -1.9) {$1$}; 342 | \node [green!70!black] at ( 0.7, -1.9) {$2$}; 343 | \node [green!70!black] at ( 1.5, -1.9) {$-1$}; 344 | \node [green!70!black] at ( 2.3, -1.9) {$-2$}; 345 | \node [green!70!black] at ( 3.1, -1.9) {$0$}; 346 | \node [green!70!black] at ( 3.9, -1.9) {$-1$}; 347 | \node [green!70!black] at ( 4.7, -1.9) {$0$}; 348 | 349 | \node [blue] at (1.0, 0.3) {$1$}; 350 | \node [blue] at (-1.8, -0.5) {$-1$}; 351 | \node [blue] at (1.0, -0.5) {$1$}; 352 | \node [blue] at (3.8, -0.5) {$-2$}; 353 | 354 | \draw (-4.1, -1.3) circle [radius = 0.4]; 355 | \draw (-2.5, -1.3) circle [radius = 0.4]; 356 | \draw (-1.7, -1.3) circle [radius = 0.4]; 357 | \draw (-0.9, -1.3) circle [radius = 0.4]; 358 | \draw ( 1.5, -1.3) circle [radius = 0.4]; 359 | \draw ( 3.1, -1.3) circle [radius = 0.4]; 360 | \draw ( 3.9, -1.3) circle [radius = 0.4]; 361 | \draw ( 4.7, -1.3) circle [radius = 0.4]; 362 | 363 | \end{tikzpicture} 364 | \caption{从空棋盘开始的深度为2的完整博弈树} 365 | \label{figureDeep2} 366 | \end{figure} 367 | 368 | \subparagraph{c} 369 | 评估函数值已在图\ref{figureDeep2}中以{\color{green!70!black} 绿色}标出 370 | 371 | \subparagraph{d} 372 | 倒推值已在图\ref{figureDeep2}中以{\color{blue} 蓝色}标出,可知最佳的起始行棋是在棋盘中央落子。 373 | 374 | \subparagraph{e} 375 | 被剪掉的结点已在图\ref{figureDeep2}中圈出。 376 | 377 | \section{Exercise 5.13} 378 | 请给出$\alpha$-$\beta$剪枝正确性的形式化证明。要做到这一点需考虑图\ref{figure5.18}。问题为是否要剪掉结点$n_j$,它是一个MAX结点,是$n_1$的一个后代。基本的思路是当且仅当$n_1$的极小极大值可以被证明独立于$n_j$的值时,会发生剪枝。 379 | \begin{figure}[h] 380 | { 381 | \centering 382 | \includegraphics[]{Figure5-18.png} 383 | \caption{是否剪掉结点$n_j$时的情形} 384 | \label{figure5.18} 385 | } 386 | \end{figure} 387 | \subparagraph{a} 388 | $n_1$的值时所有后代结点的最小值:$n_1 = \min(n_2,\, n_{2\,1},\, \cdots,\, n_{2\,b_2})$。请为$n_2$找到类似的表达式,以得到用$n_j$表示的$n_1$的表达式。 389 | \subparagraph{b} 390 | 深度为$i$的结点$n_i$的极小极大值已知,$l_i$是在结点$n_i$左侧结点的极小值(或者极大值)。同样,$r_i$是在$n_i$右侧的未探索过的结点的极小值(或者极大值)。用$l_i$和$r_i$的值重写$n_1$的表达式。 391 | \subparagraph{c} 392 | 现在重新形式化表达式,来说明为了向$n_1$施加影响,$n_j$不能超出有$l_i$值得到的某特定界限。 393 | \subparagraph{d} 394 | 假设$n_j$是MIN结点的情况,请重复上面的过程。 395 | 396 | \paragraph{解} 397 | \subparagraph{a} 398 | 类似的,有$n_2 = \max(n_3,\, n_{3\,1},\, \cdots,\, n_{3\,b_3})$,得到 399 | \begin{equation*} 400 | n_1 = \min(\max( \cdots \max(n_j,\, n_{j\,1},\, \cdots,\, n_{j\,b_j})),\, n_{2\,1},\, \cdots,\, n_{2\,b_2}) 401 | \end{equation*} 402 | 403 | \subparagraph{b} 404 | 改写$n_1$如下 405 | \begin{align*} 406 | n_1 &= \min(l_2,\, n_2,\, r_2) \\ 407 | &= \min(l_2,\, \max(l_3,\, n_3,\, r_3),\, r_2) \\ 408 | &\vdots \\ 409 | &= \min(l_2,\, \max(l_3,\, \max( \cdots \max(l_j,\, n_j,\, r_j),\, \cdots),\, r_3),\, r_2) 410 | \end{align*} 411 | 412 | \subparagraph{c} 413 | 由前述可知 414 | \begin{equation*} 415 | n_i = \min(l_{i + 1},\, \max(l_{i + 2},\, \max( \cdots \max(l_j,\, n_j,\, r_j),\, \cdots),\, r_{i + 2}),\, r_{i + 1}) 416 | \end{equation*} 417 | 由于$n_j$是一个MAX结点,为了向$n_1$施加影响,$n_j$不能超出$\min(l_2,\, l_4,\, \cdots,\, l_j)$。 418 | 419 | \subparagraph{d} 420 | 假设$n_j$是MIN结点,只需要交换前述中的$\max$与$\min$即可。 421 | \end{document} -------------------------------------------------------------------------------- /Homework4/PB17000297_罗晏宸.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyc0930/AI-Homework/81cc1ab4c2b3cedc1df2cf2ae56b02232aa47563/Homework4/PB17000297_罗晏宸.pdf -------------------------------------------------------------------------------- /Homework4/PB17000297_罗晏宸.tex: -------------------------------------------------------------------------------- 1 | \documentclass{article} 2 | \usepackage[UTF8]{ctex} 3 | \usepackage[T1]{fontenc} 4 | \usepackage[utf8]{inputenc} 5 | \usepackage{titlesec} 6 | \usepackage[colorlinks, linkcolor = black]{hyperref} 7 | \usepackage{float} 8 | \usepackage{xcolor} 9 | \usepackage{amsmath} 10 | \usepackage{amssymb} 11 | \usepackage{latexsym} 12 | \usepackage{amsthm} 13 | \usepackage{graphicx} 14 | 15 | \titleformat{\section}[block]{\LARGE\scshape}{\arabic{section}}{1em}{}[] 16 | 17 | \title{Homework 4} 18 | \author{PB17000297 罗晏宸} 19 | \date{March 22 2020} 20 | 21 | \begin{document} 22 | \maketitle 23 | 24 | \section{Exercise 7.13} 25 | 本题考虑子句和蕴涵语句之间的关系。 26 | \subparagraph{a} 27 | 证明子句$(\lnot P_1 \lor \cdots \lor \lnot P_m \lor Q)$逻辑等价于蕴涵语句$(P_1 \land \cdots \land P_m) \Rightarrow Q$。 28 | \subparagraph{b} 29 | 证明每个子句(不管正文字的数量)都可以写成$(P_1 \land \cdots \land P_m) \Rightarrow (Q_1 \lor \cdots \lor Q_n)$的形式,其中$P_i$和$Q_i$都是命题词。由这类语句构成的知识库是表示为\textbf{蕴涵范式}或称\textbf{Kowalski 范式}(Kowalski, 1979)。 30 | \subparagraph{c} 31 | 写出蕴涵范式语句的完整归结规则。 32 | 33 | \paragraph{解} 34 | \subparagraph{a} 35 | \begin{proof} 36 | 由De Morgan律,有 37 | \begin{equation*} 38 | (\lnot P_1 \lor \cdots \lor \lnot P_m \lor Q) \equiv (\lnot (P_1 \land \cdots \land P_m) \lor Q) 39 | \end{equation*} 40 | 由蕴涵消去,有 41 | \begin{equation*} 42 | (\lnot (P_1 \land \cdots \land P_m) \lor Q) \equiv ((P_1 \land \cdots \land P_m) \Rightarrow Q) 43 | \end{equation*} 44 | \end{proof} 45 | 46 | \subparagraph{b} 47 | \begin{proof} 48 | 对于一个子句,假设其中有$n$个正文字,分别为$Q_1,\, Q_2,\, \cdots,\, Q_n$,有$m$个负文字,分别为$\lnot P_1,\, \lnot P_2,\, \cdots,\, \lnot P_m$,则这个子句可以表示为$$\lnot P_1 \lor \cdots \lor \lnot P_m \lor Q_1 \lor \cdots \lor Q_n$$,由上可知 49 | \begin{equation*} 50 | (\lnot P_1 \lor \cdots \lor \lnot P_m \lor Q_1 \lor \cdots \lor Q_n) \equiv ((P_1 \land \cdots \land P_m) \Rightarrow (Q_1 \lor \cdots \lor Q_n)) 51 | \end{equation*} 52 | \end{proof} 53 | 54 | \subparagraph{c} 55 | 应用于蕴涵范式的全归结规则如下: 56 | \begin{equation*} 57 | \resizebox{\linewidth}{!}{% 58 | $\displaystyle \frac{(p_1 \land \cdots \land p_m) \Rightarrow (q_1 \lor \cdots \lor q_n), \qquad (r_1 \land \cdots \land r_l) \Rightarrow (s_1 \lor \cdots \lor s_k)}{(p_1 \land \cdots \land p_{i - 1} \land p_{i + 1} \land \cdots \land p_m \land r_1 \land \cdots \land r_l) \Rightarrow (q_1 \lor \cdots \lor q_n \lor s_1 \lor \cdots \lor s_{j - 1} \lor s_{j + 1} \lor \cdots \lor s_k)}$ 59 | } 60 | \end{equation*} 61 | 其中每一个$p$,$q$,$r$,$s$都是文字,且$p_i = s_j$。 62 | \section{Supplementary Exercise} 63 | 证明Forward Chaining algorithm的完备性 64 | 65 | \paragraph{解} 66 | \begin{proof} 67 | 前向链接是完备的即每个被蕴涵的原子语句都可以推导得出。考察\textit{inferred}表的最终状态(在算法到达不动点以后,不会再出现新的推理)。该表把推导出的每个符号设为\textit{true},而其他符号为\textit{false}。可以把此表看作一个逻辑模型;而且,原始\textit{KB}中的每个限定子句在该模型中都为真。假设相反的情况成立,即某个子句$a_1 \land \cdots \land a_k \Rightarrow b$在此模型下为假。那么$a_1 \land \cdots \land a_k$在模型中必须为真,$b$必须为假。但这与算法已到达一个不动点的假设矛盾。因此在不动点推导出的原子语句集定义了原始\textit{KB}的一个模型。更进一步,被\textit{KB}蕴涵的任一原子语句$q$在它的所有模型中为真,尤其是这个模型。因此每个被蕴涵的语句$q$都可以被算法推导得出。 68 | \end{proof} 69 | 70 | \end{document} -------------------------------------------------------------------------------- /Homework5/PB17000297_罗晏宸.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyc0930/AI-Homework/81cc1ab4c2b3cedc1df2cf2ae56b02232aa47563/Homework5/PB17000297_罗晏宸.pdf -------------------------------------------------------------------------------- /Homework5/PB17000297_罗晏宸.tex: -------------------------------------------------------------------------------- 1 | \documentclass{article} 2 | \usepackage[UTF8]{ctex} 3 | \usepackage[T1]{fontenc} 4 | \usepackage[utf8]{inputenc} 5 | \usepackage{titlesec} 6 | \usepackage[colorlinks, linkcolor = black]{hyperref} 7 | \usepackage{float} 8 | \usepackage{xcolor} 9 | \usepackage{amsmath} 10 | \usepackage{amssymb} 11 | \usepackage{latexsym} 12 | \usepackage{amsthm} 13 | \usepackage{graphicx} 14 | \usepackage{enumerate} 15 | \usepackage{enumitem} 16 | \usepackage{tikz} 17 | \usetikzlibrary{positioning} 18 | \usetikzlibrary[arrows, shapes, chains] 19 | 20 | \setlist{ 21 | leftmargin = .1\linewidth, 22 | % rightmargin = .1\linewidth, 23 | % label=\emph{\alph*}. 24 | } 25 | 26 | \titleformat{\section}[block]{\LARGE\scshape}{\arabic{section}}{1em}{}[] 27 | 28 | \title{Homework 5} 29 | \author{PB17000297 罗晏宸} 30 | \date{March 29 2020} 31 | 32 | \begin{document} 33 | \maketitle 34 | 35 | \section{Exercise 8.17} 36 | 解释下面给出的 Wumpus 世界中相邻方格的定义存在什么问题: 37 | $$ 38 | \forall x, y \quad \textit{Adjacent}([x, y], [x + 1, y]) \land \textit{Adjacent}([x, y], [x, y + 1]) 39 | $$ 40 | 41 | \paragraph{解} 42 | 这样的定义仅考虑了坐标轴正方向上的相邻,但实际上相邻关系是无向的(即对称的);另外定义没有考虑到世界边界的作用关系,可能会给出在实际问题中不存在的相邻关系。 43 | 44 | 一个更合理的定义是 45 | \begin{equation*} 46 | \begin{aligned} 47 | & \forall 1 \leqslant x < 4, 1 \leqslant y < 4 \\ & \textit{Adjacent}([x, y], [x + 1, y]) \land \textit{Adjacent}([x + 1, y], [x, y]) \\ \land &\textit{Adjacent}([x, y], [x, y + 1]) \land \textit{Adjacent}([x, y + 1], [x, y]) 48 | \end{aligned} 49 | \end{equation*} 50 | 51 | \section{Exercise 8.24} 52 | 用一个相容的词汇表(需要你自己定义)在一阶逻辑中表示下列语句: 53 | \begin{enumerate}[label = \emph{\alph*}.] 54 | \item 某些学生在2001年春季学期上法语课 55 | \item 上法语课的每个学生都通过了考试 56 | \item 只有一个学生在2001年春季学期上希腊语课 57 | \item 希腊语课的最好成绩总是比法语课的最好成绩高 58 | \item 每个买保险的人都是聪明的 59 | \item 没有人会买昂贵的保险 60 | \item 有一个代理,他只卖保险给那些没有投保的人 61 | \item 镇上有一个理发师,他给所有不自己刮胡子的人刮胡子 62 | \item 在英国出生的人,如果其双亲都是英国公民或永久居住者,那么此人生来就是一个英国公民 63 | \item 在英国以外的地方出生的人,如果其双亲生来就是英国公民,那么此人血统上是一个英国公民 64 | \item 政治家可以一直愚弄某些人,也可以在某个时候愚弄所有人,但是他们无法一直愚弄所有的人 65 | \end{enumerate} 66 | 67 | \paragraph{解} 68 | 设计如下的词汇表: 69 | \begin{itemize} 70 | \item $\textit{Student}(x)$表示$x$是学生 71 | \item $\textit{Select}(x, c, s)$表示学生$x$在$s$学期上$c$课 72 | \item $\textit{Pass}(x, c, s)$表示在$s$学期上$c$课的学生$x$通过了考试 73 | \item $\textit{Grade}(x, c, s)$表示在$s$学期上$c$课的学生$x$的成绩 74 | \item $\textit{Person}(x)$表示$x$是正常人 75 | \item $\textit{Smart}(x)$表示$x$是聪明的 76 | \item $\textit{Policy}(x)$表示$x$是保险 77 | \item $\textit{Expensive}(x)$表示$x$是昂贵的 78 | \item $\textit{Agent}(x)$表示$x$是代理 79 | \item $\textit{Insured}(x)$表示$x$已被投保 80 | \item $\textit{Buy}(x, y, g)$表示$x$向$y$购买了$g$ 81 | \item $\textit{Sell}(x, y, g)$表示$x$把$g$卖给了$y$ 82 | \item $\textit{Barber}(x)$表示$x$是理发师 83 | \item $\textit{Shave}(x, y)$表示$x$给$y$刮胡子 84 | \item $\textit{Born}(x, c)$表示$x$在国家$c$出生 85 | \item $\textit{Parent}(x, y)$表示$x$是$y$的双亲之一 86 | \item $\textit{Citizen}(x, c, b)$表示$x$基于$b$是国家$c$的公民 87 | \item $\textit{Resident}(x, c)$表示$x$是国家$c$的永久居住者 88 | \item $\textit{Politician}(x)$表示$x$是政治家 89 | \item $\textit{Fool}(x, y, t)$表示$x$在$t$时刻愚弄了$y$ 90 | \end{itemize} 91 | 给出上述语句的表示 92 | \begin{enumerate}[label = \emph{\alph*}.] 93 | \item $\exists x \quad \textit{Student}(x) \land \textit{Select}(x, \textit{French}, \textit{2001Spring})$ 94 | \item $\forall x,s \quad \textit{Student}(x) \land \textit{Select}(x, \textit{French}, s) \Rightarrow \textit{Pass}(x, \textit{French}, s)$ 95 | \item $\forall x \quad \textit{Student}(x) \land \textit{Select}(x, \textit{Greek}, s) \land \big(\forall y \quad y \neq x \Rightarrow \lnot \textit{Select}(y, \textit{Greek}, \textit{2001Spring})\big)$ 96 | \item $\forall s\ \exists x\ \forall y \quad \textit{Grade}(x, \textit{Greek}, s) > \textit{Grade}(y, French, s)$ 97 | \item $\forall x,p,a \quad \textit{Person}(x) \land \textit{Policy}(p) \land \textit{Agent}(a) \land \textit{Buy}(x, a, p) \Rightarrow \textit{Smart}(x)$ 98 | \item $\forall x,p,a \quad \textit{Person}(x) \land \textit{Policy}(p) \land \textit{Expensive}(p) \Rightarrow \lnot \textit{Buy}(x, a, p)$ 99 | \item $\exists a \quad \textit{Agent}(a) \land \Big(\forall x, p \ \big(\textit{Policy}(p) \land \textit{Sell}(a, x, p)\big) \Rightarrow \big(\textit{Person}(x) \land \lnot \textit{Insured}(x)\big)\Big)$ 100 | \item $\exists x \quad \textit{Barber}(x) \land \big(\forall y \ \textit{Person}(y) \land \lnot \textit{Shave}(y,y) \Rightarrow \textit{Shave}(x,y)\big)$ 101 | \item $\forall x \quad \textit{Person}(x) \land \textit{Born}(x, \textit{UK}) \land \bigg(\forall y \ \textit{Parent}(y,x) \land \Big(\big(\exists b \ \textit{Citizen}(y, \textit{UK}, b)\big) \lor \textit{Resident}(y, \textit{UK})\Big)\bigg) \Rightarrow \textit{Citizen}(x, \textit{UK}, \textit{"Birth"})$ 102 | \item $\forall x \quad \textit{Person}(x) \land \lnot \textit{Born}(x, \textit{UK}) \land \Big(\forall y \ \textit{Parent}(y,x) \land \big(\exists b \ \textit{Citizen}(y, \textit{UK}, b)\big)\Big) \Rightarrow \textit{Citizen}(x, \textit{UK}, \textit{"Descent"})$ 103 | \item $\forall x \quad \textit{Politician}(x) \Rightarrow \big(\exists y \ \forall t \ \textit{Person}(y) \land \textit{Fool}(x, y, t)\big) \land \big(\exists t \ \forall y \ \textit{Person}(y) \land \textit{Fool}(x, y, t)\big) \land \lnot\big(\forall t \ \forall y \ \textit{Person}(y) \land \textit{Fool}(x, y, t)\big)$ 104 | \end{enumerate} 105 | 106 | \section{Exercise 9.3} 107 | 假定知识库中只包括一条语句:$\exists x \textit{AsHighAs}(x,\, \textit{Everest})$,下列哪个语句是应用存在量词实例化以后的合法结果? 108 | \begin{enumerate}[label = \emph{\alph*}.] 109 | \item $\textit{AsHighAs}(\textit{Everest},\, \textit{Everest})$ 110 | \item $\textit{AsHighAs}(\textit{Kilimanjaro},\, \textit{Everest})$ 111 | \item $\textit{AsHighAs}(\textit{Kilimanjaro},\, \textit{Everest}) \land \textit{AsHighAs}(\textit{BenNevis},\, \textit{Everest})$ 112 | \end{enumerate} 113 | 114 | \paragraph{解} 115 | 语句b和c都是合法的结果,a不合法的原因是替换变元的应当是从未在知识库中出现过的常量符号,而不是已经出现过的\textit{Everest}。 116 | 117 | \section{Exercise 9.4} 118 | 对于下列每对原子语句,如果存在,请给出最一般合一置换: 119 | \begin{enumerate}[label = \emph{\alph*}.] 120 | \item $P(A,\, B,\, B),\ P(x,\, y,\, z)$ 121 | \item $Q(y,\, G(A,\, B)),\ Q(G(x,\, x),\, y)$ 122 | \item $\textit{Older}(\textit{Father}(y),\, y),\ \textit{Older}(\textit{Father}(x),\, \textit{John})$ 123 | \item $\textit{Knows}(\textit{Father}(y),\, y),\ \textit{Knows}(x,\, x)$ 124 | \end{enumerate} 125 | 126 | \paragraph{解} 127 | 可能的合一置换结果如下所示 128 | \begin{enumerate}[label = \emph{\alph*}.] 129 | \item $\{A/x,\, B/y,\, B/z\}$ 130 | \item 合一失败,$x$不能同时取$A$和$B$ 131 | \item $\{y/\textit{John},\, x/\textit{John}\}$ 132 | \item 合一失败,发生检验中$y$和$\textit{Father}(y)$无法合一 133 | \end{enumerate} 134 | 135 | \section{Exercise 9.6} 136 | 写出下列语句的逻辑表示,使得它们适用一般化假言推理规则: 137 | \begin{enumerate}[label = \emph{\alph*}.] 138 | \item 马、奶牛和猪都是哺乳动物 139 | \item 一匹马的后代是马 140 | \item Bluebeard 是一匹马 141 | \item Bluebeard 是 Charlie 的家长 142 | \item 后代和家长是逆关系 143 | \item 每个哺乳动物都有一个家长 144 | \end{enumerate} 145 | 146 | \paragraph{解} 147 | \begin{itemize} 148 | \item $\textit{Horse}(x)$表示$x$是马 149 | \item $\textit{Cow}(x)$表示$x$是奶牛 150 | \item $\textit{Pig}(x)$表示$x$是猪 151 | \item $\textit{Mammal}(x)$表示$x$是哺乳动物 152 | \item $\textit{Descendant}(x,y)$表示$x$是$y$的后代 153 | \item $\textit{Parent}(x,y)$表示$x$是$y$的家长 154 | \end{itemize} 155 | 逻辑表示如下 156 | \begin{enumerate}[label = \emph{\alph*}.] 157 | \item $\textit{Horse}(x) \Rightarrow \textit{Mammal}(x) \\ \textit{Cow}(x) \Rightarrow \textit{Mammal}(x) \\ \textit{Pig}(x) \Rightarrow \textit{Mammal}(x)$ 158 | \item $\textit{Descendant}(x, y) \land \textit{Horse}(y) \Rightarrow \textit{Horse}(x)$ 159 | \item $\textit{Horse}(\textit{Bluebeard})$ 160 | \item $\textit{Parent}(\textit{Bluebeard}, \textit{Charlie})$ 161 | \item $\textit{Descendant}(x, y) \Rightarrow \textit{Parent}(y, x) \\ \textit{Parent}(x, y) \Rightarrow \textit{Descendant}(y, x)$ 162 | \item $\textit{Mammal}(x) \Rightarrow \textit{Parent}(\textit{Gen}(x), x)$,其中$\textit{Gen}(x)$是一个Skolem范式 163 | \end{enumerate} 164 | 165 | \section{Exercise 9.13} 166 | 本题中需要用到你在习题9.6中写出的语句,运用反向链接算法来回答问题 167 | \subparagraph{a} 画出用穷举反向链接算法为查询$\exists h \textit{horse}(h)$生成的证明树,其中子句按照给定的顺序进行匹配 168 | \subparagraph{b} 对于本邻域,你注意到了什么? 169 | \subparagraph{c} 实际上从你的语句中得出了多少个$h$的解? 170 | \subparagraph{d} 你是否可以想出一种方法找出所有的解? 171 | 172 | \paragraph{解} 173 | \subparagraph{a} 174 | 如图\ref{figure:1}所示。 175 | \begin{figure}[h] 176 | \centering 177 | \begin{tikzpicture}[Node/.style = {rectangle, draw = black, text ragged}, sibling distance = 5cm] 178 | \node [Node] (1) {$\textit{Horse}(h)$} 179 | child {node [Node] (2) {$\textit{Descendant}(h,y)$} 180 | child {node [Node] (3) {$\textit{Parent}(y,h)$}} 181 | } 182 | child {node [Node] (4) {$\textit{Horse}(\textit{Bluebeard})$} 183 | child {node [Node] (6) {$\textit{Descendant}(\textit{Bluebeard},y)$} 184 | child {node [Node] (7) {$\textit{Parent}(y, \textit{Bluebeard})$} 185 | child {node [Node] (8) {$\textit{Descendant}(\textit{Bluebeard}, y)$} 186 | child {node [] (9) {$\vdots$}} 187 | } 188 | } 189 | } 190 | }; 191 | \node [below = 0.5em of 3] (10) {$\{y/\textit{Bluebeard},\, h/\textit{Charlie}\}$}; 192 | \end{tikzpicture} 193 | \caption{反向链接构造的证明树。其中$\textit{Parent}(y, \textit{Bluebeard})$和$\textit{Descendant}(\textit{Bluebeard}, y)$将会无限重复,无法到达树枝} 194 | \label{figure:1} 195 | \end{figure} 196 | 197 | \subparagraph{b} 198 | 注意到树中出现的无限延伸,这实际上是由于规则子句的顺序引起的,可以通过在规则$\textit{Descendant}(x, y) \land \textit{Horse}(y) \Rightarrow \textit{Horse}(x)$之前指定匹配顺序来得到解,但是如果要求穷举所有的解,那与子句顺序无关,循环一定会发生。 199 | 200 | \subparagraph{c} 201 | 实际上得到了\textit{Bluebeard}和\textit{Charlie}两个解。 202 | 203 | \subparagraph{d} 204 | 用堆栈维护子目标是否在搜索路径中出现过,当出现循环时,搁置该目标的证明,尝试证明其他所有分支,使用得到的解决方案作为该目标的解决方案,再继续对其证明以找到不同的解决方案,如果没有来自其他分支的解决方案使得该子目标成立,那么就认为其失败。 205 | \end{document} -------------------------------------------------------------------------------- /Homework6/PB17000297_罗晏宸.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyc0930/AI-Homework/81cc1ab4c2b3cedc1df2cf2ae56b02232aa47563/Homework6/PB17000297_罗晏宸.pdf -------------------------------------------------------------------------------- /Homework6/PB17000297_罗晏宸.tex: -------------------------------------------------------------------------------- 1 | \documentclass{article} 2 | \usepackage[UTF8]{ctex} 3 | \usepackage[T1]{fontenc} 4 | \usepackage[utf8]{inputenc} 5 | \usepackage{titlesec} 6 | \usepackage[colorlinks, linkcolor = black]{hyperref} 7 | \usepackage{float} 8 | \usepackage{xcolor} 9 | \usepackage{amsmath} 10 | \usepackage{amssymb} 11 | \usepackage{latexsym} 12 | \usepackage{amsthm} 13 | \usepackage{graphicx} 14 | \usepackage{enumerate} 15 | \usepackage{enumitem} 16 | \usepackage{tikz} 17 | \usetikzlibrary{positioning} 18 | \usetikzlibrary[arrows, shapes, chains] 19 | 20 | \setlist{ 21 | leftmargin = .1\linewidth, 22 | % rightmargin = .1\linewidth, 23 | % label=\emph{\alph*}. 24 | } 25 | 26 | \titleformat{\section}[block]{\LARGE\scshape}{\arabic{section}}{1em}{}[] 27 | 28 | \title{Homework 6} 29 | \author{PB17000297 罗晏宸} 30 | \date{April 6 2020} 31 | 32 | \begin{document} 33 | \maketitle 34 | 35 | \section{Exercise 13.15} 36 | 在一年一度的体检之后,医生告诉你一些坏消息和一些好消息。坏消息是你在一种严重的疾病的测试结果呈阳性,而这个测试的准确度为99\%(即当你确实患这种病时,测试结果为阳性的概率为0.99;而当你未患这种疾病时测试结果为阴性的概率也是0.99)。好消息是,这是一种罕见的病,在你这个年龄段大约10000人中才有1例。为什么“这种病很罕见”对于你而言是一个好消息?你确实患有这种病的概率是多少? 37 | 38 | \paragraph{解} 39 | 作为测试结果呈阳性的人,我关心的是在这个条件下的我患病的条件概率,即$P(\text{患病}|\text{阳性})$,而已知$P(\text{阳性}|\text{患病}) = 0.99$,$P(\text{阴性}|\text{未患病}) = 0.99$,$P(\text{患病}) = \frac{1}{10000}$,有 40 | \begin{align*} 41 | P(\text{患病}|\text{阳性}) & = \frac{P(\text{患病} \land \text{阳性})}{P(\text{阳性})} \\ 42 | & = \frac{P(\text{阳性}|\text{患病})P(\text{患病})}{P(\text{阳性}|\text{患病})P(\text{患病}) + P(\text{阴性}|\text{未患病})P(\text{未患病})} \\ 43 | & = \frac{0.99 \times \frac{1}{10000}}{0.99 \times \frac{1}{10000} + (1 - 0.99) \times (1 - \frac{1}{10000})} \\ 44 | & = \frac{1}{102} \\ 45 | & \approx 0.009804 46 | \end{align*} 47 | 由式可见,我患病的条件概率随$P(\text{患病})$减小而减小,因此“这种病很罕见”对我而言是一个好消息,事实上当测试的准确度比个体不患病的概率小很多时,阳性的测试结果很大可能是误诊。从结果来看,我患这种病的概率仅为$\frac{1}{102}$,不足1\%。 48 | 49 | \section{Exercise 13.18} 50 | 假设给你一只袋子,装有$n$个无偏差的硬币,并且告诉你其中$n - 1$个硬币是正常的,一面是正面而另一面是反面。不过剩余1枚硬币是伪造的,它的两面都是正面。 51 | \subparagraph{a} 假设你把手伸进口袋均匀随机地取出一枚硬币,把它抛出去,硬币落地后正面朝上。那么你取出伪币的(条件)概率是多少? 52 | \subparagraph{b} 假设你不停地抛这枚硬币,一共抛了$k$次,而且看到$k$次正面向上。那么你取出伪币的条件概率是多少? 53 | \subparagraph{c} 假设你希望通过把取出的硬币抛$k$次的方法来确定它是不是伪造的。如果抛$k$次后都是正面朝上,那么决策过程返回\textit{fake}(伪造),否则返回 \textit{normal} (正常)。这个过程发生错误的(无条件)概率是多少? 54 | 55 | \paragraph{解} 56 | \subparagraph{a} 57 | 下面用$P(\text{伪币}|\text{正面})$简记随机取出一枚硬币,抛出落地后正面朝上的条件下,取出的是伪币的条件概率。 58 | \begin{align*} 59 | P(\text{伪币}|\text{正面}) & = \frac{P(\text{伪币} \land \text{正面})}{P(\text{正面})} \\ 60 | & = \frac{\frac{1}{n} \times 1}{\frac{1}{n} \times 1 + \frac{n - 1}{n} \times \frac{1}{2}} \\ 61 | & = \frac{2}{n + 1} 62 | \end{align*} 63 | \subparagraph{b} 64 | \begin{align*} 65 | P(\text{伪币}|\text{$k$次正面}) & = \frac{P(\text{伪币} \land \text{$k$次正面})}{P(\text{$k$次正面})} \\ 66 | & = \frac{\frac{1}{n} \times 1^k}{\frac{1}{n} \times 1^k + \frac{n - 1}{n} \times (\frac{1}{2})^k} \\ 67 | & = \frac{2^k}{2^k + n - 1} 68 | \end{align*} 69 | \subparagraph{c} 70 | 过程发生错误即取出了一枚正常硬币但依然有抛$k$次后都是正面朝上的结果(取出伪币但是有反面朝上的结果是不存在的),返回\textit{fake}。 71 | \begin{align*} 72 | P(\lnot \text{伪币} \land \text{$k$次正面}) & = P(\text{$k$次正面} | \lnot \text{伪币})P(\lnot \text{伪币}) \\ 73 | & = \left(\frac{1}{2}\right)^k \times \frac{n - 1}{n} \\ 74 | & = \frac{n - 1}{2^kn} 75 | \end{align*} 76 | 77 | \section{Exercise 13.22} 78 | 文本分类是基于文本内容将给定的一个文档分类成固定的几个类中的一类。朴素贝叶斯模型经常用于这个问题。在朴素贝叶斯模型中,查询(query)变量是这个文档的类别,而结果(effect)变量是语言中每个单词的存在与否;假设文档中单词的出现是独立的,单词的出现频率由文档类别决定。 79 | \subparagraph{a} 给定一组已经被分类的文档,准确解释如何构造这样的模型。 80 | \subparagraph{b} 准确解释如何分类一个新文档。 81 | \subparagraph{c} 题目中的条件独立性假设合理吗?请讨论。 82 | 83 | \paragraph{解} 84 | \subparagraph{a} 85 | 模型的概率分布由先验概率$P(\text{类别} = A)$和条件概率$P(\text{单词}_i|\text{类别} = A)$,前者描述所有文档中类别$A$的比例,后者表示类别为$A$的文档中包含单词$i$的比例。 86 | 87 | \subparagraph{b} 88 | 对于一个给定的新文档,其内容是已知的,通过统计其中各单词的出现频率,由于单词的出现频率是由文档类别决定的,可以对于文档的类别给出断言。 89 | 90 | \subparagraph{c} 91 | 不合理,单词不一定是原子的,复合词的出现概率并不一定等于其部件出现概率之积。 92 | \end{document} -------------------------------------------------------------------------------- /Homework7/Figure/14-11.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyc0930/AI-Homework/81cc1ab4c2b3cedc1df2cf2ae56b02232aa47563/Homework7/Figure/14-11.pdf -------------------------------------------------------------------------------- /Homework7/Figure/14-22(i).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyc0930/AI-Homework/81cc1ab4c2b3cedc1df2cf2ae56b02232aa47563/Homework7/Figure/14-22(i).pdf -------------------------------------------------------------------------------- /Homework7/Figure/14-22(ii).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyc0930/AI-Homework/81cc1ab4c2b3cedc1df2cf2ae56b02232aa47563/Homework7/Figure/14-22(ii).pdf -------------------------------------------------------------------------------- /Homework7/Figure/14-22(iii).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyc0930/AI-Homework/81cc1ab4c2b3cedc1df2cf2ae56b02232aa47563/Homework7/Figure/14-22(iii).pdf -------------------------------------------------------------------------------- /Homework7/Figure/14-9.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyc0930/AI-Homework/81cc1ab4c2b3cedc1df2cf2ae56b02232aa47563/Homework7/Figure/14-9.pdf -------------------------------------------------------------------------------- /Homework7/PB17000297_罗晏宸.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyc0930/AI-Homework/81cc1ab4c2b3cedc1df2cf2ae56b02232aa47563/Homework7/PB17000297_罗晏宸.pdf -------------------------------------------------------------------------------- /Homework7/PB17000297_罗晏宸.tex: -------------------------------------------------------------------------------- 1 | \documentclass{article} 2 | \usepackage[UTF8]{ctex} 3 | \usepackage[T1]{fontenc} 4 | \usepackage[utf8]{inputenc} 5 | \usepackage{titlesec} 6 | \usepackage[colorlinks, linkcolor = black]{hyperref} 7 | \usepackage{float} 8 | \usepackage{xcolor} 9 | \usepackage{amsmath} 10 | \usepackage{amssymb} 11 | \usepackage{latexsym} 12 | \usepackage{amsthm} 13 | \usepackage{graphicx} 14 | \usepackage{subcaption} 15 | \usepackage{diagbox} 16 | \renewcommand*\thesubfigure{\roman{subfigure}} 17 | 18 | % 增加矩阵两侧括号内侧的空白,新建附参数arraystretch的matrix命令族 19 | \makeatletter 20 | \renewenvironment{pmatrix} 21 | {\left(\mkern10.0mu\env@matrix} 22 | {\endmatrix\mkern10.0mu\right)} 23 | \renewcommand*\env@matrix[1][\arraystretch]{% 24 | \edef\arraystretch{#1}% 25 | \hskip -\arraycolsep 26 | \let\@ifnextchar\new@ifnextchar 27 | \array{*\c@MaxMatrixCols c}} 28 | \makeatother 29 | 30 | \newlength{\depthofsumsign} 31 | \setlength{\depthofsumsign}{\depthof{$\sum$}} 32 | \newcommand{\nsum}[1][1.4]{% only for \displaystyle 33 | \mathop{% 34 | \raisebox 35 | {-#1\depthofsumsign+1\depthofsumsign} 36 | {\scalebox 37 | {#1} 38 | {$\displaystyle\sum$}% 39 | } 40 | } 41 | } 42 | 43 | \titleformat{\section}[block]{\LARGE\scshape}{\arabic{section}}{1em}{}[] 44 | 45 | \title{Homework 7} 46 | \author{PB17000297 罗晏宸} 47 | \date{April 19 2020} 48 | 49 | \begin{document} 50 | \maketitle 51 | 52 | \section{Exercise 14.12} 53 | 两个来自世界上不同地方的宇航员同时用他们自己的望远镜观测了太空中某个小区域内恒星的数目$N$。他们的测量结果分别为$M_1$和$M_2$。通常,测量中会有不超过 1 颗恒星的误差,发生错误的概率$e$很小。每台望远镜可能出现(出现的概率$f$更小一些)对焦不准确的情况(分别记作$F_1$和$F_2$),在这种情况下科学家会少数三颗甚至更多的恒星(或者说,当$N$小于 3 时,连一颗恒星都观测不到)。考虑图\ref{14.22}所示的三种贝叶斯网络结构。 54 | \begin{figure} 55 | \centering 56 | \begin{subfigure}[t]{0.3\textwidth} 57 | \centering 58 | \includegraphics[scale = 0.7]{Figure/14-22(i).pdf} 59 | \caption{} 60 | \label{14.22(i)} 61 | \end{subfigure} 62 | \begin{subfigure}[t]{0.3\textwidth} 63 | \centering 64 | \includegraphics[scale = 0.7]{Figure/14-22(ii).pdf} 65 | \caption{} 66 | \label{14.22(ii)} 67 | \end{subfigure} 68 | \begin{subfigure}[t]{0.3\textwidth} 69 | \centering 70 | \includegraphics[scale = 0.7]{Figure/14-22(iii).pdf} 71 | \caption{} 72 | \label{14.22(iii)} 73 | \end{subfigure} 74 | \caption{望远镜问题的三种可能网络} 75 | \label{14.22} 76 | \end{figure} 77 | \subparagraph{a.} 这三种网络结构哪些是对上述信息的正确(但不一定高效)表示? 78 | \subparagraph{b.} 哪一种网络结构是最好的?请解释。 79 | \subparagraph{c.} 当$N \in \{1,\, 2,\, 3\}$,$M_1 \in \{0,\, 1,\, 2,\, 3,\, 4\}$时,请写出$\mathbf{P}(M_1 | N)$的条件概率表。概率分布表里的每个条目都应该表达为参数$e$和/或$f$的一个函数。 80 | 81 | \paragraph{解} 82 | \subparagraph{a.} 83 | 网络(\subref{14.22(ii)})和(\subref{14.22(iii)})都是正确的表示。虽然(\subref{14.22(i)})描述了计算过程,但没有准确描述恒星数目$N$和对焦情况的关系,因此不是一个贝叶斯网络结构;(\subref{14.22(ii)})对因果结构的表示是正确的,两台望远镜的对焦情况彼此独立,测量结果受实际恒星数量和对焦情况的影响;(\subref{14.22(iii)})也是正确的,其是对结点排序之后的结果。 84 | 85 | \subparagraph{b.} 86 | (\subref{14.22(ii)})比(\subref{14.22(iii)})需要更少的参数,因此网络(\subref{14.22(ii)})是最好的。 87 | 88 | \subparagraph{c.} 对概率展开有 89 | \begin{align*} 90 | \mathbf{P}(M_1 | N) & = \mathbf{P}(M_1 | N,\, F_1)\mathbf{P}(F_1 | N) + \mathbf{P}(M_1 | N,\, \lnot F_1)\mathbf{P}(\lnot F_1 | N) \\ 91 | & = \mathbf{P}(M_1 | N,\, F_1)\mathbf{P}(F_1) + \mathbf{P}(M_1 | N,\, \lnot F_1)\mathbf{P}(\lnot F_1) \\ 92 | & = \mathbf{P}(M_1 | N,\, F_1)f + \mathbf{P}(M_1 | N,\, \lnot F_1)(1 - f) 93 | \end{align*} 94 | 假设测量时发生的多数1颗恒星和少数1颗恒星的概率均为$\dfrac{e}{2}$计算得到条件概率表如下: 95 | \begin{table}[h] 96 | \centering 97 | \begin{tabular}{|c|c|c|c|} 98 | \hline 99 | \diagbox{$M_1$}{$\mathbf{P}(M_1 | N)$}{N} & $1$ & $2$ & $3$ \\ 100 | \hline $0$ & $f + \frac{e}{2}(1 - f)$ & $f$ & $f$ \\ 101 | \hline $1$ & $(1 - e)(1 - f)$ & $\frac{e}{2}(1 - f)$ & $0$ \\ 102 | \hline $2$ & $\frac{e}{2}(1 - f)$ & $(1 - e)(1 - f)$ & $\frac{e}{2}(1 - f)$ \\ 103 | \hline $3$ & $0$ & $\frac{e}{2}(1 - f)$ & $(1 - e)(1 - f)$ \\ 104 | \hline $4$ & $0$ & $0$ & $\frac{e}{2}(1 - f)$ \\ 105 | \hline 106 | \end{tabular} 107 | \caption{当$N \in \{1,\, 2,\, 3\}$,$M_1 \in \{0,\, 1,\, 2,\, 3,\, 4\}$时$\mathbf{P}(M_1 | N)$的条件概率表} 108 | \label{table} 109 | \end{table} 110 | 111 | \section{Exercise 14.13} 112 | 考虑图\ref{14.22}(\subref{14.22(ii)})的网络,假设两个望远镜完全相同。$N \in \{1,\, 2,\, 3\}$,$M_1,\, M_2 \in \{0,\, 1,\, 2,\, 3,\, 4\}$,CPT 表和习题14.12所描述的一样。使用枚举算法(图\ref{14.9})计算概率分布$\mathbf{P}(N | M_1 = 2,\, M_2 = 2)$。 113 | \begin{figure} 114 | \centering 115 | \fbox{\includegraphics[width = \textwidth]{Figure/14-9.pdf}} 116 | \caption{在贝叶斯网络上回答查询的枚举算法} 117 | \label{14.9} 118 | \end{figure} 119 | 120 | \paragraph{解} 121 | 使用枚举算法计算的概率分布如下 122 | \begin{align*} 123 | & \mathbf{P}(N | M_1 = 2,\, M_2 = 2) \\ 124 | =\ & \alpha \sum_{f_1, f_2}\mathbf{P}(f_1,\, f_2,\, N,\, M_1 = 2,\, M_2 = 2) \\ 125 | =\ & \alpha \sum_{f_1,f_2}\mathbf{P}(f_1)\mathbf{P}(f_2)\mathbf{P}(M_1 = 2 | f_1,\, N)\mathbf{P}(M_2 = 2 | f_2,\, N) \\ 126 | =\ & \alpha(1 - f)(1 - f)\left\langle p_1, p_2, p_3\right\rangle\left\langle \frac{e}{2}, 1 - e, \frac{e}{2}\right\rangle\left\langle \frac{e}{2}, 1 - e, \frac{e}{2}\right\rangle \\ 127 | =\ & \alpha'\left\langle p_1\frac{e^2}{4}, p_2(1 - e)^2, p_3\frac{e^2}{4}\right\rangle 128 | \end{align*} 129 | 130 | \section{Exercise 14.15} 131 | 考虑图\ref{14.11}中的变量消元算法。 132 | \begin{figure} 133 | \centering 134 | \fbox{\includegraphics[width = \textwidth]{Figure/14-11.pdf}} 135 | \caption{用于贝叶斯网络推理的变量消元算法} 136 | \label{14.11} 137 | \end{figure} 138 | \subparagraph{a} 14.4节对如下查询应用了变量消元算法$$\mathbf{P}(\textit{Burglary}\ |\ \textit{JohnCalls} = \textit{true},\, \textit{MaryCalls} = \textit{true})$$执行必要的计算,并检验计算结果的正确性。 139 | \subparagraph{b} 统计所执行的算术运算的次数,将其与枚举算法所需的运算次数进行比较。 140 | \subparagraph{c} 假设贝叶斯网络结构具有链式结构,即由一个布尔随机变量序列$X_1,\, \cdots,\, X_n$构成,其中$\textit{Parents}(X_i) = \{X_{i - 1}\},\ i = 2,\, \cdots,\, n$。请问使用枚举算法计算$\mathbf{P}(X_1 | X_n = \textit{true})$的复杂度是多少?使用变量消元算法呢? 141 | 142 | \paragraph{解} 143 | \subparagraph{a} 计算表达式 144 | \begin{align*} 145 | & \mathbf{P}(\textit{Burglary}\ |\ \textit{JohnCalls} = \textit{true},\, \textit{MaryCalls} = \textit{true}) \\ 146 | =\ & \mathbf{P}(b | j,\, m) \\ 147 | =\ & \alpha \mathbf{P}(b) \sum_{e} P(e)\sum_{a} \mathbf{P}(a | b,\, e)P(j | a)P(m | a) \\ 148 | =\ & \alpha \mathbf{P}(b) \nsum[3.2]_{e}P(e)\left[ 149 | \begin{pmatrix}[1.5] 150 | P(a | b,\, e) & P(a | \lnot b,\, e) \\ 151 | P(a | b,\, \lnot e) & P(a | \lnot b,\, \lnot e) 152 | \end{pmatrix} 153 | P(j | a)P(m | a) \right. \\ 154 | & \indent + 155 | \left. 156 | \begin{pmatrix}[1.5] 157 | P(\lnot a | b,\, e) & P(\lnot a | \lnot b,\, e) \\ 158 | P(\lnot a | b,\, \lnot e) & P(\lnot a | \lnot b,\, \lnot e) 159 | \end{pmatrix} 160 | P(j | \lnot a)P(m | \lnot a)\right] \\ 161 | =\ & \alpha \mathbf{P}(b) \nsum[2.0]_{e}P(e)\left[ 162 | \begin{pmatrix} 163 | 0.95 & 0.29 \\ 164 | 0.94 & 0.001 165 | \end{pmatrix} 166 | \times 0.90 \times 0.70 \right. \\ 167 | & \indent + 168 | \left. 169 | \begin{pmatrix} 170 | 0.05 & 0.71 \\ 171 | 0.06 & 0.999 172 | \end{pmatrix} 173 | \times 0.05 \times 0.01\right] \\ 174 | =\ & \alpha \mathbf{P}(b) \nsum[2.0]_{e}P(e) 175 | \begin{pmatrix} 176 | 0.598525 & 0.183055 \\ 177 | 0.59223 & 0.0011295 \\ 178 | \end{pmatrix} \\ 179 | =\ & \alpha \mathbf{P}(b) \left[ 180 | \begin{pmatrix} 181 | 0.598525 \\ 182 | 0.183055 183 | \end{pmatrix} \times 0.002 + 184 | \begin{pmatrix} 185 | 0.59223 \\ 186 | 0.0011295 187 | \end{pmatrix} \times 0.998 \right] \\ 188 | =\ & \alpha \mathbf{P}(b) 189 | \begin{pmatrix} 190 | 0.59224259 \\ 191 | 0.001493351 \\ 192 | \end{pmatrix} \\ 193 | =\ & \alpha \langle 0.001 \times 0.59224259, 0.999 \times 0.001493351 \rangle \\ 194 | =\ & \alpha \langle 0.00059224259, 0.001491857649 \rangle \\ 195 | \approx\ & \langle 0.284, 0.716 \rangle 196 | \end{align*} 197 | 结果是正确的 198 | 199 | \subparagraph{b} 200 | 在上述的算术运算中,共有7次加法,16次乘法和2次除法。枚举算法有7次加法,18次乘法和2次除法,相比之下需要2次额外的乘法。 201 | 202 | \subparagraph{c} 203 | 使用枚举算法计算$\mathbf{P}(X_1 | X_n = \textit{true})$,对于随机变量$X_1$的两种取值,分别需要计算两棵深度均为$n - 2$的二叉树,因此复杂度是$O(2^n)$的。 204 | 205 | 使用变量消元算法计算$\mathbf{P}(X_1 | X_n = \textit{true})$,可以归纳地得到规模$n - 1,\, n - 2,\, \cdots,\, 1$的子问题,且递推是常数时间的,因此总的复杂度是$O(n)$的。 206 | \end{document} -------------------------------------------------------------------------------- /Homework7/Script.nb: -------------------------------------------------------------------------------- 1 | (* Content-type: application/vnd.wolfram.mathematica *) 2 | 3 | (*** Wolfram Notebook File ***) 4 | (* http://www.wolfram.com/nb *) 5 | 6 | (* CreatedBy='Mathematica 12.0' *) 7 | 8 | (*CacheID: 234*) 9 | (* Internal cache information: 10 | NotebookFileLineBreakTest 11 | NotebookFileLineBreakTest 12 | NotebookDataPosition[ 158, 7] 13 | NotebookDataLength[ 10528, 311] 14 | NotebookOptionsPosition[ 8456, 265] 15 | NotebookOutlinePosition[ 8811, 281] 16 | CellTagsIndexPosition[ 8768, 278] 17 | WindowFrame->Normal*) 18 | 19 | (* Beginning of Notebook Content *) 20 | Notebook[{ 21 | 22 | Cell[CellGroupData[{ 23 | Cell[BoxData[{ 24 | RowBox[{"A", " ", "=", 25 | RowBox[{ 26 | RowBox[{"{", 27 | RowBox[{ 28 | RowBox[{"{", 29 | RowBox[{"950", ",", "290"}], "}"}], ",", 30 | RowBox[{"{", 31 | RowBox[{"940", ",", "001"}], "}"}]}], "}"}], "/", 32 | "1000"}]}], "\[IndentingNewLine]", 33 | RowBox[{"B", "=", 34 | RowBox[{"1", "-", "A"}]}], "\[IndentingNewLine]"}], "Input", 35 | CellChangeTimes->{{3.7963724036986313`*^9, 3.796372468826006*^9}, { 36 | 3.7963740245514145`*^9, 3.796374026464363*^9}, {3.796374216588541*^9, 37 | 3.796374228060277*^9}, {3.796374324649212*^9, 3.796374348709227*^9}}, 38 | CellLabel->"In[23]:=",ExpressionUUID->"31c7df0d-5081-4933-be2e-ccd304b5427f"], 39 | 40 | Cell[BoxData[ 41 | RowBox[{"{", 42 | RowBox[{ 43 | RowBox[{"{", 44 | RowBox[{ 45 | FractionBox["19", "20"], ",", 46 | FractionBox["29", "100"]}], "}"}], ",", 47 | RowBox[{"{", 48 | RowBox[{ 49 | FractionBox["47", "50"], ",", 50 | FractionBox["1", "1000"]}], "}"}]}], "}"}]], "Output", 51 | CellChangeTimes->{3.796374349420331*^9}, 52 | CellLabel->"Out[23]=",ExpressionUUID->"bfbc90f0-d1e6-4bcb-97bc-430d8252a6b6"], 53 | 54 | Cell[BoxData[ 55 | RowBox[{"{", 56 | RowBox[{ 57 | RowBox[{"{", 58 | RowBox[{ 59 | FractionBox["1", "20"], ",", 60 | FractionBox["71", "100"]}], "}"}], ",", 61 | RowBox[{"{", 62 | RowBox[{ 63 | FractionBox["3", "50"], ",", 64 | FractionBox["999", "1000"]}], "}"}]}], "}"}]], "Output", 65 | CellChangeTimes->{3.796374349449252*^9}, 66 | CellLabel->"Out[24]=",ExpressionUUID->"b5b074d2-d03c-4117-b769-b2305624e723"] 67 | }, Open ]], 68 | 69 | Cell[CellGroupData[{ 70 | 71 | Cell[BoxData[ 72 | RowBox[{"c", "=", 73 | RowBox[{ 74 | RowBox[{"A", "*", 75 | RowBox[{"9", "/", "10"}], " ", 76 | RowBox[{"7", "/", "10"}]}], " ", "+", " ", 77 | RowBox[{"B", "*", 78 | RowBox[{"5", "/", "100"}], " ", 79 | RowBox[{"1", "/", "100", " "}]}]}]}]], "Input", 80 | CellChangeTimes->{{3.796372475697839*^9, 3.7963724828473177`*^9}, { 81 | 3.796373258813498*^9, 3.7963732601285934`*^9}, {3.7963739547900963`*^9, 82 | 3.796373963486575*^9}, {3.796374353360585*^9, 3.796374404034562*^9}}, 83 | CellLabel->"In[25]:=",ExpressionUUID->"57cbd38e-fb9d-407d-a8cd-3e296a84dd82"], 84 | 85 | Cell[BoxData[ 86 | RowBox[{"{", 87 | RowBox[{ 88 | RowBox[{"{", 89 | RowBox[{ 90 | FractionBox["23941", "40000"], ",", 91 | FractionBox["36611", "200000"]}], "}"}], ",", 92 | RowBox[{"{", 93 | RowBox[{ 94 | FractionBox["59223", "100000"], ",", 95 | FractionBox["2259", "2000000"]}], "}"}]}], "}"}]], "Output", 96 | CellChangeTimes->{3.796373263334696*^9, 3.796373973488812*^9, 97 | 3.7963740315149565`*^9, 3.7963740924998646`*^9, 3.796374404707116*^9}, 98 | CellLabel->"Out[25]=",ExpressionUUID->"8b2f2bc0-e5c2-4968-b420-ae274aba5461"] 99 | }, Open ]], 100 | 101 | Cell[CellGroupData[{ 102 | 103 | Cell[BoxData[ 104 | RowBox[{"MatrixForm", "[", 105 | RowBox[{"N", "[", 106 | RowBox[{"c", ",", "10"}], "]"}], "]"}]], "Input", 107 | CellChangeTimes->{{3.7963739667767982`*^9, 3.796373971246004*^9}, { 108 | 3.79637440787516*^9, 3.7963744167716804`*^9}, {3.796374476623748*^9, 109 | 3.7963744776465826`*^9}}, 110 | NumberMarks->False, 111 | CellLabel->"In[33]:=",ExpressionUUID->"ebad0ac2-d19f-48b3-8417-fb31ee2a827d"], 112 | 113 | Cell[BoxData[ 114 | TagBox[ 115 | RowBox[{"(", "\[NoBreak]", GridBox[{ 116 | {"0.598525`10.", "0.183055`10."}, 117 | {"0.59223`10.", "0.0011295`10."} 118 | }, 119 | GridBoxAlignment->{"Columns" -> {{Center}}, "Rows" -> {{Baseline}}}, 120 | GridBoxSpacings->{"Columns" -> { 121 | Offset[0.27999999999999997`], { 122 | Offset[0.7]}, 123 | Offset[0.27999999999999997`]}, "Rows" -> { 124 | Offset[0.2], { 125 | Offset[0.4]}, 126 | Offset[0.2]}}], "\[NoBreak]", ")"}], 127 | Function[BoxForm`e$, 128 | MatrixForm[BoxForm`e$]]]], "Output", 129 | CellChangeTimes->{ 130 | 3.796373421003273*^9, 3.7963739759268637`*^9, {3.7963744092775927`*^9, 131 | 3.7963744170804944`*^9}, 3.79637447827291*^9}, 132 | CellLabel-> 133 | "Out[33]//MatrixForm=",ExpressionUUID->"ffec5d7a-2ad5-4290-aa00-\ 134 | c8fef1e38bfc"] 135 | }, Open ]], 136 | 137 | Cell[CellGroupData[{ 138 | 139 | Cell[BoxData[ 140 | RowBox[{"d", "=", 141 | RowBox[{ 142 | RowBox[{ 143 | RowBox[{"c", "[", 144 | RowBox[{"[", "1", "]"}], "]"}], "*", 145 | RowBox[{"2", "/", "1000"}]}], "+", 146 | RowBox[{ 147 | RowBox[{"c", "[", 148 | RowBox[{"[", "2", "]"}], "]"}], "*", 149 | RowBox[{"998", "/", "1000"}]}]}]}]], "Input", 150 | CellChangeTimes->{{3.7963739799854155`*^9, 3.7963739914740534`*^9}, { 151 | 3.7963744396730433`*^9, 3.7963744532711325`*^9}}, 152 | CellLabel->"In[29]:=",ExpressionUUID->"12926654-13a8-49dd-b6e5-b507015ea69e"], 153 | 154 | Cell[BoxData[ 155 | RowBox[{"{", 156 | RowBox[{ 157 | FractionBox["59224259", "100000000"], ",", 158 | FractionBox["1493351", "1000000000"]}], "}"}]], "Output", 159 | CellChangeTimes->{ 160 | 3.7963739920915155`*^9, 3.79637403450619*^9, 3.7963740957238035`*^9, { 161 | 3.796374446455509*^9, 3.796374455077303*^9}}, 162 | CellLabel->"Out[29]=",ExpressionUUID->"49a7f611-08b9-4877-ab5a-bf0272a885f3"] 163 | }, Open ]], 164 | 165 | Cell[CellGroupData[{ 166 | 167 | Cell[BoxData[ 168 | RowBox[{"MatrixForm", "[", 169 | RowBox[{"N", "[", 170 | RowBox[{"d", ",", "10"}], "]"}], "]"}]], "Input", 171 | CellChangeTimes->{{3.7963744621851826`*^9, 3.7963744734853177`*^9}}, 172 | CellLabel->"In[32]:=",ExpressionUUID->"a25e5c94-8eac-45ae-86d9-ec2232d10496"], 173 | 174 | Cell[BoxData[ 175 | TagBox[ 176 | RowBox[{"(", "\[NoBreak]", 177 | TagBox[GridBox[{ 178 | {"0.59224259`10."}, 179 | {"0.001493351`10."} 180 | }, 181 | GridBoxAlignment->{"Columns" -> {{Center}}, "Rows" -> {{Baseline}}}, 182 | GridBoxSpacings->{"Columns" -> { 183 | Offset[0.27999999999999997`], { 184 | Offset[0.5599999999999999]}, 185 | Offset[0.27999999999999997`]}, "Rows" -> { 186 | Offset[0.2], { 187 | Offset[0.4]}, 188 | Offset[0.2]}}], 189 | Column], "\[NoBreak]", ")"}], 190 | Function[BoxForm`e$, 191 | MatrixForm[BoxForm`e$]]]], "Output", 192 | CellChangeTimes->{{3.7963744626658974`*^9, 3.7963744739520893`*^9}}, 193 | CellLabel-> 194 | "Out[32]//MatrixForm=",ExpressionUUID->"d630bb2a-113d-489c-a895-\ 195 | d1e64a05098f"] 196 | }, Open ]], 197 | 198 | Cell[CellGroupData[{ 199 | 200 | Cell[BoxData[ 201 | RowBox[{"e", "=", 202 | RowBox[{"{", 203 | RowBox[{ 204 | RowBox[{ 205 | RowBox[{"d", "[", 206 | RowBox[{"[", "1", "]"}], "]"}], "*", 207 | RowBox[{"1", "/", "1000"}]}], ",", 208 | RowBox[{ 209 | RowBox[{"d", "[", 210 | RowBox[{"[", "2", "]"}], "]"}], "*", 211 | RowBox[{"999", "/", "1000"}]}]}], "}"}]}]], "Input", 212 | CellChangeTimes->{{3.796375365368187*^9, 3.7963754063648853`*^9}}, 213 | CellLabel->"In[34]:=",ExpressionUUID->"f696f427-3fde-47d9-bb5d-dd7616bc9300"], 214 | 215 | Cell[BoxData[ 216 | RowBox[{"{", 217 | RowBox[{ 218 | FractionBox["59224259", "100000000000"], ",", 219 | FractionBox["1491857649", "1000000000000"]}], "}"}]], "Output", 220 | CellChangeTimes->{3.796375408192339*^9}, 221 | CellLabel->"Out[34]=",ExpressionUUID->"39b382f5-bebd-42f3-a453-6855ff1af7a5"] 222 | }, Open ]], 223 | 224 | Cell[CellGroupData[{ 225 | 226 | Cell[BoxData[ 227 | RowBox[{"N", "[", 228 | RowBox[{"e", ",", "11"}], "]"}]], "Input", 229 | CellChangeTimes->{{3.796375412980429*^9, 3.7963754284763536`*^9}}, 230 | CellLabel->"In[37]:=",ExpressionUUID->"554cb44d-a96c-4d47-9cf6-01e7a47fe064"], 231 | 232 | Cell[BoxData[ 233 | RowBox[{"{", 234 | RowBox[{"0.00059224259`11.", ",", "0.001491857649`11."}], "}"}]], "Output", 235 | CellChangeTimes->{{3.796375416695307*^9, 3.796375428794323*^9}}, 236 | CellLabel->"Out[37]=",ExpressionUUID->"27b66c4a-b959-4154-bdb0-f2dc4a815cb2"] 237 | }, Open ]], 238 | 239 | Cell[CellGroupData[{ 240 | 241 | Cell[BoxData[ 242 | RowBox[{"N", "[", 243 | RowBox[{"{", 244 | RowBox[{ 245 | RowBox[{ 246 | RowBox[{"e", "[", 247 | RowBox[{"[", "1", "]"}], "]"}], "/", 248 | RowBox[{"Total", "[", "e", "]"}]}], ",", 249 | RowBox[{ 250 | RowBox[{"e", "[", 251 | RowBox[{"[", "2", "]"}], "]"}], "/", 252 | RowBox[{"Total", "[", "e", "]"}]}]}], "}"}], "]"}]], "Input", 253 | CellChangeTimes->{{3.7963755362222967`*^9, 3.7963755551257153`*^9}, { 254 | 3.7963755868081007`*^9, 3.7963756143647437`*^9}}, 255 | CellLabel->"In[43]:=",ExpressionUUID->"13d4d9f0-6ae6-4a20-9739-9fc69deed5af"], 256 | 257 | Cell[BoxData[ 258 | RowBox[{"{", 259 | RowBox[{"0.28417183536439294`", ",", "0.7158281646356071`"}], 260 | "}"}]], "Output", 261 | CellChangeTimes->{{3.796375540889688*^9, 3.7963755555944633`*^9}, { 262 | 3.7963755874005165`*^9, 3.7963756153900337`*^9}}, 263 | CellLabel->"Out[43]=",ExpressionUUID->"65d38fa2-d549-4e9b-a9da-85b8bde7ffc7"] 264 | }, Open ]] 265 | }, 266 | WindowSize->{638, 668}, 267 | WindowMargins->{{Automatic, -7}, {Automatic, 0}}, 268 | FrontEndVersion->"12.0 for Microsoft Windows (64-bit) (2019\:5e745\:670818\ 269 | \:65e5)", 270 | StyleDefinitions->"Default.nb" 271 | ] 272 | (* End of Notebook Content *) 273 | 274 | (* Internal cache information *) 275 | (*CellTagsOutline 276 | CellTagsIndex->{} 277 | *) 278 | (*CellTagsIndex 279 | CellTagsIndex->{} 280 | *) 281 | (*NotebookFileOutline 282 | Notebook[{ 283 | Cell[CellGroupData[{ 284 | Cell[580, 22, 638, 15, 84, "Input",ExpressionUUID->"31c7df0d-5081-4933-be2e-ccd304b5427f"], 285 | Cell[1221, 39, 398, 12, 57, "Output",ExpressionUUID->"bfbc90f0-d1e6-4bcb-97bc-430d8252a6b6"], 286 | Cell[1622, 53, 398, 12, 57, "Output",ExpressionUUID->"b5b074d2-d03c-4117-b769-b2305624e723"] 287 | }, Open ]], 288 | Cell[CellGroupData[{ 289 | Cell[2057, 70, 557, 12, 35, "Input",ExpressionUUID->"57cbd38e-fb9d-407d-a8cd-3e296a84dd82"], 290 | Cell[2617, 84, 518, 13, 57, "Output",ExpressionUUID->"8b2f2bc0-e5c2-4968-b420-ae274aba5461"] 291 | }, Open ]], 292 | Cell[CellGroupData[{ 293 | Cell[3172, 102, 385, 8, 55, "Input",ExpressionUUID->"ebad0ac2-d19f-48b3-8417-fb31ee2a827d"], 294 | Cell[3560, 112, 766, 21, 75, "Output",ExpressionUUID->"ffec5d7a-2ad5-4290-aa00-c8fef1e38bfc"] 295 | }, Open ]], 296 | Cell[CellGroupData[{ 297 | Cell[4363, 138, 492, 13, 35, "Input",ExpressionUUID->"12926654-13a8-49dd-b6e5-b507015ea69e"], 298 | Cell[4858, 153, 368, 8, 57, "Output",ExpressionUUID->"49a7f611-08b9-4877-ab5a-bf0272a885f3"] 299 | }, Open ]], 300 | Cell[CellGroupData[{ 301 | Cell[5263, 166, 265, 5, 55, "Input",ExpressionUUID->"a25e5c94-8eac-45ae-86d9-ec2232d10496"], 302 | Cell[5531, 173, 715, 21, 75, "Output",ExpressionUUID->"d630bb2a-113d-489c-a895-d1e64a05098f"] 303 | }, Open ]], 304 | Cell[CellGroupData[{ 305 | Cell[6283, 199, 469, 13, 35, "Input",ExpressionUUID->"f696f427-3fde-47d9-bb5d-dd7616bc9300"], 306 | Cell[6755, 214, 277, 6, 57, "Output",ExpressionUUID->"39b382f5-bebd-42f3-a453-6855ff1af7a5"] 307 | }, Open ]], 308 | Cell[CellGroupData[{ 309 | Cell[7069, 225, 225, 4, 55, "Input",ExpressionUUID->"554cb44d-a96c-4d47-9cf6-01e7a47fe064"], 310 | Cell[7297, 231, 251, 4, 40, "Output",ExpressionUUID->"27b66c4a-b959-4154-bdb0-f2dc4a815cb2"] 311 | }, Open ]], 312 | Cell[CellGroupData[{ 313 | Cell[7585, 240, 539, 14, 55, "Input",ExpressionUUID->"13d4d9f0-6ae6-4a20-9739-9fc69deed5af"], 314 | Cell[8127, 256, 313, 6, 40, "Output",ExpressionUUID->"65d38fa2-d549-4e9b-a9da-85b8bde7ffc7"] 315 | }, Open ]] 316 | } 317 | ] 318 | *) 319 | 320 | (* End of internal cache information *) 321 | 322 | -------------------------------------------------------------------------------- /Homework8/Figure/SVM.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyc0930/AI-Homework/81cc1ab4c2b3cedc1df2cf2ae56b02232aa47563/Homework8/Figure/SVM.pdf -------------------------------------------------------------------------------- /Homework8/PB17000297_罗晏宸.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyc0930/AI-Homework/81cc1ab4c2b3cedc1df2cf2ae56b02232aa47563/Homework8/PB17000297_罗晏宸.pdf -------------------------------------------------------------------------------- /Homework8/PB17000297_罗晏宸.tex: -------------------------------------------------------------------------------- 1 | \documentclass{article} 2 | \usepackage[UTF8]{ctex} 3 | \usepackage[T1]{fontenc} 4 | \usepackage[utf8]{inputenc} 5 | \usepackage{titlesec} 6 | \usepackage[colorlinks, linkcolor = black]{hyperref} 7 | \usepackage{float} 8 | \usepackage{xcolor} 9 | \usepackage{amsmath} 10 | \usepackage{amssymb} 11 | \usepackage{latexsym} 12 | \usepackage{amsthm} 13 | \usepackage{graphicx} 14 | \usepackage{subcaption} 15 | \usepackage{diagbox} 16 | \renewcommand*\thesubfigure{\roman{subfigure}} 17 | \DeclareMathOperator{\sign}{sign} 18 | \titleformat{\section}[block]{\LARGE\scshape}{\arabic{section}}{1em}{}[] 19 | 20 | \title{Homework 8} 21 | \author{PB17000297 罗晏宸} 22 | \date{May 3 2020} 23 | 24 | \begin{document} 25 | \maketitle 26 | 27 | \section{} 28 | 试证明对于不含冲突数据(即特征向量完全相同但标记不同)的训练集,必存在一个与训练集一致(即训练误差为0)的决策树。 29 | 30 | \paragraph{解} 31 | \begin{proof} 32 | 决策树中叶节点生成于样本属于同一类或者样本在当前属性集上取值相同时,对于不含冲突数据的训练集,不会出现在当前属性集上取值相同但不同标记的样本,因此决策树的叶节点均为同类样本,即从根节点到每个叶节点的路径都代表一个向量,这个决策树与训练集是一致的。 33 | \end{proof} 34 | 35 | \section{} 36 | 已知正例点$\boldsymbol{x}_1 = (1, 2)^\mathbf{T}$, $\boldsymbol{x}_2 = (2, 3)^\mathbf{T}$, $\boldsymbol{x}_3 = (3, 3)^\mathbf{T}$,负例点$\boldsymbol{x}_4 = (2, 1)^\mathbf{T}$, $\boldsymbol{x}_5 = (3, 2)^\mathbf{T}$, 试求 Hard Margin SVM 的最大间隔分离超平面和分类决策函数,并在图上画出分离超平面、间隔边界以及支持向量。 37 | 38 | \paragraph{解} 39 | 按照训练集数据构造约束最优化问题 40 | \begin{align*} 41 | & \min_{\boldsymbol{\omega},b}{\frac{1}{2}(\omega_1^2 + \omega_2^2)} \label{1.1} \tag{1.1} \\ 42 | & \operatorname{s.t.} \left\{ 43 | \begin{aligned} 44 | \phantom{1}\omega_1 + 2\omega_2 + b & \geqslant 1 \\ 45 | 2\omega_1 + 3\omega_2 + b & \geqslant 1 \\ 46 | 3\omega_1 + 3\omega_2 + b & \geqslant 1 \\ 47 | -2\omega_1 - \phantom{1}\omega_2 - b & \geqslant 1 \\ 48 | -3\omega_1 - 2\omega_2 - b & \geqslant 1 49 | \end{aligned} 50 | \label{1.2} \tag{1.2} 51 | \right. 52 | \end{align*} 53 | Lagrange 函数 54 | \begin{align*} 55 | L(\boldsymbol{\omega}, b, \boldsymbol{\alpha}) = \frac{1}{2}\Arrowvert\boldsymbol{\omega} \Arrowvert^2 - \sum_{i = 1}^5{\alpha_i y_i (\boldsymbol{\omega} \cdot \boldsymbol{x}_i + b)} + \sum_{i = 1}^5{\alpha_i} 56 | \end{align*} 57 | 其中,$\boldsymbol{\alpha} = (\alpha_1,\alpha_2,\cdots,\alpha_5)^\mathbf{T}$为 Lagrange 乘子向量 58 | 59 | 根据 Lagrange 对称性,原问题的对偶问题是极大极小问题 60 | \begin{equation*} 61 | \max_{\boldsymbol{\alpha}}{\min_{\boldsymbol{\omega},b}{L(\boldsymbol{\omega},b,\boldsymbol{\alpha})}} 62 | \end{equation*} 63 | 64 | \subparagraph{(1)} 求$\displaystyle \min_{\boldsymbol{\omega},b}{L(\boldsymbol{\omega},b,\boldsymbol{\alpha})}$ 65 | 66 | 将 Lagrange 函数$L(\boldsymbol{\omega}, b, \boldsymbol{\alpha})$分别对$\boldsymbol{\omega}$、$b$求偏导数并令其等于0 67 | \begin{align*} 68 | & \nabla_{\boldsymbol{\omega}}{L(\boldsymbol{\omega}, b, \boldsymbol{\alpha})} = \boldsymbol{\omega} - \sum_{i = 1}^{5}{\alpha_i y_i \boldsymbol{x}_i} = 0 \\ 69 | & \nabla_{b}{L(\boldsymbol{\omega}, b, \boldsymbol{\alpha})} = \sum_{i = 1}^{5}{\alpha_i y_i} = 0 70 | \end{align*} 71 | 得 72 | \begin{align*} 73 | \boldsymbol{\omega} = & \sum_{i = 1}^{5}{\alpha_i y_i \boldsymbol{x}_i} = (\alpha_1 + 2\alpha_2 + 3\alpha_3 - 2\alpha_4 - 3\alpha_5, 2\alpha_1 + 3\alpha_2 + 3\alpha_3 - \alpha_4 - 2\alpha_5)^\mathbf{T} \\ 74 | & \sum_{i = 1}^{5}{\alpha_i y_i} = \alpha_1 + \alpha_2 + \alpha_3 - \alpha_4 - \alpha_5 = 0 75 | \end{align*} 76 | 代入 Lagrange 函数,得到 77 | \begin{align*} 78 | & \min_{\boldsymbol{\omega},b}{L(\boldsymbol{\omega},b,\boldsymbol{\alpha})} \\ 79 | = & -\frac{1}{2}\sum_{i = 1}^{5}{\sum_{j = 1}^{5}{\alpha_i \alpha_j y_i y_j(\boldsymbol{x}_i \cdot \boldsymbol{x}_j)}} + \sum_{i = 1}^{5}{\alpha_i} \\ 80 | = & \alpha _1+\alpha _2+\alpha _3+\alpha _4+\alpha _5+ \\ 81 | & \frac{1}{2} \big(-5 \alpha _1^2-16 \alpha _2 \alpha _1-18 \alpha _3 \alpha _1+8 \alpha _4 \alpha _1+14 \alpha _5 \alpha _1 \\ 82 | & -13 \alpha _2^2-18 \alpha _3^2-5 \alpha _4^2-13 \alpha _5^2-30 \alpha _2 \alpha _3+14 \alpha _2 \alpha _4 \\ 83 | & +18 \alpha _3 \alpha _4+24 \alpha _2 \alpha _5+30 \alpha _3 \alpha _5-16 \alpha _4 \alpha _5\big) 84 | \end{align*} 85 | \subparagraph{(2)} 求$\displaystyle \min_{\boldsymbol{\omega},b}{L(\boldsymbol{\omega},b,\boldsymbol{\alpha})}$对 $\boldsymbol{{\alpha}}$ 的极大 86 | 87 | 将目标函数转换为极小,得到与之等价的对偶最优化问题 88 | \begin{align*} 89 | & \min_{\boldsymbol{\alpha}}{\frac{1}{2}\sum_{i = 1}^{5}{\sum_{j = 1}^{5}{\alpha_i \alpha_j y_i y_j(\boldsymbol{x}_i \cdot \boldsymbol{x}_j)}} - \sum_{i = 1}^{5}{\alpha_i}} \label{2.1} \tag{2.1} \\ 90 | & \operatorname{s.t.} \left\{ 91 | \begin{aligned} 92 | \alpha _1+ \alpha _2+ \alpha _3- \alpha _4- \alpha _5 & = 0 \\ 93 | \alpha_i & \geqslant 0, \quad i = 1, 2, 3, 4, 5 94 | \end{aligned} 95 | \label{2.2} \tag{2.2} 96 | \right. 97 | \end{align*} 98 | 解得$\boldsymbol{\alpha}^* = (-2, 5, -3, 0, 0)^\mathbf{T}$。 99 | 考虑原始最优化问题\eqref{1.1}$\sim$\eqref{1.2}和对偶最优化问题\eqref{2.1}$\sim$\eqref{2.2},由$\alpha^*_2 = 5 > 0$原始最优化问题有解 100 | \begin{align*} 101 | \boldsymbol{\omega}^* & = \sum_{i = 1}^{5}{\alpha_i^* y_i \boldsymbol{x}_i} = (-1, 2)^\mathbf{T} \\ 102 | b^* & = \boldsymbol{1 - \sum_{i = 1}^{5}{\alpha_i^* y_i(\boldsymbol{x}_i \cdot x_2)}} = -2 103 | \end{align*} 104 | 于是最大间隔分离超平面为 105 | \begin{equation*} 106 | -\boldsymbol{x}^{(1)} + 2 \boldsymbol{x}^{(2)} - 2 = 0 107 | \end{equation*} 108 | 其中$\boldsymbol{x}_1 = (1, 2)^\mathbf{T}$, $\boldsymbol{x}_3 = (3, 3)^\mathbf{T}$与$\boldsymbol{x}_5 = (3, 2)^\mathbf{T}$为支持向量 109 | ,如图\ref{SVM}所示。 110 | \begin{figure} 111 | \centering 112 | \includegraphics[width = \textwidth]{Figure/SVM.pdf} 113 | \caption{最大间隔分离器、间隔边界与支持向量} 114 | \label{SVM} 115 | \end{figure} 116 | 分类决策函数为 117 | \begin{equation*} 118 | f(x) = \sign{\left\{\sum_{i = 1}^{5}{\alpha^*_i y_i (x \cdot \boldsymbol{x}_i)} + b^* \right\}} = \sign{\{ -\boldsymbol{x}^{(1)} + 2\boldsymbol{x}^{(2)} - 2\}} 119 | \end{equation*} 120 | % 在 2 维空间中设 1 维超平面(即直线)方程为$\boldsymbol{\omega} \cdot \boldsymbol{x} - b = (A, B) \cdot (x, y)^\mathbf{T} + C = Ax + By + C = 0$。为避免歧义,用$x_i$与$y_i$表示点$\boldsymbol{x}_1$的分量,也即在二维空间中的坐标。平行的两个间隔边界间距为$\dfrac{\left|C_1 - C_2\right|}{\sqrt{A^2 + B^2}}$,对于数据集求间距的最大值点,即求 121 | % \begin{equation*} 122 | % \arg\max 123 | % \left\{ 124 | % \begin{aligned} 125 | % & \frac{\left|2B-A\right|}{\sqrt{A^2+B^2}}, & -2 \leqslant & \frac{A}{B} < -1, & & C_1 = -3A - 3B, & & C_2 = -2A - B \\ 126 | % & \frac{\left|B\right|}{\sqrt{A^2+B^2}}, & -1 \leqslant & \frac{A}{B} < -\frac{1}{2}, & & C_1 = -3A - 3B, & & C_2 = -3A - 2B \\ 127 | % & \frac{\left|2 A\right|}{\sqrt{A^2+B^2}}, & -\frac{1}{2} \leqslant & \frac{A}{B} \leqslant 0, & & C_1 = -A - 2B , & & C_2 = -3A - 2B \\ 128 | % \end{aligned} 129 | % \right. 130 | % \end{equation*} 131 | % 得到 132 | % \begin{equation*} 133 | % \frac{A}{B} = -\frac{1}{2},\ C_1 = -\frac{3B}{2},\ C_2 = -\frac{B}{2} 134 | % \end{equation*} 135 | % \begin{figure} 136 | % \centering 137 | % \includegraphics[width = \textwidth]{Figure/SVM.pdf} 138 | % \caption{最大间隔分离器、间隔边界与支持向量} 139 | % \label{SVM} 140 | % \end{figure} 141 | % 如图\ref{SVM}所示,最大间隔分离超平面$\{\boldsymbol{x} : \boldsymbol{\omega} \cdot \boldsymbol{x} - b = 0\}$,其中$\boldsymbol{\omega} = (-1, 2),\ b = 2$,即 142 | % \begin{equation*} 143 | % \{\boldsymbol{x} : -x + 2y - 2= 0\} 144 | % \end{equation*} 145 | % 分类决策函数为 146 | % \begin{equation*} 147 | % h(x) = \sign{\{\boldsymbol{\omega} \cdot \boldsymbol{x} - b\}} = \sign{\{ -x + 2y - 2\}} 148 | % \end{equation*} 149 | \end{document} --------------------------------------------------------------------------------