数学表达式2

课程训练


Day 4

作业11

问题1:写出该无向图的邻接矩阵.
在这里插入图片描述
E = [ 0 1 1 1 1 0 1 0 1 1 0 1 1 0 1 0 ] \mathbf E = \begin{bmatrix} 0 &1 &1 &1\\ 1 &0 &1 &0\\ 1 &1 &0 &1\\ 1 &0 &1 &0 \end{bmatrix} E=0111101011011010

问题2:定义无向网络

Definition 1. A undirected net is a tuple G = ( V , w ) G = (\mathbf V, w) G=(V,w), where

  • V ≠ ∅ \mathbf V \ne \emptyset V= is the set of nodes,
  • w : V × V → R w : \mathbf V \times \mathbf V \to \mathbb R w:V×VR is the weight function where w ( v i , v j ) w(v_i, v_j) w(vi,vj) is the weight of the arc ⟨ v i , v j ⟩ \langle v_i, v_j \rangle vi,vj satisfying
    • ∀ ( v i , v j ) ∈ V × V \forall (v_i,v_j)\in \mathbf V \times \mathbf V (vi,vj)V×V, w ( v i , v j ) = w ( v j , v i ) w(v_i, v_j) = w(v_j, v_i) w(vi,vj)=w(vj,vi).

作业12

问题1:自己画一棵树, 将其元组各部分写出来 (特别是函数 p p p).
在这里插入图片描述
Let ϕ \phi ϕ be the empty node, the tree is a triple G = ( V , r , p ) G = (\mathbf V, r, p) G=(V,r,p) where

  • V = [ v 0 . . v 9 ] \mathbf V = [v_0..v_9] V=[v0..v9] is the set of nodes;
  • r = v 0 r = v_0 r=v0 is the root node;
  • p : V → V ∪ { ϕ } p : \mathbf V \to \mathbf V \cup \{\phi\} p:VV{ϕ} is the parent mapping satisfying
    • p ( r ) = ϕ p(r) = \phi p(r)=ϕ;
    • ∀ v ∈ V , ∃ ! n ≥ 0 , s.t. p ( n ) ( v ) = r \forall v \in \mathbf V, \exist ! n \ge 0, \textrm {s.t.} p^{(n)}(v) = r vV,!n0s.t.p(n)(v)=r.

问题2:针对该树, 将代码中的变量值写出来 (特别是 parent 数组).

以 -1 为空结点,有如下代码:

class myTree{
private:
    //结点数量
    int numNodes;
    //根结点
    int root;
    //父结点数组
    int *parent;

public:
    //该树的构造函数
    myTree(){
        numNodes = 10;
        root = 0;

        parent = new int[numNodes];
        if (parent == NULL){
            cout << "new mem fail" << endl;
            return;
        }

        parent[0] = -1;
        parent[1] = 0;
        parent[2] = 1;
        parent[3] = 1;
        parent[4] = 3;
        parent[5] = 3;
        parent[6] = 3;
        parent[7] = 0;
        parent[8] = 7;
        parent[9] = 7;
    }
    ~myTree(){
        delete[] parent;
    }

    //找父结点
    int findParent(int node, int n){
        int resParent = node;
        for (int i = 0; i < n; i++)
        {
            resParent = parent[resParent];
            if (resParent == -1)
            {
                break;
            }
        }
        return resParent;
    }
};

作业13

问题1:画一棵三叉树, 并写出它的 child 数组.

再用用作业12的图,最大的度为3,也是三叉树。
在这里插入图片描述

child [10][3] :
[ 1 − 1 7 2 − 1 3 − 1 − 1 − 1 4 5 6 − 1 − 1 − 1 − 1 − 1 − 1 − 1 − 1 − 1 8 − 1 9 − 1 − 1 − 1 − 1 − 1 − 1 ] \begin{bmatrix} 1 &-1 &7\\ 2 &-1 &3\\ -1 &-1 &-1\\ 4 &5 &6\\ -1 &-1 &-1\\ -1 &-1 &-1\\ -1 &-1 &-1\\ 8 &-1 &9\\ -1 &-1 &-1\\ -1 &-1 &-1 \end{bmatrix} 121411181111151111117316111911

问题2:按照本贴风格, 重新定义树. 提示: 还是应该定义 parent 函数, 字母表里面只有一个元素.

Definition 2. Let ϕ \phi ϕ be the empty node, a tree is a quadruple G = ( V , r , p , Σ ) G = (\mathbf V, r, p, \Sigma) G=(V,r,p,Σ) where

  • Σ = { u } \Sigma=\{\mathrm u\} Σ={u} is the alphabat;
  • V ≠ ∅ \mathbf V \ne \emptyset V= is the set of nodes;
  • r ∈ V r\in \mathbf V rV is the root node;
  • p : ( V ⋃ { ϕ } ) × Σ ∗ → V ⋃ { ϕ } p : (\mathbf V\bigcup\{\phi\}) \times \Sigma^* \to \mathbf V \bigcup \{\phi\} p:(V{ϕ})×ΣV{ϕ} is the parent mapping satisfying
    • ∀ v ∈ V , ∃ ! s ∈ Σ ∗ , s.t. p ( v , s ) = r \forall v \in \mathbf V, \exist !s \in \Sigma^* , \textrm {s.t.} p(v, s) = r vV,!sΣ,s.t.p(v,s)=r

问题3: 根据图、树、 m m m-叉树的学习, 谈谈你对元组的理解.

元组由元组名和其中的元素组成,例如 G = ( V , r , p ) G = (\mathbf V, r, p) G=(V,r,p),其中 G G G 为元组名, V , r , p \mathbf V, r, p V,r,p 为该元组的元素。元素可以是任何东西,如矩阵、函数……
这样一来,就可以理解为面向对象编程语言当中的类。类里面可以有成员变量、可以有函数。


Day5

作业14

问题:定义一个标签分布系统, 即各标签的值不是 0/1, 而是 [ 0 , 1 ] [0, 1] [0,1] 区间的实数, 且同一对象的标签和为 1.

Definition 3. A Label Distribution system is a tuple S = ( X , Y ) S = (\mathbf X, \mathbf Y) S=(X,Y) , where

  • X = [ x i j ] n × m ∈ R n × m \mathbf X = [x_{ij}]_{n \times m} \in \mathbb R^{n \times m} X=[xij]n×mRn×m is the data matrix, and x i = [ x i 1 , … , x i m ] \mathbf{x}_i = [x_{i1}, \dots, x_{im}] xi=[xi1,,xim] is an instance;
  • Y = [ y i k ] n × l ∈ [ 0 , 1 ] n × l \mathbf Y = [y_{ik}]_{n \times l} \in [0, 1]^{n \times l} Y=[yik]n×l[0,1]n×l is the lable matrix, and y i = [ y i 1 , … , y i l ] \mathbf{y}_i = [y_{i1}, \dots, y_{il}] yi=[yi1,,yil]is the label vector of x i \mathbf{x}_i xi satisfying
    • ∀ y i ⊂ Y , ∑ t = 1 l y i t = 1 \forall \mathbf y_i \subset \mathbf Y, \sum_{t = 1}^{l}y_{it} = 1 yiY,t=1lyit=1.
  • n n n is the number of instances;
  • m m m is the number of features;
  • l l l is the number of distribution labels.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值