离散数学入门级概念:集合、关系、元组

习题原文链接:minfanphd

1. 集合

1.1 朴素的定义

Definition 1. A set is a collection of elements, and an element is an object in a set.

集合的两种表示法:
a) 列举法,如:\small A = \small \{​\small 0,\small 1,\small 2,\small 3,\small 4,\small 5,\small 6,\small 7,\small 8,\small 9\small \};
b) 谓词法,如:\small O = \small \{​\small x \small \in \small N\small x mod \small 2 = \small 1\small \}.

习题1:{0,1,{0,1},{1,2}}有几个元素?机器学习中,这类形式的集合有什么优点和缺点?

  • 上述集合有4个元素,分别是0、1、{0,1}、{1,2} ,其中元素{0,1}为一个集合,它的元素为0、1,元素{1,2}也为一个集合,它的元素为1、2。
  • 优点:集合中的元素是确定的,且集合可以容纳多种类型的数据。
  • 缺点:判断一个对象是否为指定集合的元素需一一对比;不同的维度出现重复的数据,可能意味着同一对象的重复表达,给问题的解决增添复杂。

1.2 基数 

集合 \small A 的基数,即其元素的个数,记为 |\small A|,读的时候,需读成“the cardinality of A”.

习题2:∅ 的基数是多少? {∅} 呢?

  • ∅ 是没有元素的集合,因此∅的基数为0。
  • {∅} 不是空集,该集合里有一个∅元素,因此{∅} 的基数为1。

1.3 笛卡尔积 

Definition 2. The Cartesian product of \small A_1 \small , \small ... \small , \small A_n is \small A_1  \small \times \small A_2  \small ... \small A_n = \small \{​\small \(\small x_1 \small , \small ... \small , \small x_n\small \) \small | \small x_1 \small \in \small A_1 \small , \small ... \small , \small x_n \small \in \small A_n\small \}.
笛卡尔积不满足结合律,如 \small A ={\small a}, \small B = {\small b}, \small C = {\small c}.那么 \small A \small \times \small B = {(\small a\small , \small b)}, (\small A \small \times \small B\small \times \small C = ((\small a\small , \small b)\small , \small c), 同理 \small A \small \times (\small B \small \times \small C) = (\small a\small , (\small b\small , \small c)).

数据集的两种表示法:
a) 矩阵表示法:记\small D = \small \(\small x_1\small , \small x_2,  \small ... \small , \small x_n\small \)^T,则 \small x_i \small \in \small R^m, 可支持矩阵的相乘,易于表示加权等操作;
b) 集合与向量混合法:记 \small D = {\small x_1\small , \small x_2,  \small ... \small , \small x_n},其中 \small x_i \small \in \small R^m,元素可随意交换顺序,但不允许两个元素相同。

1.4 幂集 

Definition 2. The power set of \small A is given by \small 2^A = {\small B\small |\small B \small \subseteq \small A}.
例:\small A = {1,2,3}, \small 2^A = {\small \phi,{1},{2},{3},{1,2},{1,3},{2,3},{1,2,3}}.幂集里的每个元素都是一个集合,另外,\small |\small 2^A\small | = \small 2^{|A|} = \small 2^3 = 8.

2. 二元关系

Definition 3. Let \small A and \small B be two sets. Any \small R\small \subseteq \small A \small \times \small B is a binray relation. 
例如二元关系\small :=\small \{​\small {(x,y)} \small \in \small R^2 \small | \small x=y\small \}.

3. 函数

Definition 4. Let \small V_1\small ,...V_m be the domain of conditional attribute \small a_1,...,a_m,  respectively, and \small L  be the set of classes. A classifier is a function \small f:V_1\times...\times \small V_m\small \rightarrow\small L.
需注意:函数的定义域、值域都是集合;对于函数定义域上的每个点,均在值域中有一个唯一的点与之对之,反之不然。因此,函数的逆函数不一定存在,若逆函数存在,就是一一映射。

习题 5: 多标签学习中, 输出为一个向量,相应的学习器算不算函数呢? 

  • 算函数。在多标签学习的学习器中,输入数据形式一定(如图像、音频),输出数据为向量,映射关系是一定的,符合函数的性质:定义域上的每个点,均在值域中有一个唯一的点与之对之的关系。

4. 元组

需注意:元组用\small ();向量既可用\small (), 也可用\small [];集合用\small {}\small {\left \{ \right \}}.

元组的各个部分,既可以是个集合,也可以是一个基本元素。图 (Graph) 就是最经典的二元组,因为一个图由两个元素确定,即顶点\small (V)和边\small (E).
a) 定义有向图:
directed graph is a tuple \small G_d = \small (V,E), where \small V=\small {}\small \{​\small v_1,...,v_n\} is the set of nodes, and \small E\subseteq V\times V is the set of edges.

b) 定义无向图:
An undirected graph is a tuple \small G_u = \small (V,E), where \small V=\small {}\small \{​\small v_1,...,v_n\} is the set of nodes, \small E\subseteq V\times V is the set of edges, and \small \langle \small v_i \small , \small v_j\small \rangle \small \in \small E iff  \small \langle \small v_j \small , \small v_i\small \rangle \small \in \small E (iff 为if and only if).

