|
| 1 | +\chapter{字符串编辑距离} |
| 2 | + |
| 3 | +\begin{introduction} |
| 4 | + \item 问题引入 |
| 5 | + \item 相关概念 |
| 6 | + \item 算法思想 |
| 7 | +\end{introduction} |
| 8 | + |
| 9 | +\section{问题引入} |
| 10 | +如何定义两个字符串的距离呢?ocurrance和occrrence有多大的区别呢?下面我们将讨论两个字符串的距离问题。 |
| 11 | +\section{相关概念} |
| 12 | +\begin{definition}{匹配M}{matching} |
| 13 | + 字符串X有$x_1$到$x_n$共n个字符,字符串Y有$y_1$到$y_m$共m个字符。X和Y之间存在一个匹配M,其满足:$if (i,j) \in M, (l,k)\in M, i<l iff j<k$。 |
| 14 | +\end{definition} |
| 15 | + |
| 16 | +%距离代价: |
| 17 | + |
| 18 | +%$\alpha_{xy}$ :两个不同的字符x和y相匹配的代价,则$\alpha_{xy}=0$. |
| 19 | + |
| 20 | +%$\delta$ :每存在一个没有被选择的字符就会多一个$\delta$. |
| 21 | + |
| 22 | +%总距离代价:所有$\delta$ 和 $\alpha$ 的和。 |
| 23 | + |
| 24 | +\begin{definition}{距离代价}{penalty} |
| 25 | + $\alpha_{xy}$:两个不同的字符x和y相匹配的代价,则$\alpha_{xy}=0$. |
| 26 | + |
| 27 | + $\delta$:每存在一个没有被选择的字符就会多一个$\delta$. |
| 28 | + |
| 29 | + 总距离代价:所有$\delta$ 和 $\alpha$ 的和。 |
| 30 | +\end{definition} |
| 31 | + |
| 32 | +示例: |
| 33 | + |
| 34 | +\begin{figure}[htb] |
| 35 | + \centering |
| 36 | + \includegraphics[scale=0.6]{image/connect1.png} |
| 37 | + \caption{字符串匹配}\label{fig:connect1} |
| 38 | +\end{figure} |
| 39 | +如上图所示,其中的总距离代价为$\alpha_{ae} + \delta$ |
| 40 | + |
| 41 | +\section{算法思想} |
| 42 | +从后往前推: |
| 43 | + |
| 44 | +bopt (i,j):字符串$x_1,\ldots,x_i$和$y_1,\ldots,y_j$之间的最佳匹配 |
| 45 | +\begin{equation} |
| 46 | + bopt (m,n)=\begin{cases} |
| 47 | + bopt(m-1,n-1)+\alpha_{x_m y_n} & \text{$x_m$和$y_n$ 相连} \\ |
| 48 | + bopt (m-1,n)+\delta & \text{$x_m$跳过} \\ |
| 49 | + bopt (m,n-1)+\delta & \text{$y_n$跳过} |
| 50 | + \end{cases} |
| 51 | +\end{equation} |
| 52 | + |
| 53 | +从前往后推: |
| 54 | + |
| 55 | +fopt (i,j):字符串$x_i,\ldots,x_m$ |
| 56 | +和 |
| 57 | +$y_j,\ldots,y_n$ |
| 58 | +之间的最佳匹配 |
| 59 | +\begin{equation} |
| 60 | + fopt (1,1)=\begin{cases} |
| 61 | + fopt(2,2)+\alpha_{x_1 y_1} & \text{$x_1$和$y_1$ 相连} \\ |
| 62 | + fopt (2,1)+\delta & \text{$x_1$跳过} \\ |
| 63 | + fopt (1,2)+\delta & \text{$y_1$跳过} |
| 64 | + \end{cases} |
| 65 | +\end{equation} |
| 66 | +初始化: |
| 67 | +$bopt (i,0) = \delta_i $ $bopt (0,i) = \delta_j$ |
| 68 | + |
| 69 | +构造图: |
| 70 | + |
| 71 | +\begin{figure}[htb] |
| 72 | + \centering |
| 73 | + \includegraphics[scale=0.6]{image/connect2.png} |
| 74 | + \caption{构造图}\label{fig:connect2} |
| 75 | +\end{figure} |
| 76 | +按图构造方法如图所示 |
0 commit comments