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

本文解答了关于集合、广义表、单标签与多标签学习等问题,并探讨了元组、二叉树、带权无向图等数据结构的概念及应用。通过对不同数据结构的定义与性质的分析,帮助读者理解其在机器学习和算法设计中的作用。

前言:对于博客中提出的问题的解答

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

答:
根据集合的定义可以知道,上述的集合有四个元素,分别是 0 , 1 , { 0 , 1 } , { 1 , 2 } 0,1,\{0,1\},\{1,2\} 01{ 0,1}{ 1,2}
在看到这类形式的数据的时候,我的第一想法就是广义表。
关于在机器学习中的优缺点,目前而来还没有比较深刻的体会。这次就对数据结构层次的优缺点进行表述,优点:可以便利的进行便利;缺点:在查找的时候遍历深度可以会很高。
了解到了单标签学习和多标签学习的定义之后,优点:对于多标签学习来说,这类形式的集合天然支持多标签学习的输出。
缺点:在解析数据的时候,数据深度可能过高导致程序执行效率降低。

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

前置知识:集合 A \mathbf{A} A的基数(cardinality),表示为 ∣ A ∣ |\mathbf{A}| A,指集合 A \mathbf{A} A中元素的个数
答:

∅ \varnothing 表示空集,其中元素个数为零,基数是0; { ∅ } \{\varnothing\} { }表示包含一个空集元素的集合,元素个数为一,基数是1。

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

前置知识:Traditional single-label classification is concerned with learning from a set of examples that are associated with a single label l from a set of disjoint labels L, |L| > 1. In multi-label classification, the examples are associated with a set of labels Y in L.(直白的理解就是识别一幅画(有太阳和沙滩)中的内容,单标签学习只会输出一个标签如太阳或者沙滩,而多标签学习会输出太阳和沙滩)

答:
函数三要素:定义域A、值域C和对应法则f(映射)。定义域与值域是存在且合理的,只需要考虑映射是否符合函数定义,对于输入的数据,在值域中存在唯一的元素与之对应。所以多标签学习中, 输出为一个向量,相应的学习器算函数。

习题 6: 元组只能表达对象的数据部分, 还是可以完整地表达 (既包括数据, 也包括方法/函数)? 用一个具体的程序来说明.

答:

/**
 * 定义一个二元组
 */
public class Tuple {
    //权重
    private int weight;

    //一组盒子
    private Set<Box> boxSet;

    public Tuple(Set<Box> boxSet) {
        this.boxSet = boxSet;
        //随机赋权重
        int i = new Random().nextInt();
        this.weight = Math.abs(i) % 10;
    }

    @Override
    public String toString() {
        return "Tuple{" +
                "weight=" + weight +
                ", boxSet=" + boxSet +
                '}';
    }
    private static class Box {
        //标号,唯一确定一个盒子
        private String mark;
        //填充物类型
        private String dataType;
        //容量
        private int capacity;

        public Box(String dataType) {
            this.mark = this.hashCode()+"";
            this.dataType = dataType;
            Random random = new Random();
            this.capacity = Math.abs(random.nextInt());
        }

        @Override
        public String toString() {
            return "Box{" +
                    "mark='" + mark + '\'' +
                    ", dataType='" + dataType + '\'' +
                    ", capacity=" + capacity +
                    '}';
        }
    }

    public static void main(String[] args) {
        Set<Box> boxSet = new HashSet<>();
        Box box1 = new Box("uint8");
        Box box2 = new Box("string");
        boxSet.add(box1);
        boxSet.add(box2);
        Tuple tuple = new Tuple(boxSet);
        //通过调用元组的toString方法,元素重载的toString也得以调用
        //st.元组也表达了对象的函数部分
        System.out.println(tuple.toString());
    }
}

输出:

Tuple{weight=8, boxSet=[Box{mark='621009875', dataType='uint8', capacity=1809725570}, Box{mark='2125039532', dataType='string', 	capacity=464452496}]}

习题 7: 定义二叉树.

答:
Let Σ = { l , r } \Sigma = \{\mathrm{l}, \mathrm{r}\} Σ={ l,r}be the alphbet and ϕ \phi ϕ be a null node. A binary tree is a triple T = ( V , r , c ) T = (\bm{V}, r, c) T=(V,r,c), where V = { v 1 , … , v n } \bm{V} = \{v_1, \dots, v_n\} V={ v1,,vn}is the set of nodes, r ∈ V r \in \bm{V} rVis the root, and c : V ∪ { ϕ } × Σ + → V ∪ { ϕ } c:\bm{V} \cup \{\phi\} \times \Sigma^+ \to \bm{V} \cup \{\phi\} c:V{ ϕ}×Σ+V{ ϕ} satisfying
a) c ( ϕ , l ) = c ( ϕ , r ) = ϕ c(\phi, \mathrm{l}) = c(\phi, \mathrm{r}) = \phi c(ϕ,l)=c(ϕ,r)=ϕ;
b) ∀ v ∈ V ∖ { r } \forall v \in \bm{V} \setminus \{r\} vV{ r}, ∃ \exists 1 s ∈ Σ + \in \Sigma^+ Σ+ st. c ( r , s ) = v c ( r , s ) = v c(r,s)=v;
c) ∀ v ∈ V \forall v \in \bm{V} vV, ! ∃ s ∈ Σ + ! \exists s \in \Sigma^+ !sΣ+ st. c ( v , s ) = v c ( v , s ) = v c(<

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

来日可期1314

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值