c) 定义带权有向图:
weighted directed graph is a tuple \small G_w=(V,w), where \small V=\small {}\small \{​\small v_1,...,v_n\} is the set of nodes, and\small w:V\times V\rightarrow R^+\cup \small \{0\small \}  is the edge weight function.
\small R^+ 表示正实数, 不包括 0, 所以只有把 0 加进来, 表示非负实数;若限定\small w只能取0或1,即\small w:V\times V\rightarrow \{0,1\},带权有向图就退化为有向图。

习题 6: 元组只能表达对象的数据部分, 还是可以完整地表达? 用一个具体的程序来说明.

  • 可以完整的表达一个对象。在Python中,有多种方式表示对象,元组只是其中的一个。
# 对象属性为name、age、height
>>> student=('jack',18,170.0)
>>> student
('jack', 18, 170.0)
>>> student[1]
18
# tuple不能修改
>>> student[2]=175.0
TypeError: 'tuple' object does not support item assignment

5. 字母表、二叉树、树 

5.1 字母表

Definition 11. An alphabet \small \Sigma is a set of characters. 常见的字母表包括:\small \Sigma = {0,1}, \small \Sigma = {a,...,z}.

字母表的正闭包定义如下:
Definition 12. The positive closure of alphabet \small \Sigma is given by \small \Sigma^+ = \small \Sigma^1 \small \cup \small \Sigma^2 \small \cup \small ....若 \small \Sigma ={0,1}, 那么 \small \Sigma^+ = {0,1,00,01,10,11,000,\small ...}, 若 \small \Sigma = {\small \mathrm{l},\small \mathrm{r}}, 那么 \small \Sigma^+ = {\small \mathrm{l},\small \mathrm{r},\small \mathrm{ll},\small \mathrm{lr},\small \mathrm{rl},\small \mathrm{rr},\small \mathrm{lll},\small ...}.

字母表的克林闭包(考虑空串\small \varepsilon)定义如下:
Definition 13. The Cling closure of alphabet \small \Sigma is given by \small \Sigma^* = \small \Sigma^0 \small \cup \small \Sigma^+ = {\small \varepsilon\small \cup \small \Sigma^+.字母表克林闭包的元素,就称为字符串.

5.2 二叉树

习题 7: 定义二叉树.

  • 参照闵老师的定义:https://blog.csdn.net/minfanphd/article/details/116245485?spm=1001.2014.3001.5501
  • 初始版本:Let \small \Sigma = \small \{​\small \mathrm{l} \small , \small \mathrm{r}\small \} be the alphbet and \small \phi be a null node. A binary tree is a triple \small T \small \(\small V \small , \small r \small , \small c\small \), where \small V =  \small \{​\small v_1 \small , \small ... \small , \small v_n\small \} is the set of nodes, \small r \small \in \small V is the root, and c \small : \small V \small \cup \small \{​\small \phi\small \} \small \times \small \Sigma^+ \small \to \small V \small \cup \small \{​\small \phi\small \} satisfying
    a) \small c\small \(\small \phi \small , \small \mathrm{l}\small \) = \small c\small \(\small \phi \small , \small \mathrm{r}) = \small \phi;
    b) \small \forall v \small \in \small V \small \setminus \small \{​\small r\small \}\small \exists 1 s \small \in \small \Sigma^+ st. \small c\small \(\small r \small , \small s ) = \small v;
    c) \small \forall_v\in V,\small a\in\Sigma,c(v,a)\neq r.
  • 打磨版本:Let \small \Sigma = \small \{​\small \mathrm{l} \small , \small \mathrm{r}\small \} be the alphbet and \small \phi be a null node. A binary tree is a triple \small T \small \(\small V \small , \small r \small , \small c\small \), where \small V =  \small \{​\small v_1 \small , \small ... \small , \small v_n\small \} is the set of nodes, \small r \small \in \small V is the root, and c \small : \small V \small \cup \small \{​\small \phi\small \} \small \times \small \Sigma^* \small \to \small V \small \cup \small \{​\small \phi\small \} satisfying
    \small \forall v \small \in \small V\small \exists 1 s \small \in \small \Sigma^* st. \small c\small \(\small r \small , \small s ) = \small v;
    若仅保留初始版本中的 b), 会出现 bug. 反例: \small V\small \{​\small \mathrm{r}\small \}\small c\small \(\small r \small , \small \mathrm{l}) = \small c\small \(\small r \small , \small \mathrm{r}) = \small \phi\small c\small \(\small \phi \small , \small \mathrm{l}) = \small c\small \(\small \phi \small , \small \mathrm{r}) = \small \phi.
    \small c\small \(\small r \small , \small \varepsilon) = \small r, 即从 \small r 读入空串到自己.

习题 8: 定义带权无向图.

  • weighted undirected graph is a tuple \small G_w = \small (\small V \small , \small E \small , \small w\small ), where \small V = \small \{​\small v_1 \small , \small ... \small , \small v_n\small \} is the set of nodes, \small E \small \subseteq\small V \small \times \small V is the set of edges, \small w:V\times V\rightarrow R^+\cup \small \{0\small \}  is the edge weight function, and \small \langle \small v_i \small , \small v_j\small \rangle \small \in \small E iff  \small \langle \small v_j \small , \small v_i\small \rangle \small \in \small E.

5.3 树

 习题 9. 考虑 ∅, 重新写 Definition 7 以解决其存在的问题, 见其讨论 d).

  • Definition 7. A tree is a triple \small T = \small \(\small V \small , \small r \small , \small p\small ), where \small V =  \small \{​\small v_1 \small , \small ... \small , \small v_n\small \} is the set of nodes,\small r\in V is the root, and p:(V\cup\{\phi\}) \setminus \{r\}\rightarrow(V\cup\{\phi\}) satisfying
    a) \small \forall v \small \in \small V\small \forall\small k\geq 1\small p^k(v) \small \neq \small v;
    b) \small \forall\small v \in V \small \setminus \{r\}\small \exists 1 \small k\geq 1, st.\small p^k(v) = \small r;
    c) \small \forall v\in V \small \setminus \{r\}p(v) \neq \small \phi.
    此定义与 Amaris-Bunny讨论、交流完成,如有错误,还请指正!

6. 自动机描述

确定的有穷状态自动机定义如下:
A deterministic finite state automata (DFA) is a 5-tuple \small M = \small (\small \Sigma \small , \small Q \small , \small q_0 \small , \small T \small , \small f\small ), where
a) \small \Sigma is the alphabet;
b) \small Q is the set of states;
c) \small q_0 \small \in \small Q is the start state;
d) \small T \small \subseteq \small Q is the set of terminal states;
e) \small f \small : \small Q \small \times \small \Sigma^*\small \rightarrow\small Q is the transition function.
Any \small s \small \in \small \Sigma^* is accepted by the automata iff \small f\small (q_0,s) \small \in \small T.

说明:
a) DFA 的开始状态只有一个, 因此为\small Q的元素;
b) DFA 的终止状态可以有多个, 因此为\small Q的子集;
c) DFA 的基础目标是看状态 \small s 是否合法 (被接受).

6.1 二叉树的自动机描述

如果将二叉树看作是一个自动机, 它包括如下几个方面:
a) 有一个字母表, 即(\mathrm{l} , \mathrm{r});
b) 有一个状态集合, 包括所有节点与空节点;
c) 有一个开始状态, 即根节点 r;
d) 有一个终止状态, 即空节点 \phi;
e) 从任一状态读入任一字母, 确定地转移到下一状态 (可以是自己), 这个用状态转移函数来描述.
通过分析可以看出, 二叉树在其中 4 点都与自动机完全契合, 唯一有问题的是终止状态. 二叉树本身没有一个“判断字符串是否合法”的目标,因此不存在终止状态. 但它又有一个特殊的状态, 即 \phi.

习题 3.1 模仿自动机的样子来重新定义二叉树.

  • A binary tree is a 6-tuple \small T = \small (\small \Sigma \small , \small Q \small , V \small , r \small , \phi \small , \small f\small ), where
    a) \small \Sigma = \small \{​\small \mathrm{l} \small , \small \mathrm{r}\small \} is the alphabet;
    b) \small Q = V\small \cup\{\phi\} is the set of states,and \phi is a null node;
    c) \small V =  \small \{​\small v_1 \small , \small ... \small , \small v_n\small \} is the set of nodes;
    d) r \small \in \small V is the start state(root);
    e) \phi is the special terminal states;
    f) \small f \small : \small Q \small \times \small \Sigma^*\small \rightarrow \small Q is the transition function, satisfying
    \small \forall v \small \in \small V\small \exists 1 s \small \in \small \Sigma^* st. \small c\small \(\small r \small , \small s ) = \small v;

6.2 树的自动机描述

如果将树看作是一个自动机, 它包括如下几个方面:
a) 有一个状态集合, 包括所有节点与空节点;
b) 有多个开始状态, 即V;
c) 有一个终止状态, 即r;
d) 树中所有节点有0或多个后继,,即父节点的分支数目不确定,无法通过父节点准确的找到相应的子节点,而每个子节点有且只有唯一的一条路径到达父节点.

习题3.2 模仿自动机的样子来重新定义树.

  • A tree is a 5-tuple \small T = \small (\small Q \small , V \small , r \small , \phi \small , p\small ), where
    a)  \small Q = V\small \cup\{\phi\} is the set of states,and \phi is a null node;
    a) \small V =  \small \{​\small v_1 \small , \small ... \small , \small v_n\small \} is the set of nodes, and \small V is the set of start states;
    b) r \small \in \small V is the terminal state;
    c) \phi is a special state;
    d) p :  \small Q \small \times \small \Sigma^*\small \rightarrow \small Q is the transition function, satisfying
    \small \forall\small v \in V\small \exists 1 s \small \in \small \Sigma^*, st.p(v,s) = \small r;

    如有错误,还请指正!

  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值